我正在尝试添加订单的数量。这就是我所拥有的,它不起作用:(.
它在没有数量的情况下工作,但它默认为1。此外,我将如何添加第二个产品?它只允许我有一个
window.paypal.Buttons({
createOrder: (data, actions, err) => {
return actions.order.create({
intent: "CAPTURE",
purchase_units: [
{
description: "cool tablet",
amount: {
currency_code: "CAD",
value: 650.00,
},
quantity: 2,
},
{
description: "ink",
amount: {
currency_code: "CAD",
value: 777.00,
}
}
]
})
},
onApprove: async (data, actions)=>{
const order = await (actions.order.capture());
console.log(order);
},
onError: (err) => {
console.log(err);
}
})
.render(paypal.current)
}, []);
您需要一个单一的采购单位,一个具有所需细分对象的单一金额,以及一个具有行项目详细信息的项目数组。请参阅API参考资料https://developer.paypal.com/docs/api/orders/v2/#orders_create
这里有一个例子:
"purchase_units": [{
"description": "DESCRIPTION GOES HERE",
"amount": {
"value": "3.00",
"currency_code": "CAD",
"breakdown": {
"item_total": {
"currency_code": "CAD",
"value": "3.00"
}
}
},
"items": [
{
"name": "item one",
"quantity": "1",
"unit_amount": {
"currency_code": "CAD",
"value": "1.00"
}
},
{
"name": "item two",
"quantity": "1",
"unit_amount": {
"currency_code": "CAD",
"value": "2.00"
}
}
]
}
]