Skip to content

feat(settings): ask why before cancelling, and offer three days to put it right - #1312

Merged
gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/billing-cancel-feedback
Oct 22, 2026
Merged

gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/billing-cancel-feedback

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Cancel Subscription now asks what went wrong first, and offers the team three days to put it right (product owner's request).

Deploy, in this order:

  1. Apply migration 00222_cancellation_feedback.sql.
  2. Deploy the server, with CANCEL_FEEDBACK_EMAILS set to the team's addresses (comma-separated). It uses the existing RESEND_API_KEY / RESEND_FROM_EMAIL.
  3. Deploy the web.

If the web goes out first, cancelling still works (it's the web's own Stripe route), but the answer is dropped and "Send and give us 3 days" fails. Without the env var, answers are only kept in the table, and a wait says the message didn't reach the team.

The dialog (CancelSubscriptionDialog, replacing the old "Cancel your subscription?" confirm)

  • "Before you go, what went wrong?", with six reasons to tick and a message box. Both are optional.
    • The reasons: Too expensive · Missing a feature I need · Not seeing results · Switching to another tool · Only needed it for a while · Something else.
  • Send and cancel cancels at the end of the period, as before (the same DELETE /api/stripe/subscription). The answer is sent after the cancel succeeds.
    • With nothing ticked or written, the button reads Cancel Subscription, and the team still hears about it.
    • Cancelling stays one step away: nothing is required.
  • Send and give us 3 days changes nothing in Stripe.
    • The team gets the answer and is asked to act by the date shown, e.g. "We'll get back to you by October 24, 2026".
    • The dialog then says so, and the customer can still cancel any time.
    • It needs a reason or a message, so there is something to fix.
  • Waiting isn't offered when the plan renews (or the trial ends) within those 3 days, or the period end is unknown, so no one is charged while they wait (canWait, on Stripe's period end from GET /api/stripe/subscription).
  • If the server refuses a wait, the dialog says why and leaves only cancelling:
    • too_late: "Your plan renews before we could get back to you. You can still cancel it here."
    • not_sent: "Your message didn't reach our team. Please write to our support team, or cancel the plan here."
    • too_many and other failures keep the form, as before.
  • If cancelling fails, nothing is sent and the dialog stays open. If sending fails after a successful cancel, the cancel still stands.

Server (POST /api/billing/cancel-feedback, routes/billing.js, lib/cancel-feedback.js)

  • Zod-validated { reasons, message (≤ 2,000), choice: 'cancel' | 'wait' }.
  • The org, plan and status are read from the caller's profile.
  • Admins only, as the web's DELETE /api/stripe/subscription is: anyone else gets 403 admin_only, and the dialog is behind canAdmin.
  • It needs a subscription to cancel (400 no_subscription).
  • A wait is refused (400 too_late) only when the DB knows a period end that is still ahead and too close. A missing or past subscription_ends_at means the DB is behind Stripe (only customer.subscription.updated writes it), and the dialog already checked Stripe's date.
  • The answer is kept before the e-mail goes, so a failed send loses nothing. email_status (sent / refused / unknown / skipped) is written after the send.
  • A wait the team surely wasn't told about answers 503 not_sent (e-mail skipped, e.g. no addresses set, or refused by Resend), so the customer isn't promised an answer by a date. unknown counts as sent, since Resend may have sent it. A cancel is 201 either way: the plan is already cancelled.
  • E-mail:
    • It goes to CANCEL_FEEDBACK_EMAILS (comma-separated).
    • The subject says what they chose: "Acme Coffee asks us to act within 3 days before cancelling" or "Acme Coffee cancelled their plan".
    • The body has the act-by date, plan, period end, who (name, e-mail, role), reasons and message, all escaped.
    • reply_to is the customer, so the team answers by replying. deliverEmail gained an optional replyTo.
  • 5 answers a day per organization, then 429 too_many.

Migration 00222: cancellation_feedback (org, created_by, reasons, message, choice, plan, subscription_status, email_status, created_at). RLS is on with no policies: the server's service role writes and reads it.

Related issue

Product request (2026-10-21). No issue.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

