Repository navigation
feat(billing): show the plans in the read-only dialog, with Monthly or Annual and a promo code - #1604
Conversation
…e "Choose a plan" dialog
On the cloud, an ended trial, a cancel during the trial and a cancel
after the first payment can now sign in and look around. They used to
see a full-screen "subscription expired" notice that only signed out.
Onboarding is unchanged: an admin who never started a trial still goes
to the plan step.
- The dashboard layout lets these workspaces in, read-only. A thin
banner says so, with "See plans".
- UpgradeDialogProvider and useUpgradeGate ({ guard, isLocked,
openUpgrade }) open one "Choose a plan to keep going" dialog, with the
action that was clicked as a label.
- Admins go to Billing; members are told to ask their admin.
- A failed payment (past_due, unpaid) says so and opens Stripe's
portal.
- A 402 subscription_inactive from the API opens the dialog
(use-failure-toast, api-failure's subscription class, and the
Webflow, catalog, publish and Send to CMS clients).
- Automatic calls (Library's Webflow status, the editor's link, source,
claim and page reads, Improve's read) aren't sent while locked.
- Billing: an ended subscription starts a new Checkout ("Choose
{plan}", monthly or annual). The checkout route takes admins only,
refuses a second live subscription (409), and validates its body.
Billing reads again after a change.
- MCP: list_ and get_ tools stay open; every other tool, and REST
writes, answer subscription_inactive. Chat and new conversations
answer 402, and runSiteAuditFor, generateBriefFor and
createImproveActionFor check too. A chat message refused by a 402
goes back to the input.
Self-hosted is unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r Annual and a promo code
The "Choose a plan to keep going" dialog for an ended plan now carries
the plans, as the approved design has them.
- Starter and Growth (Popular) have "Choose {plan}"; Custom has "Starting
at $499/mo" and "Contact us". Each lists the Billing cards' features,
through a shared usePlanFeatures.
- Monthly or Annual ("Save 20%"): an annual price shows its struck 12×
price and what it is a month.
- A promo code is checked by the API (POST /api/stripe/promo-code, admins
only), through the same Stripe lookup ansvisor#1300 uses (findPromotionCode,
takesPromoCode: monthly plans only).
- A valid code shows its chip, the first month's price on each card and
in the button ("Choose Growth · $124.50 today").
- A bad one says so; on Annual a note offers Switch to Monthly.
- Choose opens Stripe Checkout for that plan and period, with the code
applied as a discount. The checkout route checks the code again and
refuses it on an annual plan.
- Members see "Ask your admin to choose a plan", with no code field.
- The footer reads "Prices in USD." with a link to the pricing page.
- A failed payment keeps its "Update payment method" dialog.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g does after ansvisor#1598 Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
- Own change and merge.
- The branch is #1599's commit (22fdd46, on 55b49e7) plus e8d8d64 and ec71ef5. I reviewed
22fdd460..ec71ef5e: 17 files, web only. - #1599 merges clean on main (15b5b5f).
- This branch doesn't:
plan-switcher.tsxconflicts with #1577 (already on main). #1577 addedaiMultipleandcustomPlanPoints()next toplanFeatures(), and e8d8d64 movesplanFeatures()out toplan-features.ts. It's this PR's own change that conflicts: on main with #1599 squashed in, and on main with #1598 and #1599, the same file conflicts and nothing else does.en.jsonandplans.tsmerge on their own. - Before merging: after #1599 is squashed, rebase this on main. In
plan-switcher.tsx, keep main'scustomPlanPoints()(with #1598'saiUsageCustomHint) and drop main's localplanFeatures()forusePlanFeatures().aiMultiple(PLANS.enterprise…)can becomeaiUsageMultiple('enterprise').plan-switcher.test.tsxchecks the custom line, so it will catch a resolution that loses it.
- The branch is #1599's commit (22fdd46, on 55b49e7) plus e8d8d64 and ec71ef5. I reviewed
- Prices.
- Starter $49 and Growth $249 a month, $470 and $2,390 a year, from
PLANS[…].pricing, as on main. "Save 20%" isannualSaving(both round to 20). - On Annual, the struck price is 12× the monthly one ($588, $2,988), and "a month, billed yearly" is the annual price over 12, to the cent ($39.17, $199.17).
- With a code,
discountedPriceworks in cents: SAVE50 gives $24.50 and $124.50. An amount off can't go below $0, and an amount off in another currency is refused. - "$124.50 today" holds: this dialog only opens for an ended plan, so the customer already had a subscription and
hasUsedTrialgives no trial. The first invoice is the discounted month. - Custom:
CUSTOM_PLAN_STARTING_PRICE($499) andCONTACT_SALES_URL, no Checkout.
- Starter $49 and Growth $249 a month, $470 and $2,390 a year, from
- Checkout.
- The dialog sends
planId,interval: period,returnTo: 'billing', and the code only when one applies to this period for an admin. Switching to Annual drops the code from the request. - The route checks again: 400
promo_code_monthly_onlyon a year (before any Stripe call), 400invalid_promo_codefor a codefindPromotionCodedoesn't take (before a customer is made or Checkout opens). A valid one goes in asdiscounts: [{ promotion_code }], andallow_promotion_codesis left out then, as Stripe requires. Without a code, Checkout is as before. - #1599's checks still come first: admins only, the caller's own organization, and 409 while a live subscription exists.
- If the code stops working between Apply and Choose, the dialog clears the chip and says so by the field instead of a toast.
- The dialog sends
- The promo code lookup (
lib/billing/promo-code.ts).- The shape matches the installed
stripe22.0.0 (API 2026-03-25):promotion.coupon, expanded withdata.promotion.coupon. - It refuses an inactive, expired, used-up or invalid code, one kept for another customer, and one that takes nothing off. Input is held to Stripe's own characters, so nothing else is sent to Stripe.
POST /api/stripe/promo-codeis signed-in admins only and only says what a code takes off.
- The shape matches the installed
- Members see the plain prices, "Ask your admin to choose a plan" in place of each button, no code field, and Contact us.
- A failed payment still gets #1599's "Update payment method" dialog: the plans only show for
ended. - Tests.
- The PR's billing, Stripe-route, provider and plan-switcher tests pass at the head (17 files, 129 tests).
- With #1599's
checkout/route.ts, the 5 new checkout tests fail and the other 9 pass.
- Before the API deploy. Web only, and only on
/api/stripe/*, which runs on the web. The dialog only shows for a workspace that #1599 lets in read-only, so nothing here depends on the API.
Follow-ups:
- One custom plan list. The dialog builds Custom's points itself, with its own
readOnly.plans.customAiUsage(no hint) placed after the fourth point, while Billing putsaiUsageCustomfirst withaiUsageCustomHint(#1598). ec71ef5 already had to change the wording in two places. AuseCustomPlanPoints()next tousePlanFeatures()inplan-features.tswould keep them the same, as the description says for the other cards. - The subscription route's own lookup. The description says #1300's lookup moved to
promo-code.ts, butPATCH /api/stripe/subscription(route.ts:197) still runs its ownpromotionCodes.listand takes any active code, including one kept for another customer or with nothing off. UsingfindPromotionCodethere too would give Billing's "buy now" the same checks. - Codes on a year in Checkout. With no code applied, Checkout still shows Stripe's own code box on an annual plan (
allow_promotion_codes: true), so SAVE50 can be typed there for a year unless the coupon itself is limited to the monthly prices. Either show the box only formonth, or limit the coupon in Stripe (applies_to). The check of SAVE50's settings you asked Gökhan for covers the second. paused.readOnlyReasonreadspausedasended, so it gets the plans, but the checkout route countspausedas live and answers 409. If a subscription can be paused, it belongs with the payment path (the portal), or the 409 needs words in the dialog. Today it shows the raw error in a toast.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…essage test main's catalog-client test (ansvisor#1583) asks for words for every StoreError code; 'subscription' opens the upgrade dialog instead of saying one, so the test leaves it out, as ansvisor#1613 does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-plan-dialog Co-Authored-By: Claude Opus 5.5 <[email protected]> # Conflicts: # web/src/components/settings/plan-switcher.tsx
|
Merged #1599's new head in (4b17fac). The |
… $50 or more (#1675) * fix(billing): take a hand-set Enterprise AI budget only at the plan's $50 or more Follow-up from #1598 (item 1). The comment said "$50 or more", but any finite number was taken: 0 or a negative number made every AI call answer "budget used up" (reserveAiBudget), and -1 read as unlimited. applyPlanOverrides now takes plan_overrides.improveMonthlyBudgetUsd only when it's a number at or above the plan's budget (Enterprise's $50, the floor the billing cards and the AI usage tiers name); anything else keeps the plan's. Unlimited AI isn't something a customer is given by hand. Tests: 0, -5, -1 and just under the plan's keep the plan's; the AI usage meter reads an override of 0 on the plan's $50. The meter's own test of a $0 budget (still read as used up) now mocks a plan with 0 instead of setting one by hand. Item 2 (#1604's dialog reusing aiUsageCustom) is #1604's to take when it's rebased. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(billing): undo the plans mock in afterEach, so a failing test can't leak it Review follow-up. The "budget of nothing" test undid its plans.js mock at the end of its own body, so a failure there left the next tests reading a $0 budget. The unmock is in afterEach now, beside the supabase one. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
# Conflicts: # web/src/app/[locale]/(dashboard)/layout.tsx # web/src/lib/mcp/data.ts
…alog # Conflicts: # web/src/app/[locale]/(dashboard)/layout.tsx
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups.
Since my last review (ec71ef5), the branch merged #1599's current head (4b17fac), and that merge resolved the plan-switcher.tsx conflict as I asked: main's customPlanPoints() stays, with #1598's aiUsageCustomHint, on aiUsageMultiple('enterprise') from plan-features.ts, and the local aiMultiple()/planFeatures() are gone for usePlanFeatures(). The PR's own commits (e8d8d64, ec71ef5) are unchanged.
What I checked:
- Own change.
origin/pr/1599..4b17fac1: the same 17 files as before (web only, no migration). Prices, the promo code lookup, the Checkout checks and the member view are as in my last review. - Merge state on main (8356ba3). This PR's own change merges clean. The branch as a whole conflicts only through #1599 (
(dashboard)/layout.tsxandlib/mcp/data.ts); see #1599.plan-switcher.tsx,plans.tsanden.jsonmerge on their own. - Tests on this head. The PR's 6 test files pass (62 tests).
tsc --noEmit: no errors. - Before the API deploy: no longer a question. Everything here runs on the web's
/api/stripe/*.
Follow-ups (from last time, none blocking):
- One custom plan list. The dialog still builds Custom's points itself (
readOnly.plans.customAiUsage, after the fourth point), while Billing putsaiUsageCustomfirst with its hint. AuseCustomPlanPoints()next tousePlanFeatures()would keep them the same. - The subscription route's own lookup.
PATCH /api/stripe/subscriptionstill runs its ownpromotionCodes.listand takes any active code, including one kept for another customer or with nothing off.findPromotionCodethere would give Billing's "buy now" the same checks. - Codes on a year in Checkout. With no code applied, Checkout still shows Stripe's code box on an annual plan (
allow_promotion_codes: true). Either show it only formonth, or limit the coupon to the monthly prices in Stripe. paused.readOnlyReasonreadspausedasended(plans shown), but Checkout counts it as live and answers 409, which shows as a raw toast.
Merge after #1599.
Summary
Read-only, part B2: the plans in the "Choose a plan to keep going" dialog. #1599 opens one dialog for every action of a workspace whose plan ended. This PR fills it with the plans, as Ansvisor's approved design has them, so the person can buy from where they are.
Stacked on #1599. This PR's own change is its commits after #1599's: e8d8d64 and ec71ef5. Web only.
The dialog (
components/billing/choose-plan-dialog.tsx), for an ended plan:CONTACT_SALES_URL;CUSTOM_PLAN_STARTING_PRICEinconfig/plans.ts).usePlanFeatures(components/settings/plan-features.ts), so the two never drift. Billing is unchanged.PRICING_URL).Promo code:
POST /api/stripe/promo-code, admins only. It uses the same Stripe lookup feat(settings): buy a trial now from Billing, with annual plans and the SAVE50 offer #1300 uses, moved tolib/billing/promo-code.ts:findPromotionCodechecks the code is active, not expired or used up, not kept for another customer, and gives a percent or USD off;takesPromoCode: monthly plans only, as feat(settings): buy a trial now from Billing, with annual plans and the SAVE50 offer #1300's plan change already ruled.Choose:
discounts: [{ promotion_code }].allow_promotion_codes: true; Stripe doesn't take both./api/stripe/checkoutchecks the code again. On an annual plan it answers 400promo_code_monthly_only; a bad code answers 400invalid_promo_code. Onboarding's checkout is unchanged.Members see "Ask your admin to choose a plan" in place of the buy buttons, under the note "Only an admin can choose a plan for your workspace." There's no code field, prices show without a discount, and Contact us stays.
Related issue
None. Product decision and approved design (Ansvisor, 2026-10-27).
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
cd web && yarn vitest run src/components/billing src/lib/billing src/app/api/stripe src/components/providersChecked in the browser at 1024 px, light and dark, against the dev DB with #1589's API, both in cloud mode. The demo organization was set to a cancelled Growth plan, then put back.
Not checked here: Checkout itself (no Stripe key), and the member view, since the demo user is an admin. The tests cover both.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run in
web/:yarn format,yarn lint(0 errors),yarn typecheck;yarn test(4,248 tests);yarn build.For you, @gkhngyk: please check SAVE50's coupon settings in Stripe. If it's limited to a first purchase (
first_time_transaction) or to some products (applies_to), the dialog shows it as valid but Checkout refuses it. The person then sees Checkout's error.🤖 Generated with Claude Code