Why did a canceled user get paid access back?

Run a free check: FlowWatch signs up, logs in and runs a Stripe test checkout on your app, then scans for exposed keys. You get a shareable report. Run the free check at flowwatch.org

Your app was built with Lovable, Bolt, Cursor, Claude Code or another AI tool. Payments work, and the webhook that flips the plan works most of the time. But now and then a user who canceled still has Pro, or a user who just paid shows as free for a few minutes, or someone gets the welcome email twice.

The usual cause is a webhook handler that assumes two things Stripe doesn't promise:

  1. That events arrive in order. Stripe's docs say it doesn't guarantee delivery of events in the order they're generated. Creating a subscription, for example, can produce customer.subscription.created, invoice.created, invoice.paid and charge.created, and your endpoint can receive them in any order.
  2. That each event arrives once. Stripe's docs say an endpoint might occasionally receive the same event more than once. Failed deliveries are also retried: in live mode for up to three days with exponential backoff, and in a sandbox three times over a few hours.

So if your handler writes "whatever the event says" straight into your database, an older event that arrives late, or a retried one, can overwrite newer state.

What it looks like

  • The resurrected subscriber. The user cancels and customer.subscription.deleted sets them to free. Then a delayed customer.subscription.updated from earlier (status still active) arrives and sets them back to Pro.
  • The slow upgrade. invoice.paid arrives before the event your code uses to create the subscription row, the handler can't find the row, returns an error, and the user waits for a retry.
  • Double side effects. The same checkout.session.completed is processed twice, so credits are granted twice or two emails go out.

The fix, in order of importance

1. Treat the event as a signal and fetch the current state

For subscription access, don't copy the status from the event payload. When any subscription-related event arrives, take the subscription ID from it, retrieve the subscription from the Stripe API, and write that status to your database. Stripe's docs note you can retrieve the API resource to get its latest state. Whatever order events arrive in, the last write then reflects what Stripe says now, not what was true when an old event was created.

// inside your verified webhook handler (Node, stripe-node)
const sub = await stripe.subscriptions.retrieve(subscriptionId);
await setPlanForCustomer(sub.customer, sub.status, sub.items.data[0].price.id);

Base access on the retrieved status (for example, active or trialing gets access; canceled, unpaid and incomplete_expired don't). Decide deliberately what past_due means for your app.

2. Record event IDs and skip ones you've already processed

Stripe's recommended guard against duplicates is to log processed event IDs and skip repeats. A simple version is a table with a unique constraint on the event ID:

create table if not exists stripe_events (
  id text primary key,          -- the Stripe event id, e.g. evt_...
  processed_at timestamptz not null default now()
);

Insert the ID inside the same database transaction as the work it triggers. If the work fails and the transaction rolls back, the ID isn't stored either, so Stripe's retry can still be processed. If you insert the ID first in a separate step and then crash, every retry will be skipped and the work never happens.

Stripe also notes that in some cases two separate Event objects are generated for the same change, so for side effects like "grant 100 credits" it can help to key on the object ID in data.object (for example the checkout session or invoice ID) together with the event type.

3. Don't use created to order events

Stripe's docs say snapshot events record created in seconds, so distinct events can share a timestamp, and you shouldn't use created to decide order or whether you've already processed something. Fetching current state (step 1) avoids the need to order events at all.

4. Return 2xx quickly

Stripe asks endpoints to return a 2xx before any slow logic that could time out. If your handler does heavy work (emails, AI calls, big database updates) before responding, Stripe may treat the delivery as failed and retry it, which creates more duplicates. Verify the signature, record the event, queue or do the minimal update, and respond.

5. Make "missing row" a retryable case, not a crash

If an invoice.paid arrives before your app has created the user's subscription row, either create it from the retrieved subscription (step 1) or return a non-2xx so Stripe retries later. Don't silently return 200 and drop it.

How to test it before a customer finds it

  1. In test mode, run stripe listen --forward-to <your local or preview webhook URL> and use stripe trigger customer.subscription.deleted and stripe trigger checkout.session.completed to fire events.
  2. Resend the same event twice (from the Dashboard's event deliveries, or with stripe events resend <event_id>). Your app should do the work once.
  3. Cancel a test subscription, then resend an older customer.subscription.updated event for it. With step 1 in place, the user should stay on free, because your handler re-reads the subscription and sees canceled.
  4. Do one full purchase in your deployed app with the test card 4242 4242 4242 4242 and confirm the plan flips from the webhook, not just from the success page.

Where FlowWatch fits

FlowWatch runs a real signup, login and Stripe test-mode checkout on your app on a schedule, and emails you when that flow fails and again when it recovers. It only uses Stripe's test card, and it stops before entering anything if your checkout is live. It doesn't read your webhook code or replay out-of-order events for you, so it won't catch the resurrected-subscriber bug directly. It does catch the case where a deploy breaks signup or checkout entirely. Start with the free check: flowwatch.org.

Sources: Stripe webhooks documentation (event ordering, handling duplicate events, automatic retries, quick 2xx responses): https://docs.stripe.com/webhooks

Contact: hello@flowwatch.org