Creator
Billing

Stripe

Stripe integration for checkout, subscriptions, and customer management.

Setup

  1. Create a Stripe account at stripe.com
  2. Get your API keys from the Stripe dashboard
  3. Set environment variables:
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_..."
NEXT_STRIPE_SECRET_KEY="sk_..."
NEXT_STRIPE_WEBHOOK_SECRET="whsec_..."
  1. Create products and prices in the Stripe dashboard
  2. Copy the price IDs to config/billing.config.ts

API routes

RouteMethodPurpose
/api/stripe/checkoutPOSTCreate a checkout session
/api/stripe/portalPOSTCreate a billing portal session
/api/stripe/webhookPOSTHandle Stripe webhook events
/api/stripe/plansGETGet available plans
/api/stripe/statusGETCheck subscription status
/api/stripe/invoicesGETGet user's invoices

Webhook setup

  1. In the Stripe dashboard, go to Developers > Webhooks
  2. Add an endpoint: https://yourdomain.com/api/stripe/webhook
  3. Select events: checkout.session.completed, customer.subscription.created, customer.subscription.updated, customer.subscription.deleted, invoice.payment_succeeded, invoice.payment_failed
  4. 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/webhook

Service functions

Helper functions are available in lib/services/stripe-service.ts for creating checkout sessions, managing subscriptions, and interacting with the Stripe API.

On this page

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.