【发布时间】:2019-12-25 19:27:03
【问题描述】:
我想在 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>
上面的代码是我尝试过的,我预计分解属性将成为有效负载的一部分,如文档中所示,但我从控制台收到错误消息。
那么添加这些属性的正确方法是什么?在此先感谢:)
【问题讨论】:
标签: javascript laravel paypal-sandbox