使用Paypal Rest API和Node

我有一个问题,debugging我的贝宝与Node的集成,其余的API https://github.com/paypal/rest-api-sdk-nodejs

  • 我创build了一个Paypal账户
  • 我得到了应用程序的信用
  • 我创build了一个应用程序并为用户设置了一个密码
  • 我login到该用户的沙箱
  • 我没有看到任何交易logging

代码片段如下:

var config_opts = { 'host': 'api.sandbox.paypal.com', 'port': '', 'client_id': 'my id', 'client_secret': 'my secret' }; var create_payment_json = { "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:3000", "cancel_url": "http://localhost:3000" }, "transactions": [{ "amount": { "currency": "USD", "total": "10.00" }, "description": "This is the payment description." }] }; paypal_sdk.payment.create(create_payment_json, config_opts, function (err, res) { if (err) { console.log( err ); } if (res) { console.log("Create Payment Response"); console.log(res); } }); 

我得到的回应如下:

 { id: 'PAY-55J119327J2030636KLXMVJI', create_time: '2014-02-02T22:45:57Z', update_time: '2014-02-02T22:45:57Z', state: 'created', intent: 'sale', payer: { payment_method: 'paypal', payer_info: { shipping_address: {} } }, transactions: [ { amount: [Object], description: 'This is the payment description.' } ], links: [ { href: 'https://api.sandbox.paypal.com/v1/payments/payment/PAY- 55J119327J2030636KLXMVJI', rel: 'self', method: 'GET' }, { href: 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-90D3081342725343U', rel: 'approval_url', method: 'REDIRECT' }, { href: 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-55J119327J2030636KLXMVJI/execute', rel: 'execute', method: 'POST' } ] } 

我想知道是否有一些额外的步骤来validation我失踪?

您必须去仪表板 – >restAPI交易。

见附件截图:

在这里输入图像描述

首先,你必须声明一个正确的return_url(不只是localhost:3000)。 我build议你把你的return_url改成“ http:// localhost:3000 / success ”。 然后,在您的付款上面插入这一个POST方法:

 app.get('/success', function(req, res) { var paymentId = req.query.paymentId; var payerId = { 'payer_id': req.query.PayerID }; paypal.payment.execute(paymentId, payerId, function(error, payment){ if(error){ console.error(error); } else { if (payment.state === 'approved'){ res.send('payment completed successfully'); console.log(payment); } else { res.send('payment not successful'); } } }); });