Translate reason codes into human-readable messages your checkout can display.
const REASON_MESSAGES = {
OUT_OF_ZONE: "We don't deliver to this postcode. Please check the postcode or choose a collection option.",
UNKNOWN_POSTCODE: "We couldn't recognise this postcode. Please double-check and try again.",
MIN_BASKET: "The minimum order for this delivery area is not met. Add more items to qualify.",
};
function getErrorMessage(reason) {
return REASON_MESSAGES[reason] || "We can't deliver to this address. Please contact support.";
}
// usage
const data = await checkZone(postcode, basket);
if (!data.canDeliver) {
showError(getErrorMessage(data.reason));
}