With NEXT_PUBLIC_IS_CLOUD=true, migration 00222 applied, the server running, and a test subscription whose period ends more than 3 days out:

  1. Settings → Billing → Cancel Subscription: the dialog shows the reasons, the message box and "Give us 3 days?". Send and give us 3 days is disabled until a reason is ticked or something is written.
  2. Tick a reason, write a message, Send and give us 3 days.
    • "Thanks, we're on it" shows, and the plan is unchanged.
    • A cancellation_feedback row has choice = 'wait'.
    • With Resend and CANCEL_FEEDBACK_EMAILS set, the e-mail arrives and Reply goes to the customer.
  3. Open it again and Send and cancel: the subscription is set to cancel at period end, and a choice = 'cancel' row and e-mail follow.
  4. With a period ending within 3 days, the dialog only offers cancelling.

Checked locally against the dev DB:

  • Step 2 end to end through a local server (row written, e-mail skipped as Resend isn't set locally).
  • Step 4 by moving the demo period end 2 days out.
  • Light and dark, 1024 px.

The cancel itself needs Stripe, so step 3 is covered by tests. The demo org and preview rows are restored and deleted.

Review round 2 (2026-10-22), checked locally the same way, through this branch's real route on the dev DB (e-mail off) and Stripe's subscription answered in the browser (trialing, period end 10 days out), at 1024 px in light and dark:

  • With subscription_ends_at null in the DB (a new trial), "Send and give us 3 days" got through. The row was kept with email_status = skipped, and the dialog said "Your message didn't reach our team…" with only cancelling left.
  • With it 2 days out in the DB, the server answered too_late, and the dialog said "Your plan renews before we could get back to you…" with only cancelling left.

Tests:

  • Server:
    • cancel-feedback.test.js (7): the schema, recipients, both e-mails, escaping, canWait;
    • billing.test.js (8): kept then e-mailed with replyTo; a cancel kept when the e-mail is skipped; a wait skipped or refused → 503 not_sent and kept, unknown → 201; the daily limit; admins only; no subscription and too_late; a missing or past period end lets a wait through; bad input / no org;
    • email.test.js (+1): reply_to.
  • Web:
    • cancel-subscription-dialog.test.tsx (7, incl. too_late / not_sent leaving only cancelling);
    • lib/billing/cancel-feedback.test.ts (3, canWait);
    • plan-switcher.test.tsx (+1: asks first, then DELETE, onUpdate and the answer).

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) (0 errors; the 6 warnings are in untouched files, as on main)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • web yarn test (2,732 tests) and yarn build;
  • server npm run format, npm run lint and npm test (2,045 tests);
  • bash supabase/build-schema.sh (schema.sql included).

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 21, 2026 01:20
…ce it's spent

Starter now has the Improve tab (prompt_improve) on a $1 monthly budget,
a trial rather than 1% of its $49 price, so it can see what Improve does.
PROMPT-003 kept Improve to Growth and above.

- server/src/config/plans.js and web/src/config/plans.ts: Starter gets
  prompt_improve and improveMonthlyBudgetUsd 1.
- Improve tab: the budget note reads from en.json
  (prompts.improve.quota); once the budget is spent, Starter gets an
  "Upgrade for more" link to the billing page. A spent budget is said
  once, by the note, instead of also repeating the server's error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Settings → Billing's plan cards and custom plan box now follow
www.ansvisor.com/pricing.

- Each card lists, with a check: brands, unlimited seats, prompts
  tracked, the answer engines it tracks by name (Starter: ChatGPT &
  Microsoft Copilot; Growth: ChatGPT, Perplexity, Gemini, Microsoft
  Copilot, Google AI Mode and Google AI Overviews, instead of
  "8 answer engines"), content briefs and site audits a month, and what
  the plan adds; the taglines are the pricing page's.
- "Need a custom plan?" says who it's for and that it starts at
  $499/month, with six of the custom plan's points.
- The copy is in en.json (settings.planCards, customPlanPoints); the card
  keys nothing uses any more are removed. Plan limits are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wth at 5x

AI usage (the monthly budget Improve and, later, the Content Editor's AI
spend) now comes in tiers the billing cards can name: Starter $1 (1x),
Growth $5 (5x, up from $2.49), Enterprise $10 at the least (up from $4.99,
so it stays above Growth; 1% of the contract still raises it).

- server/src/config/plans.js and web/src/config/plans.ts: the new budgets,
  with comments; plan-guard.js and improve-cost.js no longer say the
  budget is 1% of the plan price.
- Billing cards: "{n}x AI usage", worked out from the budgets against
  Starter's, with a hover note on what it covers (Agent Chat runs on the
  customer's own key).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he SAVE50 offer

