Stripe
Last updated December 18, 2025
Overview
Stripe is a payment processing platform that supports subscriptions, one-time payments, and complex billing scenarios. It provides robust APIs, webhooks, and a customer portal for subscription management.
Account Setup
- Go to stripe.com and sign up for an account
- Complete your business profile
- Add a payment method (for account verification)
- Switch between "Test mode" and "Live mode" using the toggle in the dashboard
- Important: Use Test mode for development, Live mode for production
Get API Keys
- In your Stripe dashboard, go to "Developers" → "API keys"
- You'll see two keys:
- Publishable key: Starts with
pk_test_(test) orpk_live_(live) - Secret key: Starts with
sk_test_(test) orsk_live_(live)
- Publishable key: Starts with
- Click "Reveal" to see the secret key
- Copy both keys - you'll need them in the next step
- Important: Never expose your secret key in client-side code
Create Products
- Go to "Products" in your Stripe dashboard
- Click "Add product"
- Fill in product details:
- Name: Your subscription tier (e.g., "Starter")
- Description: Optional
- Pricing: Set recurring price (monthly, yearly, etc.)
- Click "Save product"
- Copy the Price ID (starts with
price_) - you'll need this in your code - Repeat for each subscription tier you want to offer
Configure Webhooks
Webhooks notify your app when payment events occur (subscription created, canceled, payment succeeded, etc.).
Step 1: Create Webhook Endpoint
- Go to "Developers" → "Webhooks" in your Stripe dashboard
- Click "Add endpoint"
- Set the endpoint URL:
- Development:
http://localhost:3000/api/webhooks/stripe(use ngrok for local testing) - Production:
https://yourdomain.com/api/webhooks/stripe
- Development:
- Select events to listen to (recommended: all
customer.subscription.*events) - Click "Add endpoint"
Step 2: Get Webhook Secret
- After creating the endpoint, click on it to view details
- Click "Reveal" next to "Signing secret"
- Copy the webhook secret (starts with
whsec_) - This is your
STRIPE_WEBHOOK_SECRET
Environment Variables
Add these variables to your .env.local file:
# Stripe (Test mode) NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_xxxxxxxxxxxxx" STRIPE_SECRET_KEY="sk_test_xxxxxxxxxxxxx" STRIPE_WEBHOOK_SECRET="whsec_xxxxxxxxxxxxx" # Stripe Products NEXT_PUBLIC_STRIPE_STARTER_PRICE_ID="price_xxxxxxxxxxxxx" # App URL NEXT_PUBLIC_APP_URL="http://localhost:3000"
For Production:
Replace test keys with live keys (starting with pk_live_ and sk_live_) and update NEXT_PUBLIC_APP_URL to your production domain.
Important:
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYis safe to expose in client codeSTRIPE_SECRET_KEYmust NEVER be exposed - use server-side onlySTRIPE_WEBHOOK_SECRETis used to verify webhook signatures
Testing
- Use Stripe's test mode (toggle in dashboard)
- Restart your dev server:
npm run dev - Navigate to your pricing/checkout page
- Use Stripe test card:
4242 4242 4242 4242- Expiry: Any future date (e.g., 12/34)
- CVC: Any 3 digits (e.g., 123)
- ZIP: Any 5 digits (e.g., 12345)
- Complete the checkout flow
- Verify webhook events are received (check server logs)
- Check subscription status updates in your database
Test Cards:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Requires 3D Secure:
4000 0027 6000 3184
Testing Webhooks Locally: Use Stripe CLI to forward webhooks:
stripe listen --forward-to localhost:3000/api/webhooks/stripe
This gives you a webhook signing secret to use locally.