Skip to content

fix(billing): annual plans include a year of credits, plan switches rebase the usage limit - #10386

Merged
waleedlatif1 merged 7 commits into
stagingfrom
fix/billing-plan-correctness
Nov 25, 2026
Merged

waleedlatif1 merged 7 commits into
stagingfrom
fix/billing-plan-correctness

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Annual plans get a year of credits. An annual Pro/Max/Team period is the whole year, but its included usage was one month's worth, so annual subscribers hit their cap after a month of usage (weekly refresh only hid part of it).
    • getPlanPricing now takes the subscription and returns 12× the monthly allowance on annual billing, reading the interval from the column or metadata (resolveBillingInterval moved into subscriptions/utils).
    • Every path uses it: the personal and org limit floors, threshold billing, cycle close, the final invoice, credit grants.
    • The hourly reconcile-billing-seats cron re-syncs settled annual subscriptions (syncAnnualPlanUsageLimits), so existing annual payers are raised without a data migration. The sync only raises.
    • The checkout webhook writes the interval before the limit sync, so new annual subscribers start at the annual floor.
  • Annual Team seats are prorated. A seat added partway through the year includes only the months left, matching Stripe's prorated charge, so a late seat can't buy a year of credits.
    • Migration 0474_annual_seat_allowance adds three nullable columns: allowance_period_start, allowance_seats, allowance_seat_months.
    • The hourly sweep keeps the seat-months in step with seats. It keeps a year's count until that year's cycle close, which prices the closed year with it.
    • The sweep pages through every annual subscription, re-reads each row before syncing it, and backfills billing_interval on rows that kept it only in metadata.
  • Cycle close prices a closed period from its own length. After a monthly → annual switch, the closed month is billed against one month's allowance, not the new year's.
  • Annual downgrades wait for renewal. A lower tier mid-term would re-price usage the old tier covered, so switch-plan refuses it with a clear message.
  • Plan switches rebase the usage limit. A Max → Pro or annual → monthly switch left the old, higher limit in place, which read as on-demand usage the payer never turned on and billed overage past the new allowance.
    • recordPlanSwitch (new, in core/plan-switch.ts) writes the plan and interval (column and metadata) and moves the limit to the new allowance.
    • A raised limit keeps its on-demand headroom, rescaled across an interval change.
    • An unlimited limit stays unlimited, and a personal trial keeps its allowance.
    • switch-plan no longer writes the database itself.
  • Billing page matches the server.
    • The personal usage-limit minimum came from the tier price ($25) while the server enforces the included credits ($30). The billing DTO now carries includedUsage, which the page uses for both the minimum and on-demand math.
    • A past-due or billing-blocked plan no longer offers limit edits the server refuses. The payment-method row and a refused plan switch explain why, with separate wording for a failed payment and a dispute.
    • Annual plans show the discounted monthly price ($21.25, not $25), and only org plans say "per user".
    • Limit errors state the minimum in credits, matching the input.
  • Invites.
    • A trialing Pro could send invites that failed on acceptance; the invite policy now treats a trial like Free.
    • The invite dialog says an accepted member adds a prorated paid seat (or, on self-serve Enterprise, is trued up quarterly).
  • Copy: the pricing FAQ, the costs docs and the usage-limit tooltip describe the annual allowance.

Type of Change

  • Bug fix

Testing

  • New lib/billing/plan-allowance.integration.ts (real Postgres), 13 cases:
    • annual limit floor (column and metadata interval), annual overage, annual Team org floor, the hourly annual re-sync
    • prorated late Team seat, closed monthly period after an annual switch
    • Max → Pro rebase, kept and rescaled headroom, unlimited kept, trial untouched
  • Proved red: reverting the annual multiplier, the seat proration, the closed-period pricing, the rebase guard and the trial guard each fail their cases.
  • trial.integration.ts and enterprise-self-serve.integration.ts pass (the self-serve error assertion now expects credits).
  • Unit tests beside every changed file pass. check:source-conventions and check:unused-exports baselines shrank. Also ran check:boundaries, check:comment-hygiene, check:file-names and check:api-validation:strict. CI runs type-check and the full audits.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 25, 2026 12:00am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 41 files

Confidence score: 3/5

  • In seats.ts, annual Team orgs with a null billing_interval column can get the monthly floor applied to added seats, even though the annual interval is in metadata. Pass the resolved interval instead of the raw column.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/billing/organizations/seats.ts">

<violation number="1" location="apps/sim/lib/billing/organizations/seats.ts:141">
P2: Pass the resolved interval here, not the raw column. For annual Team orgs whose `billing_interval` column is null, the interval exists only in `metadata`, so this sets the monthly floor and the added seat's annual allowance waits for the next hourly sweep. Use `resolveBillingInterval(orgSubscription)` and import it from `@/lib/billing/subscriptions/utils`, which this file already imports from.</violation>
</file>

This PR changes payment, billing, or quota logic. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/lib/logs/execution/logger.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The latest changes appear safe to merge.

Summary

This PR gives annual plans twelve months of included credits, prorates annual Team seat credits, and moves spending limits when plans change.

  • Annual Pro and Team plans include a year of usage.
  • Annual Team allowances follow seat changes during the year.
  • Plan switches move the usage limit to the new allowance.
  • The billing page shows the right limit floor and plan price.
  • Invite dialogs explain seat charges and trial invite limits.
  • Cycle-close billing uses the allowance for the period that ended.
  • The source-check baselines match the updated code.

Reviews (5) · Last reviewed commit: "fix(billing): price fractional seat-mont..." · Reviewed by Greptile

Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/lib/billing/cycle-close.ts Resolved
@waleedlatif1
waleedlatif1 force-pushed the fix/billing-plan-correctness branch from eecf532 to d3f402e Compare November 24, 2026 23:27
…ar's seat-months until it closes, dispute-aware copy
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/lib/logs/execution/logger.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 52 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/lib/billing/organization.ts Resolved
…afe limit rebase, test schemas carry the allowance columns
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/lib/billing/organization.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 56 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/billing/organization.ts Resolved
…s, allowance and limit writes in one transaction
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/lib/billing/organization.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 56 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 9ded3fc into staging Nov 25, 2026
87 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/billing-plan-correctness branch November 25, 2026 01:38

This branch was previously deployed

1 inactive deployment
Preview — 4bae14c3 Deployed Nov 25, 2026 by vercel[bot]
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.

1 participant