Paypal Express Sandbox - onShippingChange returns error 400 when patching order

Ian44
Contributor
Contributor

 I've been using the sample code in the tutorial as a base to get a simple Paypal express button working, all seems to be fine until I attempt to patch the order to add shipping costs. The patch command returns an error 400 

 

My onshippingchange code is below :

 

const baseOrderAmount = '15.00';
const addFloats = (...floats) => floats.reduce((v, t) => parseFloat(t) + parseFloat(v), 0).toFixed(2);

 

onShippingChange: function(data, actions) {

// Patch the shipping amount
const shippingAmount = '20.00';
return actions.order.patch([
{
op: 'replace',
path: '/purchase_units/@reference_id==default/amount',
value: {
currency_code: 'USD',
value: addFloats(baseOrderAmount, shippingAmount),
breakdown: {
item_total: {
currency_code: 'USD',
value: baseOrderAmount
},
shipping: {
currency_code: 'USD',
value: shippingAmount
}
}
}
}
]);
}

 

 

What am I missing here?

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.