Hi, I am having issues with using the smart payments buttons and having the patch function update the paypal total. The code is working, but the value reflected to the user seems to always be out of sync. I have two test addresses saved against my sandbox user account. One with a post code of 7000 and one with a post code of 3350. After detecting a shipping change, I make a call to my server to update the users post code, which will in turn update the shipping total. I then follow the documentation and return actions.order.patch() with appropriate parameters. However, the value reflected in the paypal window is out of sync with the selected shipping address. E.g. When I select my 7000 shipping address, I can see my cart total changing in the background on our ecommerce platform (so I know that is working) and paypal says "Address has been updated" , but the total charged to the customer does not change. However if I then go and select the 3350 address, again, I see my website update to the correct value and in a grey box I see the order total that relates to when the 7000 post code was selected. This suggests to me that the patch is working (on some level), but it isn't reflecting immediately in the paypal payments window.. Any thoughts? Here is my code: paypal.Buttons({
style: {
branding: true,
label: 'buynow',
layout: 'horizontal',
tagline: false
},
createOrder: (data, actions) => {
let order_data = {
purchase_units: [
{
amount: this.generate_purchase_units_amount()
}
]
};
return actions.order.create(order_data);
},
onCancel: function (data) {
//alert('order cancelled');
},
onError: function (err) {
//alert ("there was a paypal error");
},
onShippingChange: (data, actions) => {
if (data.shipping_address.country_code !== 'AU') {
return actions.reject();
}
this.$store.dispatch('update_user_data', {
['s_zipcode']: data.shipping_address.postal_code
}).then(response => {
console.log(this.generate_purchase_units_amount());
return actions.order.patch([
{
op: 'replace',
path: "/purchase_units/@reference_id=='default'/amount",
value: this.generate_purchase_units_amount()
}
]);
});
}
}).render('#paypal-button-container'); generate_purchase_units_amount(){
return {
currency_code: 'AUD',
value: this.$store.getters.cart_total,
breakdown: {
item_total: {
currency_code: 'AUD',
value: this.$store.getters.cart_subtotal
},
shipping: {
currency_code: 'AUD',
value: this.$store.getters.cart_shipping_total
}
}
};
},
... View more