Skip to content

feat(billing): show the plans in the read-only dialog, with Monthly or Annual and a promo code - #1604

Merged
gkhngyk merged 11 commits into
ansvisor:mainfrom
cihan-gyk:feature/read-only-plan-dialog
Oct 28, 2026
Merged

gkhngyk merged 11 commits into
ansvisor:mainfrom
cihan-gyk:feature/read-only-plan-dialog

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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:

  • Header: "Choose a plan to keep going", with the shared subtitle and the clicked action as a small label. From the banner, the label reads "Your workspace is read-only".
  • Starter $49 and Growth $249 (Popular), each with Choose {plan} and "You'll pay by card on Stripe's checkout." under it.
  • Custom: "Starting at $499/mo" with Contact us (CONTACT_SALES_URL; CUSTOM_PLAN_STARTING_PRICE in config/plans.ts).
  • The features are the Billing cards' own, through a shared usePlanFeatures (components/settings/plan-features.ts), so the two never drift. Billing is unchanged.
  • Monthly / Annual ("Save 20%"): annual shows $470 and $2,390, with the 12× price struck through and "$39.17 a month, billed yearly".
  • Footer: "Prices in USD." and "See everything each plan includes ↗" (PRICING_URL).
  • X, Escape or a click outside closes it. A failed payment keeps feat(web): let a workspace whose plan ended browse read-only, with one "Choose a plan" dialog #1599's "Update payment method" dialog.

Promo code:

  • The API checks it: 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 to lib/billing/promo-code.ts:
  • A valid code (SAVE50) shows a chip with ×. Each card then shows "SAVE50: first month 50% off", $49 struck through, "$24.50 first month" and "then $49/mo". The button reads "Choose Growth · $124.50 today".
  • A bad code reads "“X” isn't a valid code."
  • On Annual, a note reads "SAVE50 is for monthly plans: 50% off the first month. Switch to Monthly".
  • The code's name comes from Stripe, never from the copy.

Choose:

  • Opens Stripe Checkout for that plan and period, as a new subscription, with the code applied as discounts: [{ promotion_code }].
  • With no code, Checkout keeps allow_promotion_codes: true; Stripe doesn't take both.
  • /api/stripe/checkout checks the code again. On an annual plan it answers 400 promo_code_monthly_only; a bad code answers 400 invalid_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 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

  1. cd web && yarn vitest run src/components/billing src/lib/billing src/app/api/stripe src/components/providers
  2. On a cloud set-up, with an organization whose plan ended (see feat(web): let a workspace whose plan ended browse read-only, with one "Choose a plan" dialog #1599): See plans opens the dialog.
    • Try Monthly and Annual.
    • Apply SAVE50, and an invalid code.
    • Choose Growth opens Stripe Checkout with the first month at $124.50.

Checked 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.

  • See plans: the three cards, the features, "Popular", the Stripe note under each button, and the footer.
  • Annual: $588 struck through to $470/yr ("$39.17 a month, billed yearly"), and $2,988 to $2,390.
  • Apply SAVE50:
    • with no Stripe key on this machine, the check failed cleanly: "Couldn't check the code. Try again.";
    • with the promo route stubbed in the page, the chip, the "$24.50 first month" and "$124.50 first month" cards, and "Choose Starter · $24.50 today" / "Choose Growth · $124.50 today" showed;
    • switching to Annual showed the monthly-only note with Switch to Monthly.
  • Nothing scrolls sideways.

Not checked here: Checkout itself (no Stripe key), and the member view, since the demo user is an admin. The tests cover both.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

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

cihan-gyk and others added 3 commits October 27, 2026 17:58
…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]>

