我在我的网站上有一个贝宝付款。看起来像这样:
app.post('/pay', (req, res) => {
console.log(req.body);
const create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:1234/success",
"cancel_url": "http://localhost:1234/cancel"
},
"transactions": [{
"item_list": {
"items": [{
"name": req.body.user_name,
"sku": "001",
"price": "25",
"currency": "USD",
"quantity": req.body.persons_count
}]
},
"amount": {
"currency": "USD",
"total": "25"
},
"description": req.body.user_name + " with email " + req.body.email + " just ordered " + req.body.persons_count + " places"
}]
};
paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
throw error;
} else {
res.send('on my way');
console.log(payment);
}
});
})
如果我更改金额对象中的总字段(这是我想做的),我会收到 400 响应(错误请求)。我怎样才能进行这样的付款:
"amount":{
"total": req.body.persons_count * 2
}
其中req.body.persons_countvariable 是我从之前的一种表单的发布请求中获得的变量。
与该代码的斗争表明,两者price和total价值必须相等,但是我希望单个项目的价格与我想要获得的总金额不同。非常感谢!
顺便说一句,数量值必须等于 1。在所有其他情况下,应用程序崩溃。