Self-serve plan changes and invoice history on the billing page #503
Opennkem-okafor wants to merge 4 commits into main from billing/self-serve-plan-change· opened 4 days ago
+124−4
nkem-okafor commented 4 days agoAuthor
Context
Plan upgrades still go through support. This lets org admins switch plan and seat count themselves and
shows the last 12 invoices on /billing.
Changes
changePlan Server Action: updates the existing Stripe subscription (with proration) or creates one
for orgs that never had one, then records the plan and an audit log entry
getOrgBilling and getRecentInvoices are wrapped in unstable_cache (5 min, billing tag) since
the billing page was making 3 Stripe calls per load and we were getting rate limited in the EU region
updateTag("billing") after a change so the admin sees the new plan immediately
Stripe webhooks (/api/webhooks/stripe) were getting 307'd to /login by the proxy, so API routes are
now excluded from the matcher. Unauthenticated API calls also get a JSON 401 instead of a redirect.
Testing
Stripe test mode: starter to growth with proration, new subscription for a fresh org, invoices render.
Webhook delivery is green again in the Stripe dashboard.
Context
Plan upgrades still go through support. This lets org admins switch plan and seat count themselves and shows the last 12 invoices on
/billing.Changes
changePlanServer Action: updates the existing Stripe subscription (with proration) or creates one for orgs that never had one, then records the plan and an audit log entrygetOrgBillingandgetRecentInvoicesare wrapped inunstable_cache(5 min,billingtag) since the billing page was making 3 Stripe calls per load and we were getting rate limited in the EU regionupdateTag("billing")after a change so the admin sees the new plan immediately/api/webhooks/stripe) were getting 307'd to/loginby the proxy, so API routes are now excluded from the matcher. Unauthenticated API calls also get a JSON 401 instead of a redirect.Testing
Stripe test mode: starter to growth with proration, new subscription for a fresh org, invoices render. Webhook delivery is green again in the Stripe dashboard.