Setup Stripe
Configure your Stripe API keys, create products, and set up webhooks.
Environment Variables
| Variable | Description | Type | Source |
|---|---|---|---|
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY | Stripe publishable key for client-side* | public safe | Stripe Dashboard → Developers → API keys |
STRIPE_SECRET_KEY | Stripe secret key for server-side* | server secret | Stripe Dashboard → Developers → API keys |
STRIPE_WEBHOOK_SECRET | Webhook signing secret for verifying events* | server secret | Stripe Dashboard → Developers → Webhooks |
STRIPE_PRICE_ID_BASIC | Price ID for basic subscription tier | server safe | Stripe Dashboard → Products → Price ID |
STRIPE_PRICE_ID_PRO | Price ID for pro subscription tier | server safe | Stripe Dashboard → Products → Price ID |
* Required variable
Step 1: Get API Keys
- Go to Stripe Dashboard → Developers → API keys
- Copy your Publishable key (starts with
pk_) - Copy your Secret key (starts with
sk_)
Test vs Live Keys
Use test keys (starting with
pk_test_ and sk_test_) during development. Switch to live keys only in production.Step 2: Create Products & Prices
- Go to Stripe Dashboard → Products
- Click "Add product"
- Create your subscription tiers (e.g., Basic, Pro)
- Set pricing (monthly/yearly)
- Copy the Price ID for each tier (starts with
price_)
Step 3: Set Up Webhooks
- Go to Stripe Dashboard → Developers → Webhooks
- Click "Add endpoint"
- Enter your webhook URL:
https://your-domain.com/api/webhooks/stripe - Select events to listen for:
checkout.session.completedcustomer.subscription.updatedcustomer.subscription.deletedinvoice.payment_succeededinvoice.payment_failed
- Copy the Signing secret (starts with
whsec_)
Local Development
For local webhook testing, use the Stripe CLI:
stripe listen --forward-to localhost:3000/api/webhooks/stripeStep 4: Add to .env.local
.env.local
# Stripe Configuration
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_xxxxx
STRIPE_SECRET_KEY=sk_test_xxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxx
# Subscription Price IDs
STRIPE_PRICE_ID_BASIC=price_xxxxx
STRIPE_PRICE_ID_PRO=price_xxxxxVerify Setup
Test your Stripe integration:
- Restart your development server
- Navigate to a checkout or pricing page
- Use Stripe test card:
4242 4242 4242 4242 - Verify the webhook receives events (check Stripe Dashboard → Developers → Webhooks)
