Lambda webhook configuration
Lambda handler function
import { createLambdaWebhookHandler } from '@bates-solutions/squareup/server';
export const handler = createLambdaWebhookHandler({
signatureKey: process.env.SQUARE_WEBHOOK_SIGNATURE_KEY!,
notificationUrl: 'https://api.example.com/webhooks/square',
handlers: {
'payment.completed': async (event, context) => {
await processPayment(event.data.id, context.orderId);
},
},
});
Create an AWS Lambda handler for Square webhooks
Handles CORS preflight, signature verification, event parsing, routing to handlers, and entity ID extraction.
Responses:
204for a CORS preflight (OPTIONS)400when the body is missing or is not JSON401when the signature header is missing or the signature is invalid500when a handler (oronUnhandledEvent) throws, so Square retries the delivery200with{ success: true, eventId, ...ids }once the handler has runSquare retries a delivery that fails, so make handlers idempotent (for example, keyed on
event.event_id).