gpt4 book ai didi

javascript - 如何向 actions.order.create paypal 集成添加更多属性

转载 作者:行者123 更新时间:2023-12-03 17:29:21 24 4
gpt4 key购买 nike

我想在 paypal 的 actions.order.create 函数中添加更多属性。 tax_total、运费、保险、客户购买的元素 list 等属性。

我已经实现了他们网站上的代码,它工作正常,剩下的就是在代码中添加额外的细节。这是他们的文档: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>

上面的代码是我尝试过的,我希望分解属性将成为有效负载的一部分,如文档中所示,但我从控制台收到错误消息。

那么添加这些属性的正确方法是什么?提前致谢 :)

最佳答案

我在这里找到了答案:
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 的值必须匹配。如果您的订单中有不止一件商品,则情况可能并非如此。

关于javascript - 如何向 actions.order.create paypal 集成添加更多属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57576003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com