SaaS Failed-Payment Dunning & Idempotent Stripe Webhook State Machines (2026)
1. Defending Against Out-of-Order Webhook Races
Stripe and Paddle do not guarantee strict global ordering across invoice.payment_failed, invoice.paid, and customer.subscription.updated. If a delayed failure event lands seconds after a customer updates their card, naive handlers overwrite active state back to past_due.
if (incoming.created < current.lastEventCreated) return jsonResponse(200, { ignored: "stale_event" });
INSERT OR IGNORE INTO processed_events (event_id, created_ts) VALUES (?, ?);
2. Decline-Code Routing & Signed Update Links
Soft declines like insufficient_funds benefit from payday-window retries, whereas authentication_required needs an instant 3DS completion link and expired_card should never waste retry attempts. Pair StripeGuard's monotonic worker state machine (StripeGuard Kit) with CronPulse signature monitoring and InvoiceForge Global for EU VAT compliance.
Simulate Out-of-Order Races in StripeGuard or Unlock All 16 Kits ($79)
Model MRR leakage, test decline routing, and sign expiring WebCrypto HMAC billing-update tokens live, or grab all 16 source packs ($433 value) for $79.