Shipping always resolved to Nationwide
Every address on dev checkout came out as Nationwide. Regular and Express were greyed out, so a free-shipping coupon could not be tested against a regular order. Reported with a Bangkok address 2.4 km from the branch — 64 Soi Sukhumvit 11, Khlong Toei Nuea, Watthana, Bangkok 10110 (13.748, 100.557).
Root cause: two versions of one API contract
delivery/GetDeliveryFee on the feature branch pointed at a newer shipping-cost API:
https://km797c84si.execute-api.ap-southeast-1.amazonaws.com/Prod/shipping-cost
→ {"eligible_branches": [...], "ineligible_count": 0}
The checkout code still branched on the older PolygonCost shape:
if (t.success) { const n = t.top5.filter(e => e.cost >= 0); /* pick branch, set REGULAR */ }
// no success, no top5 → falls through:
console.log("apply nationwide"); this.delivery.forceNationwide = true;Neither success nor top5 exists in the new response, so the guard never passed and every address hit the fallback. forceNationwide disables Regular and Express outright, which is why it looked address-independent.
The migration to the new API had been started but its consumer was never updated.
What it was not
Worth recording, because both were checked first and were fine:
calculatecost2 honoured whatever mode it was sent — REGULAR returned a 90 baht branch fee, NATIONWIDE returned 115. The backend was never the problem.
Production was unaffected. master calls the relative /api/polygon/getPolygonCost; only feature — the branch dev builds from — had the absolute URL. Diffing the two branches would have found this in a minute.
Fix
Point the endpoint back at the CloudFront route that already existed on dev, matching production:
export const DELIVERY_ENDPOINT = getEndpoint("/api/polygon/getPolygonCost");Applied as a hot-patch to the deployed dev bundle and permanently in villaEcommerceWeb#315. The dev CloudFront distribution already routed /api/polygon/* to the PolygonCost API, so no infrastructure change was needed.
Verification
Guest checkout with the reported address:
| Check | Result |
|---|---|
/api/polygon/getPolygonCost | success: true, branches [1046, 1006, 1000] |
| Console | apply regular |
| Delivery type | Regular selected, Nationwide disabled |
| Regular fee | 90 baht, isNationwide: false |
Coupon 90000008 | shipping discount 90, free shipping applied |
Worth remembering
The fallback was silent and total. A failure in one endpoint disabled two delivery options for every customer, and produced no error anywhere — just a different, plausible answer. When a UI “always chooses X”, look for a fallback branch before looking at the logic that chooses X.
The console.log("apply nationwide") line was the fastest diagnostic in the whole investigation. Cheap logs at branch points earn their keep.