PayPal 支付操作 - 错误 81002

PayPal Pay Operation - error 81002

我不确定为什么这个 PayPal Pay 操作会给我这个错误,尽管我似乎已经涵盖了所有必填字段:

Error Code: 81002 Severity: Error Message: Unspecified Method (Method Specified is not Supported)"

string postData = JsonConvert.SerializeObject(request);

post数据的值:

"actionType=PAY
&currencyCode=USD
&cancelUrl=https%3a%2f%2fexample.com%2fcancel
&returnUrl=https%3a%2f%2fexample.com%2freturn
&requestenvelope.errorLanguage=en_US
&receiverList.receiver(0).email=recipientemail%40gmail.com
&receiverList.receiver(0).amount=0.05
&VERSION=94.0
&USER=bizemail-facilitator_api1.gmail.com
&PWD=xxxxx
&SIGNATURE=xxxxxxxxx"

我是这样操作的post:

 SendRequest("https://api-3t.sandbox.paypal.com/nvp", postData);

 public string SendRequest(string url, string postData) 
 {
        var uri = new Uri(url);
        var request = WebRequest.Create(uri);
        var encoding = new UTF8Encoding();
        var requestData = encoding.GetBytes(postData);

        request.ContentType = "application/x-www-form-urlencoded";
        request.Method = "POST";
        request.Timeout = (300*1000); //TODO: Move timeout to config
        request.ContentLength = requestData.Length;

        using (var stream = request.GetRequestStream()) {
            stream.Write(requestData, 0, requestData.Length);
        }

        var response = request.GetResponse();

        string result;

        using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) {
            result = reader.ReadToEnd();
        }

        return result;
    }

NVP api 上不存在方法 PAY。 API 支持的完整方法列表已找到 here

然而,PAY 方法是在 Adaptive Payments API 中定义的。根据您的需要,您有两种选择:

  • 将端点更改为 https://svcs.paypal.com/AdaptivePayments/PAY 并修改您的值
  • 使用其他方法,例如 DoDirectPayment,但我不确定它是否符合您的要求。

我假设 postData 的值是 before 你将它序列化为 JSON 字符串,而不是像你说的那样,因为它显然是 不是一个JSON字符串。

如果是,那就已经是x-www-form-urlencoded了,根本不需要序列化成JSON字符串

或者,如果你最终还是这样做了,那么只改变这个:request.ContentType = "application/json";