Node.js中的PayPal自适应支付存在问题

Node.js中的PayPal自适应支付存在问题,node.js,paypal,paypal-adaptive-payments,Node.js,Paypal,Paypal Adaptive Payments,我一辈子都搞不清楚发生了什么事。我只是想对PayPal的Adaptive Payments API做一个基本的调用,Pay调用。我正试图通过node.js实现这一点。我可以使用curl成功地进行调用,但node只是拒绝工作。我一直收到一条“无效请求:{0}”错误消息,errorId580001。我已经寻找了很长一段时间的解决方案,虽然很多人都有过类似的问题,但他们的问题与我的不同,因此他们的解决方案并不奏效 非常感谢您提供的任何帮助 以下是我不断得到的回应(美化): 这是我的节点代码:(注意:我

我一辈子都搞不清楚发生了什么事。我只是想对PayPal的Adaptive Payments API做一个基本的调用,
Pay
调用。我正试图通过node.js实现这一点。我可以使用
curl
成功地进行调用,但node只是拒绝工作。我一直收到一条
“无效请求:{0}”
错误消息,errorId
580001
。我已经寻找了很长一段时间的解决方案,虽然很多人都有过类似的问题,但他们的问题与我的不同,因此他们的解决方案并不奏效

非常感谢您提供的任何帮助

以下是我不断得到的回应(美化):

这是我的节点代码:(注意:我使用的是
请求
模块:)

以下是运行上述代码的输出:

{"actionType":"PAY","senderEmail":"happy_1349101075_biz@onehappystudent.com","receiverList":{"receiver":[{"email":"luke_1346604373_biz@onehappystudent.com","amount":"1.00"}]},"currencyCode":"USD","feesPayer":"EACHRECEIVER","memo":"This is a test","cancelUrl":"http://cancelurl","returnUrl":"http://returnUrl","ipnNotificationUrl":"http://your_ipn_notification_url","requestEnvelope":{"errorLanguage":"en_US"}}
{ readable: true,
  writable: true,
  headers: 
   { 'X-PAYPAL-SECURITY-USERID': 'happy_1349101075_biz_api1.onehappystudent.com',
     'X-PAYPAL-SECURITY-PASSWORD': '1349101103',
     'X-PAYPAL-SECURITY-SIGNATURE': 'AFcWxV21C7fd0v3bYYYRCpSSRl31Avw12OuF33eJo9IbQpXMS6wrOp1.',
     'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON',
     'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON',
     'X-PAYPAL-APPLICATION-ID': 'APP-80W284485P519543T',
     'Content-Type': 'application/json',
     host: 'svcs.sandbox.paypal.com',
     'content-length': 409 },
  body: <Buffer 7b 22 61 63 74 69 6f 6e 54 79 70 65 22 3a 22 50 41 59 22 2c 22 73 65 6e 64 65 72 45 6d 61 69 6c 22 3a 22 68 61 70 70 79 5f 31 33 34 39 31 30 31 30 37 35 ...>,
  callback: [Function],
  pool: {},
  dests: [],
  __isRequestRequest: true,
  _callback: [Function],
  _events: 
   { error: [Function],
     complete: [Function],
     pipe: { [Function: g] listener: [Function] } },
  uri: 
   { protocol: 'https:',
     slashes: true,
     host: 'svcs.sandbox.paypal.com',
     hostname: 'svcs.sandbox.paypal.com',
     href: 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
     pathname: '/AdaptivePayments/Pay',
     path: '/AdaptivePayments/Pay',
     port: 443 },
  _redirectsFollowed: 0,
  maxRedirects: 10,
  followRedirect: true,
  followAllRedirects: false,
  redirects: [],
  setHost: true,
  originalCookieHeader: undefined,
  _jar: undefined,
  port: 443,
  host: 'svcs.sandbox.paypal.com',
  clientErrorHandler: [Function],
  _parserErrorHandler: [Function],
  path: '/AdaptivePayments/Pay',
  httpModule: 
   { Server: { [Function: Server] super_: [Object] },
     createServer: [Function],
     globalAgent: 
      { options: {},
        requests: {},
        sockets: {},
        maxSockets: 5,
        _events: [Object],
        createConnection: [Function: createConnection] },
     Agent: { [Function: Agent] super_: [Object] },
     request: [Function],
     get: [Function] },
  agentClass: 
   { [Function: Agent]
     super_: { [Function: Agent] super_: [Function: EventEmitter], defaultMaxSockets: 5 } },
  agent: 
   { options: {},
     requests: {},
     sockets: {},
     maxSockets: 5,
     _events: { free: [Function] },
     createConnection: [Function: createConnection] } }
{"responseEnvelope":{"timestamp":"2012-11-05T03:50:08.216-08:00","ack":"Failure","correlationId":"b1dbb6fea8378","build":"4110101"},"error":[{"errorId":"580001","domain":"PLATFORM","subdomain":"Application","severity":"Error","category":"Application","message":"Invalid request: {0}"}]}
下面是答案:(为了方便你而美化)


同样,非常感谢您提供的任何帮助。

不确定您是否粘贴了正确的代码,但此代码对我有效-看看您是否能找到区别:

var request = require('request');
body = JSON.stringify(
  {actionType: "PAY",
  senderEmail: "happy_1349101075_biz@onehappystudent.com",
  receiverList: { receiver:
    [{
      email: "luke_1346604373_biz@onehappystudent.com",
      amount: "1.00"
    }]},
  currencyCode: "USD",
  feesPayer: "EACHRECEIVER",
  memo: "This is a test",
  cancelUrl: "http://cancelurl",
  returnUrl: "http://returnUrl",
  ipnNotificationUrl: "http://your_ipn_notification_url",
  requestEnvelope: {
    errorLanguage: "en_US" }
  })

console.log(body)

request.post({
        headers: {"X-PAYPAL-SECURITY-USERID": "happy_1349101075_biz_api1.onehappystudent.com", "X-PAYPAL-SECURITY-PASSWORD": "1349101103", "X-PAYPAL-SECURITY-SIGNATURE": "AFcWxV21C7fd0v3bYYYRCpSSRl31Avw12OuF33eJo9IbQpXMS6wrOp1.", "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON", "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON", "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T", "Content-Type": "application/json"},
        url: 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
         body: body
         }, function(error, response, body){
            console.log(body);
    });

哦,上帝,我觉得自己很愚蠢。。。我少了一行

method: 'POST'
经验教训-疲劳时不要编码


(除非你有大量的咖啡)

谢谢你的回复,Praveen,它确实有效。通过查看您的示例,我找到了代码中的确切问题,这相当令人尴尬。。。
curl -s --insecure \
-H "X-PAYPAL-SECURITY-USERID: happy_1349101075_biz_api1.onehappystudent.com" \
-H "X-PAYPAL-SECURITY-PASSWORD: 1349101103" \
-H "X-PAYPAL-SECURITY-SIGNATURE: AFcWxV21C7fd0v3bYYYRCpSSRl31Avw12OuF33eJo9IbQpXMS6wrOp1." \
-H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" \
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" \
-H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" \
-H "host: svcs.sandbox.paypal.com" \
https://svcs.sandbox.paypal.com/AdaptivePayments/Pay -d '{
  "actionType":"PAY",
  "senderEmail":"happy_1349101075_biz@onehappystudent.com",
  "receiverList":{
    "receiver":[{
      "email":"luke_1346604373_biz@onehappystudent.com",
      "amount":"1.00"
    }]
  },
  "currencyCode":"USD",
  "feesPayer":"EACHRECEIVER",
  "memo":"This is a test",
  "cancelUrl":"http://cancelurl",
  "returnUrl":"http://returnUrl",
  "ipnNotificationUrl":"http://your_ipn_notification_url",
  "requestEnvelope":{
    "errorLanguage":"en_US"
  }
}'
{ responseEnvelope: 
   { timestamp: '2012-11-05T03:40:10.613-08:00',
     ack: 'Success',
     correlationId: 'abaf5b13c5515',
     build: '4110101' },
  payKey: 'AP-4B1870921M506553S',
  paymentExecStatus: 'COMPLETED' }
var request = require('request');
body = JSON.stringify(
  {actionType: "PAY",
  senderEmail: "happy_1349101075_biz@onehappystudent.com",
  receiverList: { receiver:
    [{
      email: "luke_1346604373_biz@onehappystudent.com",
      amount: "1.00"
    }]},
  currencyCode: "USD",
  feesPayer: "EACHRECEIVER",
  memo: "This is a test",
  cancelUrl: "http://cancelurl",
  returnUrl: "http://returnUrl",
  ipnNotificationUrl: "http://your_ipn_notification_url",
  requestEnvelope: {
    errorLanguage: "en_US" }
  })

console.log(body)

request.post({
        headers: {"X-PAYPAL-SECURITY-USERID": "happy_1349101075_biz_api1.onehappystudent.com", "X-PAYPAL-SECURITY-PASSWORD": "1349101103", "X-PAYPAL-SECURITY-SIGNATURE": "AFcWxV21C7fd0v3bYYYRCpSSRl31Avw12OuF33eJo9IbQpXMS6wrOp1.", "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON", "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON", "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T", "Content-Type": "application/json"},
        url: 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
         body: body
         }, function(error, response, body){
            console.log(body);
    });
method: 'POST'