During the free trial every plan card buys now: the trial ends today on the
plan and billing period picked (a Starter trial can buy Growth, or a year
up front) and the card added for the trial pays at once, with the SAVE50
code filled in for a monthly plan. A failed payment changes nothing and
offers Stripe's page to update the card. After the trial, a paid plan can
switch between monthly and annual billing as well as change plan.

The cards get a Monthly / Annual switch (a year is twelve months less 20%,
the full price struck through, "Save 20%") and a Popular badge on Growth.
Annual prices come from STRIPE_STARTER_ANNUAL_PRICE_ID and
STRIPE_GROWTH_ANNUAL_PRICE_ID; the plan request is validated with zod.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… plan on a declined card

- PATCH /api/stripe/subscription answers 403 admin_only for any role but
  admin, before anything is charged; Billing shows non-admins a note
  instead of the Buy, Upgrade, Downgrade, Switch and Reactivate buttons.
- A billing period switch now uses payment_behavior error_if_incomplete,
  so a declined card returns 402 payment_failed and leaves the plan as it
  was instead of moving it to the new period past due.
- Test: buying with the code field left empty applies no discount.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t it right

Cancel Subscription now asks what went wrong first: six reasons to tick
and a message, both optional. The customer then cancels at the end of
the period, as before, or gives the team three days with the plan
unchanged. Waiting isn't offered when the plan renews (or the trial
ends) within those days.

- Migration 00222: cancellation_feedback (RLS on, server only).
- Server POST /api/billing/cancel-feedback keeps the answer, then
  e-mails CANCEL_FEEDBACK_EMAILS with replies going to the customer
  (deliverEmail takes replyTo). Five answers a day per organization.
- Web: CancelSubscriptionDialog; the plan is cancelled first, then the
  answer is sent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 21, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk A billing follow-up on top of #1300 (merge #1300 first; this PR's own change is a56405f). Cancel Subscription now asks why first, and offers "give us 3 days" with the plan unchanged. Answers are kept in a new table and e-mailed to the team.

Things only you can do, or should decide:

  1. Env on the live server: [email protected],[email protected]. Could you also confirm RESEND_API_KEY / RESEND_FROM_EMAIL are set there? Without them the answers are only kept in cancellation_feedback, with email_status = 'skipped'.
  2. Migration number: I took 00222, after the open Content stack (00204–00221). If this merges before that stack, or you'd rather renumber, tell me and I'll move it.
  3. Who can cancel: still any member, as before. If you say on feat(settings): buy a trial now from Billing, with annual plans and the SAVE50 offer #1300 that cancelling should be admin-only, I'll apply it here too: the button, the dialog and DELETE.
  4. Customer e-mail: I didn't add a "we got your message" e-mail to the customer. The idea is that the team replies personally (Reply goes to the customer). Say if you'd like an automatic one.
  5. Conflicts with feat(settings): link the billing plans to every feature on the pricing page #1311: both are stacked on feat(settings): buy a trial now from Billing, with annual plans and the SAVE50 offer #1300 and touch plan-switcher.tsx and en.json in different places. Whichever merges second may need main merged in; I'll handle it.

