Payments
Stripe integration for subscription billing — checkout sessions, customer portal, webhooks, and full subscription lifecycle management.
What's Included
- Checkout — Stripe Checkout sessions with trial periods and promotion codes
- Customer Portal — self-serve billing management (upgrade, cancel, update payment method)
- Webhooks — automatic subscription status sync (active, canceled, unpaid)
- Pricing Page — server-rendered prices pulled from Stripe in real time
- Subscription Management — database schema tracks plan, status, and Stripe IDs
Pricing Page
The pricing page at /pricing fetches products and prices directly from Stripe. Products named Base and Plusare displayed in gradient-ring cards with checkout buttons. If Stripe isn't configured, fallback default pricing is shown.
Checkout Flow
- User clicks a plan on the pricing page
- Browser POSTs to a server action with the
priceId - Server creates a Stripe Checkout session with trial and return URLs
- User is redirected to Stripe's hosted checkout page
- After payment, Stripe redirects back to
/api/stripe/checkout - The success handler creates the team and sets the session cookie
Webhook Events Handled
| Event | Action |
|---|---|
customer.subscription.updated | Updates plan, status, and product ID in the database |
customer.subscription.deleted | Clears subscription fields (downgrade to free) |
Stripe CLI for local testing
Install the Stripe CLI and run stripe listen --forward-to localhost:3000/api/stripe/webhook to forward webhook events to your local dev server.