Builds robust Stripe webhook handlers. Match the project's stack or ask users (Next.js route, Express, Supabase edge function).
Must-haves
- Raw body for signature verification (no JSON pre-parse)
stripe.webhooks.constructEvent(body, sig, secret)- Idempotency -- dedupe by
event.id(store processed IDs) - Return
200fast; heavy work async - Handle only subscribed events; ignore rest gracefully
Core events (subscription SaaS)
| Event | Handler action |
|---|---|
checkout.session.completed |
Provision access, save customer/sub IDs |
customer.subscription.updated |
Sync plan + status |
customer.subscription.deleted |
Revoke access |
invoice.payment_failed |
Trigger dunning email/banner |
invoice.paid |
Confirm renewal |
Pattern (pseudocode)
event = constructEvent(rawBody, sig, secret)
if alreadyProcessed(event.id): return 200
switch event.type: ...handle...
markProcessed(event.id)
return 200
Verify
Use Stripe CLI stripe listen / stripe trigger, or check webhook-reliability after deploy.