Checked locally: the "3 days" path end to end through a local server against the dev DB (the row was written; e-mail skipped since Resend isn't set locally), and the option hidden when the period ends within 3 days. The cancel itself needs Stripe, so it's covered by tests.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few fixes before merge:

  1. Admins only on the server too. server/src/routes/billing.js:28-34 reads profiles.role but never checks it. Any member can post choice: 'cancel', and the team gets "… cancelled their plan" while nothing changed in Stripe. #1300 makes DELETE admin-only, so return 403 admin_only here unless profile.role === 'admin', before the daily count. When #1300 hides Cancel for other roles, put the <CancelSubscriptionDialog> mount (web/src/components/settings/plan-switcher.tsx:528) behind canAdmin too. Add a route test: a manager gets 403, and nothing is inserted or e-mailed.
  2. Check the subscription on the server. The three-day rule is only in canWait (web/src/lib/billing/cancel-feedback.ts:38-42), which runs in the browser. In billing.js:47-51, also select stripe_subscription_id. Answer 400 when it's null or subscription_status isn't active/trialing/past_due. For wait, also answer 400 when subscription_ends_at is within WAIT_DAYS. Without these checks, a direct POST can promise the customer an answer that comes after they've already renewed.
  3. One "act by" date for the customer and the team. The dialog shows now + 3 days in the browser's time zone (cancel-subscription-dialog.tsx:27-28, 89, 173). The e-mail shows it in UTC (server/src/lib/cancel-feedback.js:67-73, 90). In the evening in the Americas, the team's date is a day later than the one the customer was promised. Put the time in the e-mail's Act by row, e.g. "October 24, 2026, 17:00 UTC".
  4. Regenerate web/src/types/supabase.ts. 00222 adds cancellation_feedback, but the generated types weren't updated. Migration PRs carry the regen, as #1257 did.
  5. Revoke the default grants. At supabase/migrations/00222_cancellation_feedback.sql:35, RLS with no policies already blocks reads and writes. Even so, the default privileges still give anon and authenticated every privilege on this table of free-text customer messages. Add revoke all on public.cancellation_feedback from anon, authenticated; as 00183 does, then rebuild schema.sql.
  6. Test fixtures. server/src/lib/cancel-feedback.test.js:46-48 and server/src/routes/billing.test.js:71, 124 use the team's real addresses. Use example.com ones, as server/.env.example does.
  7. Nit: canWait (web/src/lib/billing/cancel-feedback.ts:41) still offers waiting when the renewal is a minute after the three days. A customer who hears back on day three then has no time to cancel. One day of margin (end > waitUntil(now) + 1 day) keeps the promise in the copy.

Checked and fine:

  • The e-mail escapes every value the customer or the org controls.
  • Reply-To comes from the verified token's e-mail.
  • The three-day path makes no Stripe call, so it can't extend a plan.
  • 00222 doesn't collide with any open PR.
  • schema.sql matches build-schema.sh.
  • Copy is in en.json, and the dialog uses no <Select>.

cihan-gyk and others added 3 commits October 21, 2026 18:00
DELETE /api/stripe/subscription answers 403 admin_only for other roles
before Stripe is called, and Billing shows Cancel Subscription to admins
only, with tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ble to the server

- POST /api/billing/cancel-feedback is the admins' (403 admin_only, before
  anything is kept or sent), needs a subscription that is active, trialing
  or past due, and refuses to wait when the plan renews within the three
  days and a day to spare; the dialog mounts for admins only.
- Waiting is offered only with a day left after the team's answer (web and
  server share the rule).
- The team's e-mail gives the moment to act by with its time in UTC.
- 00222 revokes the default grants on cancellation_feedback from anon and
  authenticated; schema.sql rebuilt; types/supabase.ts has the table.
- Test fixtures use example.com addresses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Fixed in e0d98dc, on top of #1300's admin-only cancel (merged in):

  1. Admins only on the server. The route answers 403 admin_only unless profile.role === 'admin', before the daily count. The dialog mounts behind canAdmin. The route test checks that manager, analyst and agency_partner get 403 and that nothing is inserted or e-mailed.
  2. The subscription, checked on the server. The route also reads stripe_subscription_id.
    • 400 no_subscription when it's null or the status isn't active/trialing/past_due.
    • 400 too_late for wait when subscription_ends_at doesn't leave the three days and a day.
    • Cancelling then still goes through. Tests cover each case.
  3. One act-by moment. The e-mail's row reads "October 24, 2026, 12:00 UTC". The customer sees the same moment in their own zone.
  4. types/supabase.ts has cancellation_feedback (Row/Insert/Update, organization FK), in the generated shape.
  5. Grants. 00222 has revoke all on public.cancellation_feedback from anon, authenticated; (as 00183), schema.sql is rebuilt, and it's applied on the dev DB: only postgres and service_role hold grants now.
  6. Fixtures use [email protected] / [email protected].
  7. One day of margin. canWait needs the renewal after waitUntil(now) + 1 day. The server's canWait in lib/cancel-feedback.js is the same rule. Tests check the boundary, a minute past three days, and 3.5 days in the dialog.

Checked as on #1300.

gkhngyk
gkhngyk previously approved these changes Oct 21, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes check out. All seven are in e0d98dc, and the merge of #1300 (2dcb74f) only brings in #1300's admin-only cancel.

One thing before merge: main now has the Content stack (00204–00221), and supabase/schema.sql conflicts with it. Please merge main and rerun bash supabase/build-schema.sh rather than resolving the conflict by hand. 00222 is still free, and types/supabase.ts merges cleanly.

