stripe-payments-demo
Stripe webhook idempotency and payment intent retry patterns, ported to Next.js 16 App Router for Vercel deploy.
Endpoints
POST /api/webhook— Stripe webhook receiver. Verifies Stripe-Signature via HMAC-SHA256, then Redis SETNX guard with a 24h TTL onstripe:event:{id}.POST /api/create-payment-intent— Caller-supplied idempotencyKey. Exponential-backoff retry on 5xx / network errors; no retry on 4xx card declines.POST /api/simulate-payment— Demo helper; server generates the idempotencyKey.GET /api/health— liveness probe.
Sequence
Stripe -> POST /api/webhook
verify Stripe-Signature (HMAC-SHA256)
invalid -> 400
valid -> SETNX stripe:event:{id} EX 86400
duplicate -> 200 { duplicate: true }
new -> dispatch by event.type -> 200