Skip to content

Billing: a cancel during Pro's free trial ends the trial and Pro at once - #249

Merged
MeharPro merged 1 commit into
mainfrom
fix/trial-cancel-now
Nov 16, 2026
Merged

MeharPro merged 1 commit into
mainfrom
fix/trial-cancel-now

Conversation

@MeharPro

Copy link
Copy Markdown
Contributor

What changes

When someone cancels Pro during the 3-day free trial, the trial and Pro now end at once. Before, they ran to the end of the trial.

  • How a cancel reaches us. Only through Stripe's portal (Manage billing on /account/billing). The site has no cancel button of its own. Account deletion already cancels at once.
  • The fix is in the webhook (telemetry-worker/src/stripe.ts). It looks for a trialing GenClass subscription set to cancel by its trial's end: cancel_at ≤ trial_end (what the portal sets with flexible billing) or cancel_at_period_end: true. It cancels that subscription in Stripe right away, reads it back, and writes Free. The customer.subscription.deleted that follows writes the same thing and cancels nothing a second time. Nothing was paid, so nothing is refunded. If Stripe fails, the webhook answers 500 and Stripe's retry finishes the job. This covers account subscriptions and version-4 project subscriptions.
  • Paid plans are unchanged. A paid plan cancelled in the portal still runs to the end of its paid month. The portal's subscription_cancel.mode stays at_period_end: it is one setting for every subscription, so immediately would end paid plans at once too. A trial set to cancel after a paid month (only possible by hand in the Stripe dashboard) is also left to Stripe.
  • Wording. The trial's line on the billing page now says a cancel ends Pro at once. The README and comments in stripe-setup.mjs say the same. Nothing on the CLI needed to change: "Cancel any time" and "nothing is charged if you cancel before the trial ends" are still true.

Tests

test/project-plans.test.ts, new block "Pro's trial: a cancel during the 3 free days ends the trial and Pro at once":

  • portal cancel with flexible billing (cancel_at), and with cancel_at_period_end: one DELETE, account on Free, GET /api/billing/pro says no Pro, no second trial at the next checkout
  • the following customer.subscription.deleted, an invoice.paid, and redeliveries: nothing is cancelled twice
  • Stripe failing on the cancel: 500 and nothing changed, then the retry ends the trial
  • a version-4 project subscription in its trial: ended now, account row untouched
  • a paid plan cancelled in the portal: no DELETE, Pro kept to the period end, "will not renew" line, Free only on deleted
  • a trial set to cancel after a paid month: left alone
  • the trialCancelled cases one by one, and the trial line on the billing page

With the fix turned off, the 5 trial-path tests fail and the 4 others still pass.

cd telemetry-worker && npx vitest run: 32 files, 892 tests pass. The first full run had one flaky failure, in index.test.ts "a client that goes away cannot cancel ingest", a 5 ms timing check in the collector, not billing. It passed 3 times alone and on the full rerun. tsc --strict on the changed files: no errors.

Not done here

  • Nothing deployed, and nothing changed in live Stripe.
  • Stripe's portal still shows its own "cancels on " message on the cancel screen, because its mode is at period end. The webhook ends the trial a moment later, and the billing page shows Free. Making the portal's own text match would need a second portal configuration (cancel mode immediately) used only when every GenClass subscription on the customer is trialing. That's a Stripe change the owner would have to run with scripts/stripe-setup.mjs.

The matching site wording (pricing FAQ and terms) is in a genclass-site PR.

🤖 Generated with Claude Code

Stripe's portal cancels at the period end, which in a trial is the trial's end, so a
cancelled trial kept Pro until then. The webhook now sees a trialing GenClass
subscription set to cancel by its trial's end (cancel_at with flexible billing, or
cancel_at_period_end), cancels it in Stripe right away and writes Free.

Paid plans are unchanged: cancelled in the portal, they run to the end of the paid
month. The portal's own cancel mode stays at_period_end, because it is one setting for
every subscription and "immediately" would end paid plans at once too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MeharPro
MeharPro merged commit 765c0a7 into main Nov 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant