Repository navigation
feat(billing): show the trial's AI credit without a percentage, and let admins start the plan now - #1818
Merged
Conversation
Buying a trial now (trial_end: now) starts the first paid period that day, and the monthly quotas, AI usage among them, count from that period (quotaPeriodStart, from subscription_ends_at). Only the webhook wrote the new period end, so until it landed the meter read the whole trial's usage against the plan's full budget. - PATCH /api/stripe/subscription writes subscription_ends_at with the plan and status, as the webhook does. - Billing reads the AI usage again after a plan change: the header meter (and its banners) and the "This period's AI usage" card. - Tests: the buy-now write, the webhook's trialing -> active update, the quota window starting at the purchase, and both reads again. - FAQ: buying during the trial starts the AI usage again from 0%. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tart the plan from it In the free trial, one Content Editor page reads as a large share of the small trial AI budget, so the trial seemed to allow only a few pages (decided 2026-10-29). The trial's AI credit now shows no percentage, and an admin can start the plan when it runs low. - The header meter reads "Trial credit", then "Almost used" from 80% and "Used up". Its popover, Billing's AI usage card and Chat's plan card show the same, with when the trial ends. They show no share, no bar and no per-feature shares. Improve's tooltip names none either. - From 80% the band and the toast say "Your trial AI credit is almost used". - Start my plan now opens a dialog that names the plan, what is charged today and that the free trial ends now; nothing to type, the card is on file. It sits in the band, the popover and the Billing card, and does what Billing's Buy now does (PATCH /api/stripe/subscription, buyNow, the first-month code on a monthly plan). A turned-down code shows the full price to confirm again; a declined card keeps the trial and offers Update card. The usage starts from 0 (ansvisor#1804). Billing reads its plan and AI usage cards again (PLAN_STARTED_EVENT). - In the popover the dialog lives outside it, since the popover closes as the dialog opens. - Admins only, as the route checks. Other members read "To start the plan now, ask an admin of your workspace." - Help: settings/trial-ai-credit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 30, 2026
Merged
6 tasks done
gkhngyk
previously approved these changes
Oct 30, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Reviewed what this PR adds on top of #1804 (0b10d6e4..979e3e5d). Approving.
What I checked
- Buying stays on the server's checks. Start my plan now reuses
PATCH /api/stripe/subscriptionwithbuyNow, the same path as Billing's Buy now. The route requires an admin of the caller's own organization (403admin_onlyotherwise), takes the organization from the session rather than the body, checks the plan and period withplanRequestSchema+planChange(Starter/Growth only, buy-now only whiletrialing, the promo code only on a monthly plan), and usespayment_behavior: 'error_if_incomplete', so a declined card or one that needs 3DS changes nothing and the trial carries on. Hiding the button for non-admins is only the UI side of that. - Double clicks. The confirm button is disabled while the request runs, and the dialog can't close mid-request. A second request after the first one went through is refused (
Only a free trial can be bought now), and reopening the dialog reads the subscription again and shows "Your plan has already started." - Dialog vs charge. The amount shown uses the same
periodPrice/firstMonthPrice/FIRST_MONTH_CODEas Billing, sends the trial's own plan and period, and when the code is gone it shows the full price and asks again instead of charging it. - No percentage in the trial: the header meter (label, aria-label, title, popover; the page and feature shares are hidden), the banner and toast (
banner.warningTrialhas no{percent}), Billing's AI usage card, Chat's Your plan card and the Improve hint's title. Paid plans look the same as before. - Other members: "ask an admin to start the plan" in the band, popover and card. No Start button and no dialog.
- Billing refresh:
PLAN_STARTED_EVENTupdates the plan card and reloads the AI usage card.router.refresh()andrefreshAiUsage()take care of the header. - No migrations, no new Supabase queries or embeds, no new routes. The read-only gate coverage passes.
Tests (PR head, which already contains current main)
plan-row.test.ts(client import walk), ai-usage components, the AI usage card, billing section, plan switcher, the Stripe subscription and webhook routes, chat-access, prompt-improve,lib/billing, subscription-guard coverage: 27 files, 256 passed.- Help validation: 5 passed. Web
tsc --noEmitis clean, and eslint and prettier are clean on the touched files.
Merge status: clean on main. It conflicts only with #1846 (billing-section.tsx and its test, adjacent imports/JSX, easy to resolve). #1806, #1823 and #1845 merge cleanly with it.
Non-blocking, for later
- Cancelled trial + #1823. If a trial set to cancel at period end is started now, Stripe clears
cancel_at_period_end. The buy-now path's optimistic organization update doesn't, though. Once #1823 adds itsorganizations.cancel_at_period_endmirror, the "plan ends" band would stay until the webhook arrives. Whichever of the two merges second should addcancel_at_period_end: falseto the buy-now update. - A code Stripe refuses on the update itself (for example a per-customer or first-time restriction on the coupon) currently comes back as
payment_failed("Update card"), because only a missing or inactive code returnsinvalid_promo_code. This comes from main's route, not from this PR. - Two tabs at once. An idempotency key on the buy-now update (for example the subscription id + its
trial_end) would make two simultaneous submits from separate tabs a single Stripe call. Also main's route. - Popover button timing. The popover shows Start my plan now at any level, but the bands and the card show it only from 80%. The help article says "once the credit is almost or all used". Either is fine, as long as the two say the same.
- #1846 trial line. Its "Trials can't buy packs. Choose a plan" could point to Start my plan now once both are in.
This was referenced Oct 30, 2026
Merged
Merged
The page now reaches Start my plan now, which reads FIRST_MONTH_OFFER when it loads, so the plans mock keeps the module's other exports.
gkhngyk
approved these changes
Oct 30, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Merging in order with the other approved PRs. One more commit: the brands page test mocks @/config/plans partially, because the page now reaches Start my plan now, which reads FIRST_MONTH_OFFER when it loads (the web CI failed on it).
7 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
From onboarding testing: one article used about 5.7% of the $2 trial AI budget. A trial user then reads that as "about 17 articles on this plan", though on Growth the same article is about 0.5%. When the trial budget ran out, the trial went on but the AI couldn't be used. The product owner approved this in a local preview.
Stacked on #1804 (AI usage restarts at 0 on purchase). The diff against main includes #1804 until it merges.
No percentage during the trial
Start my plan now
FIRST_MONTH_CODE): half today, "then $X a month".PATCH /api/stripe/subscription { newPlanId, interval, buyNow, promoCode? }, thenrouter.refresh, the AI usage is read again, andPLAN_STARTED_EVENTrefreshes Billing's plan and AI cards. With fix(billing): start the AI usage from 0 as soon as a trial is bought #1804, usage starts from 0.Help: new
help/settings/trial-ai-credit.md(approved: false).Related issue
None. Product owner's onboarding feedback.
Type of change
feat— New featureHow to test
Local preview, light and dark, at 80% and 100%: shown to and approved by the product owner. Locally the confirmation can't read the plan without a Stripe key; on staging it shows the charge.
Checklist
🤖 Generated with Claude Code