Skip to content

feat(billing): self-serve Enterprise billing — auto-pay, quarterly seat true-ups, on-demand overage - #10374

Merged
waleedlatif1 merged 6 commits into
stagingfrom
feat/enterprise-self-serve-billing
Nov 24, 2026
Merged

waleedlatif1 merged 6 commits into
stagingfrom
feat/enterprise-self-serve-billing

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Admins opt an Enterprise contract into self-serve with a per-seat monthly rate (PATCH /api/v1/admin/dashboard/organizations/[id]/self-serve). Turning it on clears the reporting-period anchor so usage resets on Stripe billing dates; turning it off restores the hard caps and emailed invoices, and is refused while members exceed contracted seats
  • Auto-pay: owners/admins save a card or US bank account on Stripe's hosted setup page (/api/organizations/[id]/payment-method); the checkout.session.completed webhook switches the contract to charge_automatically with that default method. Admins can return a customer to invoices (POST .../invoice-payment)
  • Seats: contracted seats become a baseline. Invites, acceptance, SSO and SCIM admit members past it (resolveSeatCap → fixed | baseline | on-demand, honouring a pending admin change). An hourly sweep in reconcile-billing-seats records each window's peak seats past the contract and bills closed windows once (quarters of an annual term, or the monthly term) at the rate the window opened with — new enterprise_seat_true_up table
  • Usage: owners/admins set their own limit (stored in organization.self_serve_usage_limit so the contract webhook keeps it); usage past the included allowance is billed through the existing threshold billing, period close, and cancellation paths. Prepaid credit is spent first
  • Overage, true-up and final invoices follow the subscription's collection method: invoiced customers get an emailed invoice (30-day terms) instead of an open charge nothing collects
  • Billing settings: usage limit + on-demand switch, a three-row Seats section, and a payment-method row for self-serve contracts. Non-self-serve Enterprise is unchanged
  • Follow-ups (pre-existing, not changed here): ad-hoc overage invoices are created with auto_advance: false, so a failed auto-charge is not retried by Stripe; the final-overage invoice still duplicates the outbox invoice builder

Type of Change

  • New feature

Testing

  • lib/billing/enterprise-self-serve.integration.ts (12 tests, real Postgres, Stripe stubbed): usage-limit gating and floor, overage on/off by contract, joins past seats (self-serve admits, hard cap refuses, missing seat rate stays capped), true-up peak/once-only/open-window, auto-pay switch and refusal of foreign/non-self-serve sessions. Reverting the self-serve predicate, the once-only guard, and the join guard each turned their tests red
  • 1,084 affected unit tests across lib/billing, lib/admin, lib/invitations, lib/workspaces, billing/org routes
  • bun run lint, check:migrations origin/staging, drizzle schema sync, bun run generate; check:api-validation:strict, boundaries, client-boundary, comment-hygiene, test-patterns, file-names, source-conventions, explicit-any, react-query, utils, unused-exports (baseline shrunk)
  • Full type-check and test suite in CI

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 24, 2026 8:28pm 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.

All reported issues were addressed across 51 files

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/admin/dashboard.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 revision appears safe to merge.

Summary

Adds self-serve Enterprise billing with saved payment methods, seat true-ups, and usage overage.

  • Enterprise contracts can set usage limits and bill usage beyond their included allowance.
  • Self-serve Enterprise seats can exceed the contract baseline and are billed by window peaks.
  • Enterprise customers can save a payment method or keep emailed invoices for their charges.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Invoice payment succeeds] --> B[Find its subscription]
  B --> C[Read open customer invoices across pages]
  C --> D{Another failed automatic charge for this subscription?}
  D -->|Yes| E[Keep payment block]
  D -->|No| F[Clear payment block]
Loading

Reviews (6) · Last reviewed commit: "fix(billing): scope the failed-invoice c..." · Reviewed by Greptile

Comment thread apps/sim/lib/admin/dashboard.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 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.

@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 55 files

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

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 force-pushed the feat/enterprise-self-serve-billing branch from cdcf3c9 to 1c07331 Compare November 24, 2026 19:51
@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.

@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

…at true-ups, on-demand overage

Admins opt an Enterprise contract into self-serve with a per-seat monthly rate. On a self-serve contract:
- owners and admins save a card or US bank account on Stripe's hosted setup page, and the contract switches from emailed invoices to automatic payment
- members may join past the contracted seats; each quarter (each month on a monthly contract) the peak seats past the contract are invoiced in arrears at the rate the window opened with
- owners and admins raise their own usage limit; usage past the included allowance is billed as overage through the existing threshold billing and period close

Contracts that are not self-serve keep their hard seat and usage caps. Overage, true-up, and final invoices follow the subscription's collection method, so invoiced customers get an emailed invoice instead of an open charge nothing collects.
@waleedlatif1
waleedlatif1 force-pushed the feat/enterprise-self-serve-billing branch from 1c07331 to c42155c Compare November 24, 2026 20:04
@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.

@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 57 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

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.

@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 57 files

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

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

@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 57 files

Confidence score: 5/5

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

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 17b32fb into staging Nov 24, 2026
86 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/enterprise-self-serve-billing branch November 24, 2026 21:10

This branch was previously deployed

1 inactive deployment
Preview — 7d4bb51b Deployed Nov 24, 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