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

    Function createExpressWebhookHandler

    • Create Express middleware for handling Square webhooks

      This middleware:

      1. Captures the raw body for signature verification
      2. Verifies the webhook signature
      3. Parses the event and attaches it to the request
      4. Calls the appropriate handler

      Parameters

      Returns ExpressRequestHandler

      Express middleware function

      import express from 'express';
      import { createExpressWebhookHandler } from '@bates-solutions/squareup/server';

      const app = express();

      // IMPORTANT: Use raw body parser for webhook route
      app.use('/webhook', express.raw({ type: 'application/json' }));

      app.post('/webhook', createExpressWebhookHandler({
      signatureKey: process.env.SQUARE_WEBHOOK_KEY!,
      handlers: {
      'payment.created': async (event) => {
      console.log('Payment created:', event.data.id);
      },
      },
      }));