@bates-solutions/stripe API Reference - v2.2.1
    Preparing search index...

    Function createExpressWebhookHandler

    • Create Express middleware for handling Stripe webhooks.

      This middleware:

      1. Reads the raw body (required 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 RequestHandler

      Express request handler

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

      const app = express();

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

      app.post('/webhook', createExpressWebhookHandler({
      signingSecret: process.env.STRIPE_WEBHOOK_SECRET!,
      handlers: {
      'payment_intent.succeeded': async (event) => {
      console.log('Paid:', event.data.object.id);
      },
      },
      }));