【发布时间】:2022-01-09 03:08:29
【问题描述】:
这是我得到的错误
name: 'VALIDATION_ERROR',
details: [
{
field: 'purchase_units[0]',
issue: 'Item amount must add up to specified amount subtotal (or total if amount details not specified)'
}
],
message: 'Invalid request - see details',
information_link: 'https://developer.paypal.com/docs/api/payments/#errors',
debug_id: '74ac8660674d8',
httpStatusCode: 400
这是我的 /pay 发帖路线
app.post('/pay' , (req , res) => {
let cart = new Cart(req.session.cart)
const create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:3000/success",
"cancel_url": "http://localhost:3000/failed"
},
"transactions": [{
"item_list": {
"items": getItems(cart.items)
},
"amount": {
"currency": "USD",
"total": cart.totalPrice
},
"description": "This is the payment description."
}]
};
这是 getItems 函数
function getItems(cart) {
let itemsArray = [];
for (const [idx, item] of Object.entries(cart)) {
itemsArray.push({
"name": item.item.product_name,
"price": item.price,
"currency": "USD",
"quantity": item.qty
});
}
return itemsArray;
}
当我控制台记录 cart.totalPrice 时,它应该是正确的(这是购物车中所有物品的总和)知道这里出了什么问题。我对所有这些东西有点陌生,所以有点困惑
【问题讨论】:
-
记录您的实际请求 JSON,因为这将显示问题所在。缺少某些内容或未添加内容,例如金额总计字段。您正在使用已弃用的 API
-
您能否提供一个未弃用的 API 链接?我不知道在哪里可以找到,我为那个 API 使用了一个 youtube 视频@PrestonPHX
标签: node.js paypal paypal-sandbox