Optional: sendCancelFeedback maps every code except too_many to "Couldn't send your message. Please try again." So a too_late (the server reads subscription_ends_at, which can lag Stripe's period end) asks the customer to retry something that will keep failing. Passing too_late through with its own message would fix that.

…cel-feedback

# Conflicts:
#	supabase/schema.sql
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Merged main in (86be1bc). schema.sql is rebuilt with build-schema.sh, not resolved by hand, so 00222 sits between 00221 and 00224. Server 2,020 tests and web 2,519 pass, with lint, tsc, Prettier and build. The optional too_late message is queued for a follow-up.

…cel-feedback

# Conflicts:
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/components/settings/plan-switcher.test.tsx
#	web/src/components/settings/plan-switcher.tsx
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk #1300 and #1311 are in, so I merged main into this branch (f5df702, no rebase). Its conflicts were all additive: the pricing link and seeAllPlanFeatures from #1311 sit beside the cancel dialog, and schema.sql was rebuilt with build-schema.sh. Against main, the PR now changes only its own 19 files. 00222 is still free on main. Checks pass: server 2042 tests and lint; web format, lint, typecheck, 2640 tests and build.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two fixes before merge. All seven items from the first review still hold at the head:

  • the server is admin-only, and the dialog is mounted behind canAdmin;
  • the server checks the subscription;
  • the Act by row is in UTC with the time;
  • the types are regenerated;
  • the grants are revoked;
  • the fixtures use example.com;
  • canWait keeps a day of margin.

f5df702c merges current main (12846db3), and schema.sql matches build-schema.sh. The diff from main to the head only touches this PR's files. In plan-switcher.tsx it only swaps the confirm for CancelSubscriptionDialog, so #1300's and #1311's code is intact.

  1. "Give us 3 days" is refused for orgs whose period end isn't in the DB. server/src/routes/billing.js:53 checks canWait(org.subscription_ends_at). Only customer.subscription.updated writes that column (web/src/app/api/stripe/webhook/route.ts:116-120). checkout.session.completed and /api/stripe/success never set it, so a new trial has null until its first update event.

    • The dialog uses Stripe's period end from GET /api/stripe/subscription, so it offers waiting.
    • The server then answers 400 too_late, and the customer sees "Couldn't send your message. Please try again." Every retry fails the same way.
    • On prod today, 4 of 9 trialing orgs have null there, and 2 of 9 active ones have a date in the past.

    Fix: refuse only when the DB knows a period end that is still ahead and too close. A missing or past value means the DB is behind Stripe, and the dialog has already checked Stripe's date.

    const endsAt = org.subscription_ends_at ? new Date(org.subscription_ends_at) : null;
    if (feedback.choice === 'wait' && endsAt && endsAt > new Date() && !canWait(endsAt)) {

    Add route tests for a null and a past period end. Also pass too_late through in web/src/lib/actions/cancel-feedback.ts:41, with its own message pointing to Cancel. Writing subscription_ends_at at checkout is worth its own fix, since the plan guard's quota period reads it too.

  2. A wait the team never hears about still gets "we're on it". billing.js:91-105 answers 201 whatever deliverEmail returns. Two cases lead there:

    • CANCEL_FEEDBACK_EMAILS is unset, so feedbackRecipients() is [] and the status is skipped;
    • Resend refuses the message (refused).

    In both, the dialog promises an answer by a date, and no one is told. For choice: 'wait' with skipped or refused, keep the row with its email_status, but answer 503 not_sent. Have the dialog say so and point to cancelling or support. unknown can stay a success, since Resend may have sent it. cancel stays 201, because the plan is already cancelled. Add a route test for each case.

  3. Low: the description is out of date. "Not changed: who can cancel (any member, as before)" is no longer true: cancelling is admin-only now. Also, the deploy step lists the team's own addresses. Say "the team's addresses" instead, as .env.example does.

Deploy order: 00222, then the server (with CANCEL_FEEDBACK_EMAILS and the Resend env), then the web.

  • If the web goes out first: POST /api/billing/cancel-feedback doesn't exist on the old server, so sendCancelFeedback returns server.
    • Cancel still works, because it's the web's own Stripe route. But the answer is dropped: no row and no e-mail, so the team doesn't hear about the cancel or why.
    • "Send and give us 3 days" fails every time, so the customer can only cancel.
    • The rest of Billing is unaffected.
  • If the server goes out before 00222: the insert fails with a 500, with the same result.

Merge notes

  • It merges cleanly on current main. It contains no other open PR now that #1300 is on main. It merges cleanly with #1328 and #1337.
  • 00222 doesn't clash with any open PR, and it isn't on prod yet.

cihan-gyk and others added 2 commits October 22, 2026 18:50
…cel-feedback

# Conflicts:
#	supabase/schema.sql
…ay when the team wasn't told

The server refuses "give us 3 days" (too_late) only when it knows a period
end that is still ahead and too close: a missing or past
subscription_ends_at means the DB is behind Stripe, and the dialog already
checked Stripe's date. A wait whose e-mail was skipped or refused is kept
but answers 503 not_sent. The dialog words both refusals and leaves only
cancelling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk merged main in (b1f5709; schema.sql from build-schema.sh, 00222 still free), then ae30a76:

  1. Waiting with no period end in the DB. billing.js refuses a wait (too_late) only when subscription_ends_at is known, still ahead and too close, as you suggested. A null or past value lets it through, since the dialog already checked Stripe's date. Route test: a null and a past period end both answer 201.
    • sendCancelFeedback passes too_late through. The dialog says "Your plan renews before we could get back to you. You can still cancel it here." and leaves only cancelling.
  2. A wait the team never hears about. For choice: 'wait' with email_status skipped or refused, the row is kept (with its status), and the answer is 503 not_sent.
    • The dialog says "Your message didn't reach our team. Please write to our support team, or cancel the plan here." and hides "Send and give us 3 days", so a retry doesn't add rows.
    • unknown stays 201, and a cancel stays 201.
    • Route test for skipped, refused and unknown; dialog test for both refusals.
  3. Description: cancelling is admin-only (server 403 admin_only, dialog behind canAdmin). The deploy step now says "the team's addresses" and gives the order 00222 → server → web, with what breaks if the web goes first.

Writing subscription_ends_at at checkout is its own fix: #1358.

Checked locally through this branch's route on the dev DB (e-mail off): with a null period end the wait got through and the dialog showed the not_sent message; with it 2 days out it showed too_late. Both left only cancelling (light and dark, 1024 px).

Checks: server format, lint (0 errors) and 2,045 tests; web lint (0 errors), typecheck, 2,732 tests, format:check and build.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. All three items from the last review are fixed in ae30a76f:

  1. "Give us 3 days" with no period end, or a past one, in the DB. The server now refuses a wait (too_late) only when the DB has a period end that is still ahead and too close (server/src/routes/billing.js:56-57). A null or past value goes through, and billing.test.js covers both. too_late now reaches the dialog (web/src/lib/actions/cancel-feedback.ts:12) with its own message. The dialog then hides the wait and leaves only cancelling.
  2. A wait the team never hears about. For a wait, an e-mail that was skipped or refused now returns 503 not_sent (billing.js:108-115). The row is kept with its email_status. unknown and every cancel still return 201. The route test checks all three statuses. The dialog test checks that both refusals show their message and leave only "Send and cancel".
  3. Description. The "any member can cancel" line is gone. The deploy step now says "the team's addresses", and the description lists no e-mail addresses.

The merge of main (b1f5709c) only resolves schema.sql. Re-merging its parents gives the same tree in every other file. schema.sql matches build-schema.sh.

One optional follow-up. #1358 writes subscription_ends_at at checkout. Once both PRs are in, two lines will be out of date: the comment at billing.js:53-55 ("only a subscription update writes it") and the same line in the description. Whichever PR merges second can change them to "it can lag behind Stripe".

Deploy order: 00222, then the server, then the web.

  • The server needs CANCEL_FEEDBACK_EMAILS and the existing Resend env. Without them, every wait now answers not_sent, so customers can only cancel.
  • If the web goes out first, cancelling still works. But the answer is dropped, and every wait fails with "Couldn't send your message".

Merge notes

  • It merges cleanly on current main (a08cbc68) and contains no other open PR.
  • It also merges cleanly with #1358 and #1328. With #1328, the merged schema.sql matches what build-schema.sh builds.
  • 00222 doesn't clash with any migration number, and it isn't on prod yet.

00222 is applied on production (RLS on, no access for anon/authenticated). Merging waits for the server deploy with CANCEL_FEEDBACK_EMAILS set, since the web would otherwise call a route the running server doesn't have yet.

@gkhngyk
gkhngyk merged commit 401558d into ansvisor:main Oct 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants