Guides
Setup Stripe for Payments
Accept one-time payments and subscriptions with Stripe integration.
Prerequisites
- A Stripe account
- The Stripe CLI installed for local webhook testing
1. Create Products and Prices
- Go to Stripe Dashboard → Products
- Create a product (e.g. "BetterStarter Core")
- Add a one-time price for lifetime access (or a recurring price for subscriptions)
- Copy the Product ID (
prod_...) and Price ID (price_...)
2. Configure Environment Variables
Add the following to your .env.local:
# Stripe keys
STRIPE_SECRET_KEY=sk_test_xxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxx
# Product and price IDs
VITE_STRIPE_PRODUCT_CORE_ID=prod_xxxx
VITE_STRIPE_PRICE_CORE_ONE_TIME_ID=price_xxxx
# Optional: auto-applied promotion code
VITE_STRIPE_PROMOTION_CODE_ID=promo_xxxx3. Forward Webhooks Locally
Stripe sends events (payment completed, subscription updated, etc.) to your webhook endpoint. During development, use the Stripe CLI to forward these to your local server:
# Login to Stripe
stripe login
# Forward webhooks to your local server
stripe listen --forward-to localhost:3000/api/stripe/webhookCopy the whsec_... signing secret from the CLI output and set it as STRIPE_WEBHOOK_SECRET in your .env.local.
4. Test a Purchase
- Start the dev server and Stripe CLI webhook forwarding
- Navigate to the pricing section on the homepage
- Click the purchase button
- Use the test card number
4242 4242 4242 4242with any future expiry and any CVC - After checkout, you'll be redirected to
/purchase/success
Architecture
The billing system is provider-agnostic by design:
src/constants/billing.tsholds product/price IDs and configsrc/lib/billing/providers/stripe.tsimplements the Stripe providersrc/routes/api/stripe/webhook.tshandles incoming Stripe eventssrc/lib/billing/server.tsexposes server functions for creating checkout sessions and portal sessions
To add another provider (e.g. Lemon Squeezy), implement the BillingProvider interface and register it in src/lib/billing/providers/index.ts.
Production Setup
- Switch to live mode in the Stripe Dashboard and copy your live secret key (
sk_live_...) - Create products and prices in live mode
- Add a webhook endpoint at
https://yourdomain.com/api/stripe/webhookand select the events:checkout.session.completed,customer.subscription.created,customer.subscription.updated,customer.subscription.deleted - Set
STRIPE_SECRET_KEY,STRIPE_WEBHOOK_SECRET, and the product/price IDs in your hosting platform's environment variables
Troubleshooting
- Webhook signature verification failed: Make sure
STRIPE_WEBHOOK_SECRETmatches the CLI or dashboard signing secret. - Customer not found: Verify the user is logged in before checkout, or check the
billing_customertable. - Events not arriving: Confirm the Stripe CLI is running and forwarding to the correct port.