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.

nkem-okafor added 4 commits 4 days ago
Cache org billing lookups1cbf858
Add recent invoices table1bbf83f
Add changePlan server action1abf825
Exclude API routes from proxy matcher19bf80c

Review required

Review the changes, then submit to get graded.

Some checks haven’t completed yet

1 check: dojo / review-grader

Keyboard shortcuts

Site-wide

Focus the search bar
/
Show this dialog
?

Pull request

Move to the next file
j
Move to the previous file
k
Filter changed files
t
Comment on the selected lines
c
Select a range of lines
Shiftclick