Skip to main content
The Stripe webhook endpoint receives and processes events from Stripe to keep your billing state synchronized.

Endpoint

POST /api/webhook/stripe This endpoint verifies the Stripe signature and handles various billing lifecycle events.

Authentication

This endpoint uses Stripe webhook signature verification instead of user authentication. You must configure the STRIPE_WEBHOOK_SECRET environment variable with your webhook signing secret from the Stripe dashboard.

Headers

string
required
The Stripe webhook signature header for event verification

Request body

The request body is the raw Stripe event payload. Stripe sends different event types with varying data structures.

Supported events

The webhook currently handles these Stripe event types:

checkout.session.completed

Triggered when a customer completes a checkout session.
packages/landing/app/api/webhook/stripe/route.ts
The TODO comments indicate where you should integrate with your Supabase database to grant product access to the user.

checkout.session.expired

Triggered when a checkout session expires without completion.

customer.subscription.updated

Triggered when a subscription is updated (plan change, renewal, etc.).

customer.subscription.deleted

Triggered when a subscription is canceled or expires.

invoice.paid

Triggered when an invoice payment succeeds (subscription renewal, etc.).

invoice.payment_failed

Triggered when an invoice payment fails.

Response

Success (200)

Returns an empty JSON object to acknowledge receipt of the webhook event.

Error (400)

Returned when the Stripe signature verification fails, indicating the request may not be from Stripe.

Implementation notes

The webhook handler verifies the Stripe signature before processing any events:
packages/landing/app/api/webhook/stripe/route.ts
Always verify webhook signatures in production. This prevents unauthorized parties from triggering billing actions in your system.

Setup

1. Configure webhook in Stripe

  1. Go to the Stripe Dashboard → DevelopersWebhooks
  2. Click Add endpoint
  3. Enter your webhook URL: https://yourdomain.com/api/webhook/stripe
  4. Select the events you want to receive (or select “all events” for development)
  5. Copy the Signing secret

2. Add environment variable

Add the webhook signing secret to your environment variables:

3. Test locally with Stripe CLI

Use the Stripe CLI to forward webhook events to your local development server:
The CLI will output a webhook signing secret for local testing. Use this in your .env.local file.

4. Trigger test events

Integration checklist

The current implementation includes TODO comments where you need to integrate with your database:
  • checkout.session.completed: Grant product access in Supabase
  • customer.subscription.updated: Update subscription status
  • customer.subscription.deleted: Revoke access
  • invoice.paid: Confirm or extend access
  • invoice.payment_failed: Notify customer and handle grace period
Store the Stripe customer_id, subscription_id, and price_id in your user profiles table to track billing status.

Security considerations

  • Signature verification: Always verify the stripe-signature header
  • Idempotency: Handle duplicate webhook deliveries gracefully
  • Logging: Log webhook events for debugging and audit trails
  • Error handling: Return 200 even if your internal processing fails (Stripe will retry)

Billing configuration

Configure Stripe API keys and webhook secrets

Checkout API

Create checkout sessions and customer portals