fix(billing): make Stripe checkout actually work end-to-end #82

Merged
gmackie merged 1 commit from fix/stripe-checkout-e2e into main 2026-07-12 16:11:21 +00:00
Owner

Closes the gaps that made checkout non-functional in production:

  1. Webhook was blocked by auth middleware (no session cookie on Stripe POSTs) — completed payments never activated Pro. Now allowlisted; the route verifies Stripe signatures itself.
  2. constructEvent → constructEventAsync — sync crypto is unavailable on the Workers runtime.
  3. Revenue hole: subscription.upgrade let any authed user set plan: pro directly. Now FORBIDDEN for paid plans (new tests).
  4. Downgrade kept charging: flipping the DB row didn't cancel the Stripe subscription. Now cancels at period end and lets the webhook sync the flip.
  5. Pro users get a Manage billing portal button; pricing page deep-links to checkout; success/cancel banners.

Still required ops-side (not in this PR): wrangler secret put STRIPE_SECRET_KEY / STRIPE_WEBHOOK_SECRET / STRIPE_PRO_PRICE_ID + APP_URL, create the Pro Price, and register the webhook endpoint in the Stripe dashboard.

🤖 Generated with Claude Code

Closes the gaps that made checkout non-functional in production: 1. **Webhook was blocked by auth middleware** (no session cookie on Stripe POSTs) — completed payments never activated Pro. Now allowlisted; the route verifies Stripe signatures itself. 2. **`constructEvent` → `constructEventAsync`** — sync crypto is unavailable on the Workers runtime. 3. **Revenue hole**: `subscription.upgrade` let any authed user set `plan: pro` directly. Now FORBIDDEN for paid plans (new tests). 4. **Downgrade kept charging**: flipping the DB row didn't cancel the Stripe subscription. Now cancels at period end and lets the webhook sync the flip. 5. Pro users get a **Manage billing** portal button; pricing page deep-links to checkout; success/cancel banners. Still required ops-side (not in this PR): `wrangler secret put` STRIPE_SECRET_KEY / STRIPE_WEBHOOK_SECRET / STRIPE_PRO_PRICE_ID + APP_URL, create the Pro Price, and register the webhook endpoint in the Stripe dashboard. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(billing): make Stripe checkout actually work end-to-end
All checks were successful
CI / ci (pull_request) Successful in 5m26s
aa2d979599
- Allowlist /api/stripe/webhook in middleware: Stripe's signed POSTs carry no
  session cookie, so the webhook was redirected to /login and completed
  checkouts never flipped users to Pro. The route verifies signatures itself.
- Use constructEventAsync: the sync variant needs synchronous crypto, which
  the Workers runtime doesn't have — every real event would 400.
- Close the self-upgrade revenue hole: subscription.upgrade now rejects paid
  plans (FORBIDDEN); pro/enterprise only activate via the webhook sync.
- Downgrade cancels the Stripe subscription (cancel_at_period_end) instead of
  flipping the DB row while Stripe keeps charging.
- Pro subscribers get a Manage billing button (customer portal) instead of a
  dead 'Current plan' label.
- Pricing page Pro CTA deep-links to /settings/billing through login.
- Read ?checkout= / ?billing= params on the billing page for confirmation UX.
- Document STRIPE_* + APP_URL envs in apps/web/.env.example.

Web 435 tests pass, api 598 pass (incl. new upgrade-guard tests), repo
typecheck 9/9.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
gmackie deleted branch fix/stripe-checkout-e2e 2026-07-12 16:11:21 +00:00
Sign in to join this conversation.
No description provided.