我试图在NodeJS中集成paypal-rest-sdk。
在付款时,我没有收到任何错误,客户被重定向到/succcess
路线。
主要问题是金额被扣除&分别添加到付款人和收款人帐户中。
我的代码是:
import paypal from 'paypal-rest-sdk';
let paypal_config ={
"port": 5000,
"api": {
"port": "",
"host": "api.sandbox.paypal.com",
"client_id": "my client id",
"client_secret": "my client secret"
}
}`
` app.post('/paynow', function(req, res) {
// paypal payment configuration.
var payment = JSON.stringify({
intent: 'sale',
payer: {
payment_method: 'paypal'
},
redirect_urls: {
return_url: app.locals.baseurl + '/success',
cancel_url: app.locals.baseurl + '/cancel'
},
transactions: [{
amount: {
total: parseInt(req.body.amount, 10),
currency: req.body.currency
},
description: req.body.description
}]
});
paypal.payment.create(payment, function(error, payment) {
if(error) {
console.log(error);
} else {
if(payment.payer.payment_method === 'paypal') {
req.paymentId = payment.id;
var redirectUrl;
console.log(payment);
for(var i = 0; i < payment.links.length; i++) {
var link = payment.links[i];
if(link.method === 'REDIRECT') {
redirectUrl = link.href;
}
}
res.redirect(redirectUrl);
}
}
});
});
我不知道我做错了什么,但我没有得到任何,我被重定向到“/ success”终点。