@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, 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.tsx conflicts with #1577 (already on main). #1577 added aiMultiple and customPlanPoints() next to planFeatures(), and e8d8d64 moves planFeatures() out to plan-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.json and plans.ts merge on their own.
    • Before merging: after #1599 is squashed, rebase this on main. In plan-switcher.tsx, keep main's customPlanPoints() (with #1598's aiUsageCustomHint) and drop main's local planFeatures() for usePlanFeatures(). aiMultiple(PLANS.enterprise…) can become aiUsageMultiple('enterprise'). plan-switcher.test.tsx checks the custom line, so it will catch a resolution that loses it.
  • Prices.
    • Starter $49 and Growth $249 a month, $470 and $2,390 a year, from PLANS[…].pricing, as on main. "Save 20%" is annualSaving (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, discountedPrice works 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 hasUsedTrial gives no trial. The first invoice is the discounted month.
    • Custom: CUSTOM_PLAN_STARTING_PRICE ($499) and CONTACT_SALES_URL, no Checkout.
  • 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_only on a year (before any Stripe call), 400 invalid_promo_code for a code findPromotionCode doesn't take (before a customer is made or Checkout opens). A valid one goes in as discounts: [{ promotion_code }], and allow_promotion_codes is 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 promo code lookup (lib/billing/promo-code.ts).
    • The shape matches the installed stripe 22.0.0 (API 2026-03-25): promotion.coupon, expanded with data.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-code is signed-in admins only and only says what a code takes off.
  • 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:

  1. 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 puts aiUsageCustom first with aiUsageCustomHint (#1598). ec71ef5 already had to change the wording in two places. A useCustomPlanPoints() next to usePlanFeatures() in plan-features.ts would keep them the same, as the description says for the other cards.
  2. The subscription route's own lookup. The description says #1300's lookup moved to promo-code.ts, but PATCH /api/stripe/subscription (route.ts:197) still runs its own promotionCodes.list and takes any active code, including one kept for another customer or with nothing off. Using findPromotionCode there too would give Billing's "buy now" the same checks.
  3. 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 for month, or limit the coupon in Stripe (applies_to). The check of SAVE50's settings you asked Gökhan for covers the second.
  4. paused. readOnlyReason reads paused as ended, so it gets the plans, but the checkout route counts paused as 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.

cihan-gyk and others added 3 commits October 27, 2026 23:48
…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
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged #1599's new head in (4b17fac). The plan-switcher.tsx conflict with #1577 is resolved as you asked: main's customPlanPoints and aiUsageCustomHint stay, the list is built with usePlanFeatures, and the custom plan's multiple comes from aiUsageMultiple('enterprise'); this PR's own aiMultiple and planFeatures are gone. Checks on the chain's tops: typecheck on every branch; at #1614, yarn test (4,576 tests) and yarn build; at #1613, its tests and yarn build (the editor page's test file timed out under load in the full run and passes alone, 323 tests with the Library's).

gkhngyk pushed a commit that referenced this pull request Oct 28, 2026
… $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
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (8356ba3) via #1599: resolved (dashboard)/layout.tsx (menu access kept with the dialog's organizationId). Typecheck and layout tests pass.

@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, 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.tsx and lib/mcp/data.ts); see #1599. plan-switcher.tsx, plans.ts and en.json merge 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):

  1. One custom plan list. The dialog still builds Custom's points itself (readOnly.plans.customAiUsage, after the fourth point), while Billing puts aiUsageCustom first with its hint. A useCustomPlanPoints() next to usePlanFeatures() would keep them the same.
  2. The subscription route's own lookup. PATCH /api/stripe/subscription still runs its own promotionCodes.list and takes any active code, including one kept for another customer or with nothing off. findPromotionCode there would give Billing's "buy now" the same checks.
  3. 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 for month, or limit the coupon to the monthly prices in Stripe.
  4. paused. readOnlyReason reads paused as ended (plans shown), but Checkout counts it as live and answers 409, which shows as a raw toast.

Merge after #1599.

@gkhngyk
gkhngyk merged commit cbc282e into ansvisor:main Oct 28, 2026
4 of 5 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.

2 participants