I'm using PayPal Smart Buttons with data served via JSON generated by C#.
I run the code through with "default" UK address (as we're in the UK) when the PayPal popup initially loads the order data in. We then get the customer detail back, and their country, however, we don't ship there, so I need to clear the "shipping method" drop down in the PP popup and disabled the "continue purchase" button.
I'm getting the PayPal red box message that we can't ship to that location, however, I'm passing back shipping options as null in the JSON, but the drop down doesn't update to reflect this "no shipping options available" and furthermore the continue button is not disabled, so people are still able to hit continue and place the order with the default UK shipping fee.
I can't seem to find any docs in PayPal developer specifically with these issues in mind.
Has anyone else encountered this issue and able to advise what I need to send through to 1) clear the shipping methods available 2) disable the submit button if the red box message pops up.
When I do the initial load, I default to the UK shipping options. Once the PP pop has loaded it fires again, this time using the logged in PP user. IN both instances the follow JS code is run:
var processPatches = function(data, shippingId, orderTotal, actions) {
var patches = [];
var options = [];
if (data.options !== null && data.options !== undefined) {
if (data.options.length == 0) {
return actions.reject();
}
var found = false;
for (var i = 0; i < data.options.length; i++) {
var obj = {
id: data.options[i].id,
label: data.options[i].label,
amount: {
value: data.options[i].value,
currency_code: "GBP"
}
};
if (data.options[i].id == shippingId) {
obj.selected = true;
found = true;
shippingTotal = parseFloat(data.options[i].value);
} else
obj.selected = false;
options.push(obj);
}
if (!found && options.length > 0) {
options[0].selected = true; // ensure an option is selected.
shippingTotal = parseFloat(data.options[0].value);
}
}
patches.push({
op: "replace",
path: '/purchase_units/@reference_id==\'default\'/amount',
value: {
currency_code: "GBP",
value: (orderTotal + shippingTotal).toFixed(2),
breakdown: {
item_total: {
currency_code: "GBP",
value: orderTotal.toFixed(2)
},
shipping: {
currency_code: "GBP",
value: shippingTotal.toFixed(2)
}
}
}
});
if (data.options !== null && data.options !== undefined) {
console.log("address changed");
patches.push({
op: "replace",
path: "/purchase_units/@reference_id=='default'/shipping/options",
value: options
});
}
return actions.order.patch(patches);
};
When it's run the second time and the destination is not shipped to, I return options containing no shipping options. SO it's not null so it fires the "return actions.reject();" line. However, it therefore doesn't clear the shipping options available. In conjunction with that, I was under the impression that when "return actions.reject();" is returned, the "continue purchase" button should be disabled....but it's not.
Hopefully someone can advise where I've gone wrong here.
Hard to advise without any code to go on and reproduce the order creation and shipping callback, but testing a barebones JS SDK integration with this in paypal.Buttons({...})
...
onShippingChange() {
return Promise.reject();
},
There is a red notice saying the receiver does not ship to the address, and the "Complete purchase" button does nothing.