【发布时间】:2020-12-08 13:04:30
【问题描述】:
我在我的 Expressjs 应用程序中集成了 Paypal REST sdk。我正在将它与 Angular 应用程序连接起来。
这是我写的代码:
router.post('/buy' , ( req , res ) => {
const amt = req.body.quantity*req.body.price
/**
* Paypal payment json to be passed
*/
const payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "https://localhost:4200/success",
"cancel_url": "https://localhost:4200/err"
},
"transactions": [{
"amount": {
"total": '' + Math.round((amt)*100)/100,
"currency": "CAD",
"details": {
"subtotal": '' + Math.round((amt)*100)/100,
"tax": "0.00",
"shipping": "0.00"
}
},
"description": "This is payment description.",
"item_list": {
"items":[
{
"quantity": req.body.quantity,
"name": "collection",
"price": '' + req.body.price,
"sku": req.body.collid,
"currency":"CAD"
}
]
}
}]
}
/**
* Paypal payment object created
*/
paypal.paypal.payment.create(payment_json, function (error, payment) {
if (error) {
res.status(500).send({message: error})
} else {
console.log('payment:', payment)
for(let i=0; i<payment.links.length; i++) {
if(payment.links[i].rel === 'approval_url') {
res.json({forwardLink: payment.links[i].href});
}
}
}
});
});
在进行交易时,它正在成功交易并将我带到https://localhost:4200/success页面。但我无法看到sandbox 帐户中的交易。没有扣款,因此不显示任何交易。
我做错了什么?
【问题讨论】:
标签: javascript node.js angular paypal paypal-sandbox