node.js - Node.js 中的 PayPal 自适应支付问题

标签 node.js paypal paypal-adaptive-payments

我这辈子都搞不清楚到底发生了什么。我只是想对 PayPal 的 Adaptive Payments API 进行基本调用,特别是 Pay 调用。我正在尝试使用 node.js 来实现这一点。我可以使用 curl 进行成功调用,但 Node 只是拒绝工作。我不断收到 “无效请求:{0}” 错误消息,errorId 580001。我找了很久的解决办法,虽然很多人遇到了看似相似的问题,但他们的问题与我的不同,所以他们的解决办法都没有奏效。

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

这是我不断收到的回复(经过美化):

{ 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}' } ] }

这是我的 Node 代码:(注意:我正在使用 request 模块:https://github.com/mikeal/request)

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

console.log request

  url: 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay'

  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"

  body: body

, (err, res, bod) ->

  console.log bod

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

{"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}"}]}

这是成功的 curl:

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

关于node.js - Node.js 中的 PayPal 自适应支付问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13231642/

相关文章:

node.js - 使用 NodeJS 从 CSV 填充 MongoDB

javascript - 如何在html页面或jade页面中显示mongoose结果

javascript - 我无法将 css 文件连接到 node.js 服务器上的 html 文件

android - Paypal for android 如何在回调中识别付款项?

node.js - 如何从 node.js 中删除 hdfs 文件

c# - Paypal 发布到 C# REST API 端点

Paypal:是否可以使用存储的信用卡进行并行支付?

oauth - 用于 PayPal 身份验证的 OpenId 端点

PHP - AdaptivePaymentsService::pay() - 总是返回错误:520002

c# - Paypal 并行支付