← Back to dashboard

Stripe webhook idempotency rewrite

bob/billing·Acme Engineering/ billingConnected2 approval pending
bob/billing·demo · autoplaying
cycle 0
Readsrc/billing/webhook.tsallowed
The handler commits the charge update and the audit insert in separate transactions — that's the gap. I'll wrap both plus the processed_events insert in one tx so a retry can't partially apply.
CROperator chat
@bob dedupe on event.id, not payment_intent — Stripe sends several events per intent.
BO
@bob
Right, key on event.id. Each event type still runs its own handler.
Editsrc/billing/webhook.ts (~40 lines)allowed
Wrapped, with a unique constraint on processed_events.event_id — a duplicate insert raises and we return 200 without re-running side effects. Writing a replay test next.
Bashpnpm test src/billing/webhookallowed
Replay test passes — firing the same event twice processes exactly once. Want a 24h cleanup job for the processed_events table so it doesn't grow forever?
⊙ permission requestedBash
stripe trigger charge.refunded --forward-to localhost:3002
BO
@bob
We're double-processing some Stripe webhooks on retry. I want handler processing to be idempotent keyed on the event id. Plan it before any code.
demo · read-only

Composer is disabled in the demo. In the real app, this is where you'd type a prompt — `@@bob/billing` to route, plain text to queue. Sign in to use it.

Sign in →