PayPal Pay Operation - 错误81002

时间:2015-02-14 02:57:10

标签: c# paypal paypal-sandbox

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

  

错误代码:81002严重性:错误消息:未指定方法(不支持指定的方法)“

string postData = JsonConvert.SerializeObject(request);

postData的值:

"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"

以下是我发布帖子的方式:

 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;
    }

2 个答案:

答案 0 :(得分:3)

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

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

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

答案 1 :(得分:1)

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

如果是,那么它已经是x-www-form-urlencoded,您根本不需要将其序列化为JSON字符串。

或者如果你这样做了,那就改变一下:request.ContentType = "application/json";