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 <noreply@anthropic.com>
This commit is contained in:
parent
ec748c75a9
commit
bc0540d36a
@ -87,6 +87,9 @@ export async function POST(req: NextRequest) {
|
|||||||
if (customerLastName && (typeof customerLastName !== 'string' || customerLastName.length > 100 || /[\r\n\x00-\x1f]/.test(customerLastName))) {
|
if (customerLastName && (typeof customerLastName !== 'string' || customerLastName.length > 100 || /[\r\n\x00-\x1f]/.test(customerLastName))) {
|
||||||
return NextResponse.json({ error: 'Invalid last name' }, { status: 400 })
|
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
|
const customerName = [customerFirstName, customerLastName].filter(Boolean).join(' ') || undefined
|
||||||
|
|
||||||
|
|||||||
@ -280,7 +280,7 @@ export async function createSquareOrder(params: {
|
|||||||
phoneNumber: params.fulfillment.recipientPhone,
|
phoneNumber: params.fulfillment.recipientPhone,
|
||||||
address: { addressLine1: params.fulfillment.addressLine1 },
|
address: { addressLine1: params.fulfillment.addressLine1 },
|
||||||
},
|
},
|
||||||
scheduleType: 'SCHEDULED',
|
scheduleType: params.fulfillment.deliverAt ? 'SCHEDULED' : 'ASAP',
|
||||||
...(params.fulfillment.deliverAt ? { deliverAt: params.fulfillment.deliverAt } : {}),
|
...(params.fulfillment.deliverAt ? { deliverAt: params.fulfillment.deliverAt } : {}),
|
||||||
...(params.fulfillment.deliveryWindowDuration ? { deliveryWindowDuration: params.fulfillment.deliveryWindowDuration } : {}),
|
...(params.fulfillment.deliveryWindowDuration ? { deliveryWindowDuration: params.fulfillment.deliveryWindowDuration } : {}),
|
||||||
...(params.fulfillment.note ? { note: params.fulfillment.note } : {}),
|
...(params.fulfillment.note ? { note: params.fulfillment.note } : {}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user