这就是我所犯的错误
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;
}当我console.log cart.totalPrice时,它应该是正确的(这是购物车中所有项目的总数)--知道这里到底出了什么问题。我对这一切都有点陌生,所以有点困惑。
发布于 2021-12-02 23:03:03
有关当前(非推荐)的APIs,请参阅设立标准付款中的示例。
在您的服务器上创建2条路线,一条用于“创建订单”,另一条用于“捕获命令”,记录在这里。这两条路线都应该只返回JSON数据(不返回HTML或文本)。在第二条路由中,当捕获API成功时,您应该将其结果的支付细节存储在数据库中(特别是purchase_units[0].payments.captures[0].id,即PayPal事务ID),并在将返回JSON转发给前端调用方之前执行任何必要的业务逻辑(例如发送确认电子邮件或保留产品)。
将这2条路由与当前的JS前端审批流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server
https://stackoverflow.com/questions/70202608
复制相似问题