Node.js 在execute\u payment\u json中获取可变金额
我想在我使用Paypal rest sdk的站点中集成Paypal。 我希望execute_payment_json中的金额等于用户输入的金额 paypal社区有一个帖子,但没有得到回复。 从用户处获取值后运行的代码Node.js 在execute\u payment\u json中获取可变金额,node.js,paypal-rest-sdk,Node.js,Paypal Rest Sdk,我想在我使用Paypal rest sdk的站点中集成Paypal。 我希望execute_payment_json中的金额等于用户输入的金额 paypal社区有一个帖子,但没有得到回复。 从用户处获取值后运行的代码 app.post("/paypal-pay",(req,res) => { console.log(req.body.amount); const create_payment_json = { "intent": "sale",
app.post("/paypal-pay",(req,res) => {
console.log(req.body.amount);
const create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:3000/success",
"cancel_url": "http://localhost:3000/cancel"
},
"transactions": [{
"item_list": {
"items": [{
"name": "Donation",
"sku": "item",
"price": req.body.amount,
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": req.body.amount
},
"description": "The Donation that you are doing"
}]
};
paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
throw error;
} else {
console.log(payment);
payment.links.forEach(url => {
if(url.rel === "approval_url"){
res.redirect(url.href);
}
});
}
});
})
成功后,上面的代码将我重定向到/success,我希望总数等于提供的值
app.get("/success",(req,res)=>{
console.log(req.body);
const payerId = req.query.PayerID;
const paymentId = req.query.paymentId;
const execute_payment_json = {
"payer_id" : payerId,
"transactions": [{
"amount": {
"currency": "USD",
// I want this total to be equal to the payment provided by user.
"total": "1.00"
}
}]
}