@bates-solutions/squareup API Reference - v3.2.0
    Preparing search index...

    Function createLambdaWebhookHandler

    • Create an AWS Lambda handler for Square webhooks

      Handles CORS preflight, signature verification, event parsing, routing to handlers, and entity ID extraction.

      Responses:

      • 204 for a CORS preflight (OPTIONS)
      • 400 when the body is missing or is not JSON
      • 401 when the signature header is missing or the signature is invalid
      • 500 when a handler (or onUnhandledEvent) throws, so Square retries the delivery
      • 200 with { success: true, eventId, ...ids } once the handler has run

      Square retries a delivery that fails, so make handlers idempotent (for example, keyed on event.event_id).

      Parameters

      Returns (proxyEvent: LambdaProxyEvent) => Promise<LambdaProxyResult>

      Lambda handler function

      When notificationUrl is missing

      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);
      },
      },
      });