A classic SaaS bug is unlocking paid features when the user hits /checkout/success?session_id=.... Users can close the tab before redirecting—or replay parameters manually.
Always Fulfill Inside Verified Webhooks
- Verify the cryptographic signature using the raw request buffer (not parsed JSON).
- Store processed
event.idvalues inside an atomic database transaction to prevent duplicate fulfillment when Stripe retries.
import Stripe from 'stripe' const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!) export async function processWebhook(rawBody: Buffer, sig: string) { const event = stripe.webhooks.constructEvent( rawBody, sig, process.env.STRIPE_WEBHOOK_SECRET! ) // Check if event.id already exists in DB, then grant access atomically return { received: true, type: event.type } } Want Production-Ready .cursorrules & Boilerplates?
I'm a student developer in Japan funding my upcoming new life next spring by packaging strict, battle-tested AI coding setups:
- Free Starter
.cursorrules& Reviewer Prompts ($0+): Download Free Starter Pack (or GitHub Repo) - 10-in-1 Ultimate Developer Suite ($19): Get Stack Kit
- All 10 Production Stacks Bundled ($99): 10-in-1 Ultimate Developer Suite