Setup Stripe

Configure your Stripe API keys, create products, and set up webhooks.

Environment Variables

VariableDescriptionTypeSource
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYStripe publishable key for client-side*
public
safe
Stripe Dashboard → Developers → API keys
STRIPE_SECRET_KEYStripe secret key for server-side*
server
secret
Stripe Dashboard → Developers → API keys
STRIPE_WEBHOOK_SECRETWebhook signing secret for verifying events*
server
secret
Stripe Dashboard → Developers → Webhooks
STRIPE_PRICE_ID_BASICPrice ID for basic subscription tier
server
safe
Stripe Dashboard → Products → Price ID
STRIPE_PRICE_ID_PROPrice ID for pro subscription tier
server
safe
Stripe Dashboard → Products → Price ID

* Required variable

Step 1: Get API Keys

  1. Go to Stripe Dashboard → Developers → API keys
  2. Copy your Publishable key (starts with pk_)
  3. 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

  1. Go to Stripe Dashboard → Products
  2. Click "Add product"
  3. Create your subscription tiers (e.g., Basic, Pro)
  4. Set pricing (monthly/yearly)
  5. Copy the Price ID for each tier (starts with price_)

Step 3: Set Up Webhooks

  1. Go to Stripe Dashboard → Developers → Webhooks
  2. Click "Add endpoint"
  3. Enter your webhook URL: https://your-domain.com/api/webhooks/stripe
  4. Select events to listen for:
    • checkout.session.completed
    • customer.subscription.updated
    • customer.subscription.deleted
    • invoice.payment_succeeded
    • invoice.payment_failed
  5. 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/stripe

Step 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_xxxxx

Verify Setup

Test your Stripe integration:

  1. Restart your development server
  2. Navigate to a checkout or pricing page
  3. Use Stripe test card: 4242 4242 4242 4242
  4. Verify the webhook receives events (check Stripe Dashboard → Developers → Webhooks)
Setup Stripe | Payments Module | VibeCodeMax Docs