I would like to add more properties in the paypal's actions.order.create function. Properties like tax_total, shipping, insurance, list of items that the customer bought etc.
I have implemented the code from their website and it works fine, What is left is adding the extra details in the code. This is their documentation: 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>
The code above is what I have tried, I expected that the breakdown properties will be part of the payload as shown in the documentation but I get an error from the console instead.
So what will be the right way to add these properties? Thanks in advance :)