Repository navigation
feat(billing): say on every page when a cancelled plan ends, with Keep my plan - #1823
Conversation
… my plan
A canceled subscription runs to the end of its paid period, but only
Billing said so. Every page now shows a thin band while it does: "Your
plan ends on {date}." For a canceled free trial it reads "Your free trial
ends on {date}, and your plan won't start." Decided 2026-10-29.
- 00386: organizations.cancel_at_period_end. Stripe's webhook writes it
(checkout, subscription.updated; deleted clears it), and the cancel and
reactivate routes mirror it at once. It is server only, held by its own
trigger: 00405 rewrote guard_organization_server_columns after this
number, so a fresh install would end on 00405's version, without the
column. schema.sql and the Supabase types are updated.
- The layout passes the end date (planEndsAt) to PlanProvider. The band
sits with the read-only and demo bands, in their amber style with dark
variants.
- Keep my plan, for admins as the route allows, resumes the plan as
Billing's Reactivate does. Other members read "To keep it, ask an admin
of your workspace."
- The band closes for the browser tab's session (sessionStorage, by end
date), and shows nothing past the end date (the read-only band takes
over), while read-only, or on the demo brand.
- Billing's cancel refreshes the layout, so the band shows at once.
- Help: settings/cancel-or-keep-your-plan.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Buying a trial now sends cancel_at_period_end false to Stripe; the optimistic organization update mirrors it, so a trial canceled before it was bought loses the plan-ends band at once instead of when the webhook lands.
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good with 2cc6612 (one commit on this branch), which adds one small fix.
The fix: Buy now clears the flag too. Buying a trial now already sends cancel_at_period_end: false to Stripe, but the optimistic organization update after it wrote only plan and subscription_status. A trial canceled and then bought kept the "Your free trial ends on …, and your plan won't start" band until the webhook landed. The buy-now update now writes cancel_at_period_end: false as well. A plan or period change leaves the column alone, since Stripe keeps a cancellation as it is there. Tests: the buy-now expectation is updated, there's a new "canceled trial, then bought" case, and the period-change test checks the column isn't written. Both buy-now tests fail without the fix.
Checked
- 00386: the new column has its own guard trigger, using the same
rolbypassrlscheck as 00276/00405. It doesn't depend on the order of 00405's function, which is the right call.not null default falseonorganizationsis a metadata-only change, with no rewrite. It's idempotent (if not exists/drop trigger if exists). The number is unique against main and every open PR. - Writes come only from the service role: the webhook (checkout,
subscription.updated,subscription.deleted) and the subscription route (Cancel, Reactivate, and now Buy now). Keep my plan uses the existing PATCHreactivate, which is admin-only on the server before any Stripe call. Repeating it is harmless. - The layout adds two plain columns to its select, with no embeds.
schema.sqlmatchesbuild-schema.sh.plan-row.test.tspasses (no client → server import). - The band: client-only date, sessionStorage wrapped in try/catch, hidden on the demo brand, on a read-only workspace and past the end date. Billing's Cancel and Reactivate both refresh the layout.
Follow-ups (not blocking)
- Existing canceled subscriptions: the column starts false for everyone. A workspace that canceled before this ships won't see the band until Stripe sends another
subscription.updated. A one-off pass over the Stripe subscriptions withcancel_at_period_end = truewould set them. - Webhook ordering: like
subscription_status, the column takes whatever the last delivered event says. If a late "canceled" event lands after a quick Keep my plan, the band can come back until the next event. Reading the subscription fresh in the handler, or comparingevent.created, would settle it for all the mirrored fields. - A cancellation made in the Stripe customer portal or the dashboard with a set date (
cancel_at) rather than at period end wouldn't show the band. Worth a look if the portal is set up that way.
Merge: clean on current main. With the fix it conflicts with #1804 and #1818 in subscription/route.ts and its test, where both edit the same optimistic update. The resolution keeps both keys (subscription_ends_at from those PRs, cancel_at_period_end from here). It's clean with #1806, #1845 and #1846.
Deploy: apply 00386 before the web deploy (the layout reads the column).
gkhngyk
left a comment
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main and keeps both sides of the conflict with #1804 in the subscription route: Buy now's update writes both subscription_ends_at and cancel_at_period_end: false, and the route and webhook tests expect both. Migration 00386 is applied on production just before the merge.
Summary
From testing: after Cancel subscription on Billing the product kept working. That's right: the subscription ends at the period's end, and the trial's end in a trial. But only Billing said so. Now every page says it until that date, with a way to keep the plan. The product owner approved this in a local preview.
Migration 00386:
organizations.cancel_at_period_end(boolean not null default false)rolbypassrlspattern. It doesn't rewrite 00405'sguard_organization_server_columns. On a fresh install 00386 runs before 00405, which re-creates that function, so the column would drop out of its list. A separate trigger doesn't depend on the order.Writes
checkout.session.completedandcustomer.subscription.updatedwritesub.cancel_at_period_end;customer.subscription.deletedwrites false.subscription_ends_at. Resume (PATCH reactivate) writes false. Both are optimistic, with the service role. Billing refreshes after a cancel, so the band shows at once.The band (
PlanEndsBanner)ReadOnlyBannerandDemoBanneron every dashboard page, in the same amber style, withdark:. The layout passessubscription_ends_atandcancel_at_period_endtoPlanProvider.planEndsAt.Help: new
help/settings/cancel-or-keep-your-plan.md(approved: false).Related issue
None. Product owner's feedback from testing billing.
Type of change
feat— New featureHow to test
cancel_at_period_endis false. As a non-admin you see the "ask an admin" line.plan-ends-banner,api/stripewebhook and subscription,plan-switcher, providers and Help validation (135 tests);demo/coverage(7/7).00386 was applied on the dev DB with the product owner's OK. The light and dark previews, and the trial wording, were shown and approved.
Deploy: apply 00386 before the web deploy, since the layout reads the column.
Checklist
bash supabase/build-schema.sh:schema.sqlis current (00386)🤖 Generated with Claude Code