Billing
Stripe
Stripe integration for checkout, subscriptions, and customer management.
Setup
- Create a Stripe account at stripe.com
- Get your API keys from the Stripe dashboard
- Set environment variables:
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_..."
NEXT_STRIPE_SECRET_KEY="sk_..."
NEXT_STRIPE_WEBHOOK_SECRET="whsec_..."- Create products and prices in the Stripe dashboard
- Copy the price IDs to
config/billing.config.ts
API routes
| Route | Method | Purpose |
|---|---|---|
/api/stripe/checkout | POST | Create a checkout session |
/api/stripe/portal | POST | Create a billing portal session |
/api/stripe/webhook | POST | Handle Stripe webhook events |
/api/stripe/plans | GET | Get available plans |
/api/stripe/status | GET | Check subscription status |
/api/stripe/invoices | GET | Get user's invoices |
Webhook setup
- In the Stripe dashboard, go to Developers > Webhooks
- Add an endpoint:
https://yourdomain.com/api/stripe/webhook - Select events:
checkout.session.completed,customer.subscription.created,customer.subscription.updated,customer.subscription.deleted,invoice.payment_succeeded,invoice.payment_failed - Copy the webhook signing secret to
NEXT_STRIPE_WEBHOOK_SECRET
For local development, use the Stripe CLI:
stripe listen --forward-to localhost:3000/api/stripe/webhookService functions
Helper functions are available in lib/services/stripe-service.ts for creating checkout sessions, managing subscriptions, and interacting with the Stripe API.