Stripe Webhooks API

Signature verification, idempotency, and payment status updates.

Endpoint

POST /api/webhooks/stripe

Processing requirements

Critical requirement

Read raw body text before constructing event.

const body = await req.text();
const sig = headers().get("stripe-signature");
const event = stripe.webhooks.constructEvent(body, sig, process.env.STRIPE_WEBHOOK_SECRET!);

If body is parsed as JSON first, signature verification fails.

Failure handling

  • Invalid signature: reject request (400)
  • Unknown event types: safely ignore or log for observability
  • Processing errors: return retry-safe status and preserve traceability in logs