Subscription cancelled in Stripe but the user still has the paid plan

Updated · by Zane

Why cancelled users keep the paid plan

checkout.session.completed arrives once, when someone pays for the first time. Everything after that is announced by other events: a renewal, a failed card, a cancellation, a plan change. If your app listens only for the first one, it never hears about any of them.

My own demo project did exactly this in its first version. It handled checkout.session.completed and nothing else. The upgrade worked, and a cancellation changed nothing in the database. If you built your payments with an AI tool, there is a good chance yours is the same. The same webhook can fail earlier in the chain too, which I cover in payment succeeded but the user is still on Free.

The events you need

  • customer.subscription.updated: the status or plan changed. This includes a customer clicking cancel before the period has ended.
  • customer.subscription.deleted: the subscription has really ended.
  • invoice.paid: a renewal went through.
  • invoice.payment_failed: a renewal charge failed.
If the app listens only for checkout.session.completed, which arrives once at the first payment, it never hears about cancellations, plan changes or renewals, because those arrive as other events. Subscription events carry only Stripe's customer id, so the id from the first payment has to be saved on the user to match them later.

Cancelling comes in two kinds

This is the part people trip on. A customer can cancel in two ways, and Stripe reports them differently.

  • Cancel immediately. The subscription ends right away and Stripe sends customer.subscription.deleted.
  • Cancel at period end. Stripe sets cancel_at_period_end to true and sends customer.subscription.updated. The status is still active. The customer.subscription.deleted event comes only when the paid period runs out.

So a user who clicked cancel and still has access until the end of the month is working as intended. The bug is a user who still has access after the period ended.

Step 1: see what your endpoint receives

  1. Open the Stripe Dashboard, then Developers, then Webhooks. Some accounts show this under Workbench.
  2. Make sure the test/live switch matches the subscription you are looking at.
  3. Click your endpoint and read the list of event types it is subscribed to.

If you see only checkout.session.completed, that is the problem. Stripe does not send events the endpoint is not subscribed to.

Then find the cancellation itself in Events. Check whether it was delivered to your address and what response code came back. A 400 there points to a signature problem, covered in webhook signature verification failed.

Step 2: match events to users

The first event carries client_reference_id, which is how you know whom to upgrade. Subscription events do not. They carry only Stripe's customer id. That means you must save session.customer on the user at the first payment. My demo stores it in a stripe_customer_id column, and every later event looks the user up by it.

I would also store the subscription status and current_period_end. Then your access check can read those two fields instead of trusting a single plan text.

Step 3: handle the events

In the Stripe webhook settings, tick the four event types above for your endpoint. Then extend the handler. This builds on the handler from the first guide. It keeps writing with the service role client and keeps checking that a row was changed. Your column names will differ, and sub_status and period_end need to be added to the table first.

Extending the webhook handler
// Inside the same Deno.serve handler, after the signature check.
// `supabase` is the service role client; `stripe` is the client from before.
if (event.type === "checkout.session.completed") {
  const session = event.data.object as Stripe.Checkout.Session;
  const sub = await stripe.subscriptions.retrieve(session.subscription as string);
  const { data } = await supabase
    .from("profiles")
    .update({
      plan: "pro",
      stripe_customer_id: session.customer as string,
      sub_status: sub.status,
      period_end: new Date(sub.current_period_end * 1000).toISOString(),
    })
    .eq("id", session.client_reference_id)
    .select("id");
  if (!data?.length) return new Response("not updated", { status: 500 });
}

if (event.type === "customer.subscription.updated" || event.type === "customer.subscription.deleted") {
  const sub = event.data.object as Stripe.Subscription;
  // Paid while Stripe says active, trialing, or past_due (still retrying the card)
  const paid = event.type !== "customer.subscription.deleted" &&
    ["active", "trialing", "past_due"].includes(sub.status);
  const { data } = await supabase
    .from("profiles")
    .update({
      plan: paid ? "pro" : "free",
      sub_status: sub.status,
      period_end: new Date(sub.current_period_end * 1000).toISOString(),
    })
    .eq("stripe_customer_id", sub.customer as string)
    .select("id");
  if (!data?.length) return new Response("not updated", { status: 500 });
}

One catch: on newer Stripe API versions, current_period_end is no longer on the subscription itself. It sits on each subscription item, so read sub.items.data[0].current_period_end instead. Check which version your account uses under Developers in Stripe.

Do the same for invoice.paid and invoice.payment_failed if you want to react to renewals and failures. Redeploy the function after editing it.

The simplest way to let customers cancel or change a card is Stripe's Customer Portal. They do it there, and your app only receives the events.

Fixing users who already slipped through

New events will sync correctly once the handler is fixed. Cancellations that already happened will not repair themselves. In Stripe, list your subscriptions and filter to the cancelled ones. Compare them with the users marked as paid in your database and correct the mismatches by hand. For recent events that Stripe still offers, you can open the event and click Resend.

Test the fix

  1. Switch Stripe to test mode. Never test with a real card.
  2. Subscribe with the test card 4242 4242 4242 4242, any future expiry date and any CVC.
  3. Cancel one subscription immediately, and another at period end.
  4. Check that each event shows a 200 response in the webhook log.
  5. Check the database after each step.
  6. To see the period actually end, use Stripe test clocks to move time forward past the billing date.

If you are also moving from test to live, test and live mode mix-ups are the next thing to read. I recorded a related payment fix in a video on the home page.

FAQ

The user cancelled but still has access until month end. Is that a bug?

No. When a customer cancels at the end of the period, Stripe keeps the subscription active and sets cancel_at_period_end to true. Access until the paid time runs out is normal. It is only a bug if access continues after that date.

What about failed renewal payments?

Listen to invoice.payment_failed and decide what you want. Some apps show a warning and keep access while Stripe retries the card. Others lock the account. Either way the subscription status changes, so storing status lets you act on it.

How do I find everyone who slipped through?

List your subscriptions in Stripe and filter to the cancelled ones. Compare that list with the users marked as paid in your database, and fix the mismatches by hand. Resending old events also works for events Stripe still lets you resend.

Checklist

Still stuck?

Send me the app link and what's broken. The first look is free and you get a fixed quote before I touch anything.

Related guides