Repository navigation
feat(billing): self-serve Enterprise billing — auto-pay, quarterly seat true-ups, on-demand overage - #10374
feat(billing): self-serve Enterprise billing — auto-pay, quarterly seat true-ups, on-demand overage#10374waleedlatif1 wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
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
[High impact] The PR changes Enterprise usage charges, seat admission, scheduled billing, and Stripe invoice collection. Fix the invoice-success path before merging so paying one invoice cannot clear blocks caused by another unpaid invoice. Findings
SummaryAdds self-serve Enterprise billing with saved payment methods, customer-set usage limits, and seat true-ups.
|
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 55 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
cdcf3c9 to
1c07331
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
…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.
…al credit spend, seat-cap kind in UI
…window rate, final invoice payment method
…-pay; route true-up payment events
1c07331 to
c42155c
Compare
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
| 'overage_billing', | ||
| 'overage_threshold_billing', | ||
| 'overage_threshold_billing_org', | ||
| 'enterprise_seat_true_up', |
There was a problem hiding this comment.
Unpaid invoices lose their block
Adding enterprise_seat_true_up to this lookup sends successful seat payments through unblockOrgMembers. That clears every payment_failed block for the organization, even when another true-up or overage invoice remains unpaid. These invoices are separate from renewals, so the subscription can remain active throughout. Check for other unpaid invoices before restoring access.
Summary
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/api/organizations/[id]/payment-method); thecheckout.session.completedwebhook switches the contract tocharge_automaticallywith that default method. Admins can return a customer to invoices (POST .../invoice-payment)resolveSeatCap→fixed | baseline | on-demand, honouring a pending admin change). An hourly sweep inreconcile-billing-seatsrecords 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 — newenterprise_seat_true_uptableorganization.self_serve_usage_limitso 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 firstauto_advance: false, so a failed auto-charge is not retried by Stripe; the final-overage invoice still duplicates the outbox invoice builderType of Change
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 redlib/billing,lib/admin,lib/invitations,lib/workspaces, billing/org routesbun 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)Checklist
test-auditauthoring gate)