我想在Paypal的actions.order.create函数中添加更多属性。诸如tax_total,运费,保险,客户购买的物品清单等属性。
我已经从他们的网站上实现了代码,并且工作正常,剩下的就是在代码中添加额外的细节。这是他们的文档:https://developer.paypal.com/docs/api/orders/v2/#orders_create。
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
// value: '350.00',
breakdown: {
item_total: '300.00',
tax_total: '20.00',
shipping: '10.00',
handling: '10.00',
insurance: '10.00'
},
}
}]
});
},
onApprove: function(data, actions) {
// Capture the funds from the transaction
return actions.order.capture().then(function(details) {
// Show a success message to your buyer
console.log(data, actions);
alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
return fetch('/paypal-transaction-complete', {
method: 'post',
headers: {
'content-type': 'application/json',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: JSON.stringify({
orderID: data.orderID
})
});
});
}
}).render('#paypal-button-container');
</script>
上面的代码是我尝试过的代码,我希望故障属性将成为有效负载的一部分,如文档中所示,但是我从控制台收到错误消息。
那么添加这些属性的正确方法是什么?在此先感谢:)
答案 0 :(得分:0)
我在这里找到了答案:
https://github.com/paypal/paypal-checkout-components/issues/1098
该链接中的示例使用的货币代码对我不起作用。下面是一个类似的示例:
var createOrder = function createOrder(data, actions) {
return actions.order.create({
"purchase_units": [
{
"reference_id": 1234,
"description": "Attempt n.1 for Quote ID 1234",
"amount": {
"currency_code": "USD",
"value": 14.4,
"breakdown": {
"item_total": { "currency_code":"USD", "value":"12"},
"shipping": { "currency_code":"USD", "value":"1"},
"tax_total": { "currency_code":"USD", "value":"1.4"},
"discount": { "currency_code":"USD", "value":"0"}
}
},
"items": [
{
"name": "OnePlus 6 T-rex 12\" name for 14\"\" blabla \" more double quotes",
"unit_amount": {
"currency_code": "USD",
"value": 12
},
"tax": {
"currency_code": "USD",
"value": 1.4
},
"quantity": 1,
"sku": "OnePlus61",
"category": "PHYSICAL_GOODS"
}
],
"shipping": {
"address": {
"address_line_1": "Some line 1",
"address_line_2": "Some line 2",
"admin_area_2": "Some city",
"admin_area_1": "some state",
"postal_code": "12345",
"country_code": "GB"
}
}
}
]
});
};
请注意,每个金额必须加起来为总值(在本例中为14.4)。还要注意,在此示例中,键tax_total和tax的值必须匹配。如果您作为订单的一部分包含多个商品,则可能不是这种情况。