Error "Order could not be patched" in new V2 API & checkout.js

tejasm1
Contributor
Contributor

I have working demo for new checkout.js. It was working fine but today in that demo suddenly happened 400(bad request) error. 

It throws 400 error when calling shipping callback

I am using the same code provided in  https://developer.paypal.com/docs/checkout/integration-features/shipping-callback/ link
In that it is calling Order Update (Patch request) API V2. and Error is INVALID_REQUEST in the response. 
While I double checked that request I sent is in proper format. So for now I have one hope if PayPal is changing something or having bug in sandbox again ? 

Here is my code : https://www.codepile.net/pile/5K7olXKA

 

Login to Me Too
3 REPLIES 3

Pedro88
New Community Member

Hello, I have the same problem. REST API v2, sandbox, JS SDK. Here comes the code:

 

https://www.paypal.com/sdk/js?currency=EUR&client-id=<<client-id>>


<script>
paypal.Buttons({
createOrder: function(data, actions) {

return actions.order.create({
purchase_units: [{
amount: {
currency_code: 'EUR',
value: '',
breakdown: {
item_total: {
currency_code: 'EUR',
value: ''
},
shipping: {
currency_code: 'EUR',
value: '0.00'
}
}
}
}]
});
},
onShippingChange: function(data, actions) {

country = data.shipping_address.country_code;


$.ajax({
url: '<>',
data: {country: country},
dataType: 'json',
method: 'GET'
}).done(function(ret) {
if(ret.status == 'ok') {
alert(JSON.stringify(ret));
if(ret.shipping_charge > 0) {
alert("will do a patch");
return actions.order.patch([
{
op: 'replace',
path: "/purchase_units/@reference_id=='1'/amount",
value: {
currency_code: 'EUR',
value: parseFloat(ret.order_total).toFixed(2),
breakdown: {
item_total: {
currency_code: 'EUR',
value: parseFloat(ret.items_total).toFixed(2)
},
shipping: {
currency_code: 'EUR',
value: parseFloat(ret.shipping_charge).toFixed(2)
}
}
}
}
]);
} else {
return actions.reject();
}
} else {
return actions.reject();
}
});
},
onApprove: function(data, actions) {

alert(JSON.stringify(data));

},
onCancel: function (data, actions) {

}
}).render('#paypal-button-container');
</script>

 

I did follow the guide here - https://developer.paypal.com/docs/checkout/integration-features/shipping-callback/

 

And when AJAX load data and returns them (without any error) the PayPal return error when tries to patch the order:

 

Error: Order could not be patched at https://www.sandbox.paypal.com/smart/buttons?onShippingChange=true&style.layout=vertical&style.color... ... string truncated .....

 

Any idea what is wrong? I tried to switch it to production keys and environment and same issue.

 

Thank you.

Login to Me Too

Pedro88
New Community Member

The text editor crop it, but there are initial values in "values" of purchase_units object

Login to Me Too

rahul-dighe
PayPal Employee
PayPal Employee

are you still facing this issues?

Senior Product Manager - PayPal Checkout API Product
Login to Me Too

Haven't Found your Answer?

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