Repository navigation
fix(billing): anchor monthly quotas to the subscription period, not the calendar month - #500
Merged
Merged
Conversation
…he calendar month Volume analysis, content brief and site audit quotas counted usage since the 1st of the calendar month, while the billing UI says the plan renews on the subscription's anniversary day — a customer whose subscription renewed mid-month kept seeing an exhausted quota that would not reset for another week or more, despite having just paid. quotaPeriodStart() now derives the window from organizations.subscription_ends_at (Stripe's current_period_end, kept fresh by the webhook): the quota window is the billing month containing now, computed with Stripe-style day clamping. The month walk also handles webhook lag right after renewal and annual billing. Orgs without an active subscription fall back to the old calendar-month window, and self-hosted paths are unaffected (unlimited). Error and UI copy now say the quota resets when the subscription renews. Window math lives in quota-period.js as pure functions with unit tests (the supabase config exits the process when env vars are missing, so the tests must not import plan-guard).
8 of 12 tasks
6 of 7 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
Volume analysis, content brief and site audit quotas counted usage since the 1st of the calendar month, while the billing UI tells the customer their plan "renews on" the subscription's anniversary day. A customer whose subscription renewed mid-month kept seeing an exhausted quota that would not reset for another week or more — despite having just paid.
quotaPeriodStart(orgId)derives the quota window fromorganizations.subscription_ends_at(Stripe'scurrent_period_end, kept fresh by the webhook): the window is the billing month containing now, so quotas renew the moment the subscription renews.ends_atbriefly in the past → window starts today, not last month) and annual billing (ends_atfar in the future → still a monthly window on the billing day). Day-of-month is clamped Stripe-style (a subscription anchored on the 31st resets on Feb 28/29).server/src/lib/quota-period.jsas pure functions with unit tests (8 new — the supabase config exits the process when env vars are missing, so tests must not importplan-guard).Related issue
—
Type of change
fix— Bug fixHow to test
yarn testfromserver/—quota-period.test.jscovers the monthly window, mid-period, webhook lag, annual billing and short-month clamping cases.subscription_ends_at) — the quota status endpoint reports usage counted from the billing day, not the 1st.subscription_ends_at = NULLor an inactive status keep the calendar-month window.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)