From bc0540d36a1f30ea80d081f58342877a2a35a467 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 5 May 2026 10:42:25 -0400 Subject: [PATCH] fix: delivery order failing with MISSING_REQUIRED_PARAMETER from Square scheduleType was hardcoded to SCHEDULED even when no deliverAt time was provided, causing Square to reject with 400. Now uses ASAP when no slot is present. Also added server-side validation to reject delivery orders that arrive without a deliverySlotISO before they reach Square. Co-Authored-By: Claude Sonnet 4.6 --- estore/src/app/api/checkout/route.ts | 3 +++ estore/src/lib/square.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/estore/src/app/api/checkout/route.ts b/estore/src/app/api/checkout/route.ts index 0789e71..4438e34 100644 --- a/estore/src/app/api/checkout/route.ts +++ b/estore/src/app/api/checkout/route.ts @@ -87,6 +87,9 @@ export async function POST(req: NextRequest) { if (customerLastName && (typeof customerLastName !== 'string' || customerLastName.length > 100 || /[\r\n\x00-\x1f]/.test(customerLastName))) { return NextResponse.json({ error: 'Invalid last name' }, { status: 400 }) } + if (deliveryAddress && !deliverySlotISO) { + return NextResponse.json({ error: 'A delivery time is required when scheduling a delivery.' }, { status: 400 }) + } const customerName = [customerFirstName, customerLastName].filter(Boolean).join(' ') || undefined diff --git a/estore/src/lib/square.ts b/estore/src/lib/square.ts index 83347c7..2d89153 100644 --- a/estore/src/lib/square.ts +++ b/estore/src/lib/square.ts @@ -280,7 +280,7 @@ export async function createSquareOrder(params: { phoneNumber: params.fulfillment.recipientPhone, address: { addressLine1: params.fulfillment.addressLine1 }, }, - scheduleType: 'SCHEDULED', + scheduleType: params.fulfillment.deliverAt ? 'SCHEDULED' : 'ASAP', ...(params.fulfillment.deliverAt ? { deliverAt: params.fulfillment.deliverAt } : {}), ...(params.fulfillment.deliveryWindowDuration ? { deliveryWindowDuration: params.fulfillment.deliveryWindowDuration } : {}), ...(params.fulfillment.note ? { note: params.fulfillment.note } : {}),