Repository navigation
feat(settings): ask why before cancelling, and offer three days to put it right - #1312
Conversation
…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]>
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]>
|
@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:
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
left a comment
There was a problem hiding this comment.
A few fixes before merge:
- Admins only on the server too.
server/src/routes/billing.js:28-34readsprofiles.rolebut never checks it. Any member can postchoice: 'cancel', and the team gets "… cancelled their plan" while nothing changed in Stripe. #1300 makesDELETEadmin-only, so return 403admin_onlyhere unlessprofile.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) behindcanAdmintoo. Add a route test: a manager gets 403, and nothing is inserted or e-mailed. - 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. Inbilling.js:47-51, also selectstripe_subscription_id. Answer 400 when it's null orsubscription_statusisn'tactive/trialing/past_due. Forwait, also answer 400 whensubscription_ends_atis withinWAIT_DAYS. Without these checks, a direct POST can promise the customer an answer that comes after they've already renewed. - 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". - Regenerate
web/src/types/supabase.ts. 00222 addscancellation_feedback, but the generated types weren't updated. Migration PRs carry the regen, as #1257 did. - 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 giveanonandauthenticatedevery privilege on this table of free-text customer messages. Addrevoke all on public.cancellation_feedback from anon, authenticated;as 00183 does, then rebuildschema.sql. - Test fixtures.
server/src/lib/cancel-feedback.test.js:46-48andserver/src/routes/billing.test.js:71, 124use the team's real addresses. Useexample.comones, asserver/.env.exampledoes. - 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.sqlmatchesbuild-schema.sh.- Copy is in
en.json, and the dialog uses no<Select>.
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]>
|
@gkhngyk Fixed in e0d98dc, on top of #1300's admin-only cancel (merged in):
Checked as on #1300. |
gkhngyk
left a comment
There was a problem hiding this comment.
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
…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
|
@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 |
gkhngyk
left a comment
There was a problem hiding this comment.
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; canWaitkeeps 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.
-
"Give us 3 days" is refused for orgs whose period end isn't in the DB.
server/src/routes/billing.js:53checkscanWait(org.subscription_ends_at). Onlycustomer.subscription.updatedwrites that column (web/src/app/api/stripe/webhook/route.ts:116-120).checkout.session.completedand/api/stripe/successnever set it, so a new trial hasnulluntil 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
nullthere, 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
nulland a past period end. Also passtoo_latethrough inweb/src/lib/actions/cancel-feedback.ts:41, with its own message pointing to Cancel. Writingsubscription_ends_atat checkout is worth its own fix, since the plan guard's quota period reads it too. - The dialog uses Stripe's period end from
-
A wait the team never hears about still gets "we're on it".
billing.js:91-105answers 201 whateverdeliverEmailreturns. Two cases lead there:CANCEL_FEEDBACK_EMAILSis unset, sofeedbackRecipients()is[]and the status isskipped;- Resend refuses the message (
refused).
In both, the dialog promises an answer by a date, and no one is told. For
choice: 'wait'withskippedorrefused, keep the row with itsemail_status, but answer 503not_sent. Have the dialog say so and point to cancelling or support.unknowncan stay a success, since Resend may have sent it.cancelstays 201, because the plan is already cancelled. Add a route test for each case. -
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.exampledoes.
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-feedbackdoesn't exist on the old server, sosendCancelFeedbackreturnsserver.- 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
…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]>
|
@gkhngyk merged main in (b1f5709;
Writing Checked locally through this branch's route on the dev DB (e-mail off): with a Checks: server format, lint (0 errors) and 2,045 tests; web lint (0 errors), typecheck, 2,732 tests, format:check and build. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. All three items from the last review are fixed in ae30a76f:
- "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). Anullor past value goes through, andbilling.test.jscovers both.too_latenow 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. - A wait the team never hears about. For a wait, an e-mail that was
skippedorrefusednow returns 503not_sent(billing.js:108-115). The row is kept with itsemail_status.unknownand 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". - 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_EMAILSand the existing Resend env. Without them, every wait now answersnot_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.sqlmatches whatbuild-schema.shbuilds. - 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.
Summary
Cancel Subscription now asks what went wrong first, and offers the team three days to put it right (product owner's request).
The dialog (
CancelSubscriptionDialog, replacing the old "Cancel your subscription?" confirm)DELETE /api/stripe/subscription). The answer is sent after the cancel succeeds.canWait, on Stripe's period end fromGET /api/stripe/subscription).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_manyand other failures keep the form, as before.Server (
POST /api/billing/cancel-feedback,routes/billing.js,lib/cancel-feedback.js){ reasons, message (≤ 2,000), choice: 'cancel' | 'wait' }.DELETE /api/stripe/subscriptionis: anyone else gets 403admin_only, and the dialog is behindcanAdmin.no_subscription).too_late) only when the DB knows a period end that is still ahead and too close. A missing or pastsubscription_ends_atmeans the DB is behind Stripe (onlycustomer.subscription.updatedwrites it), and the dialog already checked Stripe's date.email_status(sent / refused / unknown / skipped) is written after the send.not_sent(e-mailskipped, e.g. no addresses set, orrefusedby Resend), so the customer isn't promised an answer by a date.unknowncounts as sent, since Resend may have sent it. A cancel is 201 either way: the plan is already cancelled.CANCEL_FEEDBACK_EMAILS(comma-separated).reply_tois the customer, so the team answers by replying.deliverEmailgained an optionalreplyTo.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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow 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:cancellation_feedbackrow haschoice = 'wait'.CANCEL_FEEDBACK_EMAILSset, the e-mail arrives and Reply goes to the customer.choice = 'cancel'row and e-mail follow.Checked locally against the dev DB:
skippedas Resend isn't set locally).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:
subscription_ends_atnullin the DB (a new trial), "Send and give us 3 days" got through. The row was kept withemail_status = skipped, and the dialog said "Your message didn't reach our team…" with only cancelling left.too_late, and the dialog said "Your plan renews before we could get back to you…" with only cancelling left.Tests:
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 waitskippedorrefused→ 503not_sentand kept,unknown→ 201; the daily limit; admins only; no subscription andtoo_late; a missing or past period end lets a wait through; bad input / no org;email.test.js(+1): reply_to.cancel-subscription-dialog.test.tsx(7, incl.too_late/not_sentleaving only cancelling);lib/billing/cancel-feedback.test.ts(3,canWait);plan-switcher.test.tsx(+1: asks first, then DELETE, onUpdate and the answer).Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) (0 errors; the 6 warnings are in untouched files, as on main)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test(2,732 tests) andyarn build;npm run format,npm run lintandnpm test(2,045 tests);bash supabase/build-schema.sh(schema.sqlincluded).🤖 Generated with Claude Code