Skip to content

app/: Stripe's webhook and the plans (sc-8900, billing 1) - #61

Merged
ndbroadbent merged 4 commits into
mainfrom
laravel-billing
Dec 2, 2026
Merged

ndbroadbent merged 4 commits into
mainfrom
laravel-billing

Conversation

@ndbroadbent

Copy link
Copy Markdown
Member

Stacked on #60. The first billing slice: Stripe's webhook, ported from server/src/controllers/billing.rs, with the plans.

  • POST /webhooks/stripe is outside the session and CSRF groups. It accepts only signed events: Stripe's t=…,v1=… signature with STRIPE_WEBHOOK_SECRET, within five minutes, compared in constant time. Without a secret it's a 404.
  • What each event does, as today:
    • Checkout of a subscription, or an active subscription, puts the organization on Team.
    • Deleting the subscription puts it back on Free. A plan change emails the billing contact (PlanChanged).
    • Only the organization's own subscription counts, and only events newer than the last one applied (stripe_event_at), so a late "active" never undoes a cancellation.
    • A paid credit-pack Checkout, and an automatic reload's invoice.paid, add their credits once per reference.
    • Past due, unpaid and failed payments show the billing problem and pause automatic reloads. invoice.paid clears it.
  • The plans: billing::{FREE, TEAM, STAFF, plan_by_id}, as today.
  • add_purchased_credits is a stopgap copy. The ledger is visualci features' (app::domain::credits, coming in their API PR). This switches to theirs when it lands, before merge.
  • Keys: STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET come from the cluster's ExternalSecrets in production. Tests sign their own events and never call Stripe.

Tests (app/tests/billing.rs):

  • the signature (the time window, another body, another secret);
  • an unsigned event gets a 401;
  • Team, then Free, and an older event ignored;
  • a pack credited once across Stripe's retry.

Next: Checkout, the portal, packs, payment methods and invoices, then automatic reloads.

@ndbroadbent

Copy link
Copy Markdown
Member Author

Added the billing page's routes (billing 2) to this PR. They're today's /api/ui/billing/plans and /api/ui/orgs/{org}/billing/*, unchanged:

  • Checkout for Team and for credit packs, Stripe's customer portal, automatic reloads, payment methods (list, add, make default, remove) and invoices.
  • Admins only: a member gets a 403 and anyone else a 404.
  • The Stripe client and catalog (products, prices by lookup key, the portal configuration, the customer) run on Laravel's HTTP client.
  • One difference from today: PUT …/auto-reload returns the new setting rather than the organization's usage, until the ledger's usage lands on visualci features' side.

Test (Stripe faked): the plans; a non-member gets 404, a member 403, and an admin gets a Checkout URL with the customer saved on the organization.

@visualci-com

visualci-com Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #340 · 331 unchanged · no changes

This PR vs base: nothing since #214, across 7 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

… within five minutes, constant-time), Team on checkout and active, Free on deletion, only the organization's own subscription and only newer events, packs and automatic reloads credited once per reference, billing problems shown and reloads paused; the plans; STRIPE_SECRET_KEY/STRIPE_WEBHOOK_SECRET
… for Team and for credit packs, Stripe's portal, automatic reloads, payment methods (list, add, default, remove) and invoices, admins only (a member 403, anyone else 404); the Stripe client and catalog (products, prices by lookup key, the portal configuration, the customer) on Laravel's HTTP client
…y, and a webhook event whose livemode doesn't match the key is refused; a subscription event's freshness check and its change happen in one transaction with the organization's row locked; a paid invoice no longer clears the two-subscriptions notice; payment method IDs are letters, digits and underscores only
@ndbroadbent
ndbroadbent merged commit 9f436fc into main Dec 2, 2026
11 checks passed
@ndbroadbent
ndbroadbent deleted the laravel-billing branch December 2, 2026 16:40
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