我的网站上有Paypal付款。看起来像这样:
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_count
变量是我从较早使用的其中一种表单的发布请求中获得的变量。
与该代码的战斗表明,price
和total
的值必须相等,但是我希望单个项目的价格与我想要的总金额不同。非常感谢!
顺便说一句,数量值必须等于1。在所有其他情况下,应用程序崩溃。
答案 0 :(得分:0)
总金额应为项目金额,运费,税金和其他费用之和。
在您的情况下,总计:商品价格*商品数量
样本
"transactions": [
{
"amount": {
"currency": "USD",
"total": "20",
"details": {
"shipping": "1.20",
"tax": "1.30",
"subtotal": "17.50"
}
},
"description": "Payment description",
"invoice_number": "1231123524",
"custom": "custom data",
"item_list": {
"items": [
{
"name": "Ground Coffee 40 oz",
"currency": "USD",
"quantity": 1,
"price": "7.50"
},
{
"name": "Granola bars",
"currency": "USD",
"quantity": 5,
"price": "2"
}
]
}
}
]
您也可以参考https://developer.paypal.com/docs/api/payments/v1/#payment_create