Stripe Logo

Stripe Setup

Overview

This guide will help you set up Stripe integration in your application for handling payments and subscriptions.

Prerequisites

  • A Stripe account (create one at stripe.com)
  • Stripe CLI installed for webhook testing
  • Basic understanding of Stripe concepts

Environment Variables

Add the following environment variables to your .env.local file:

# Stripe API Keys
STRIPE_SECRET_KEY=sk_test_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
# Your application URL
NEXT_PUBLIC_SITE_URL=http://localhost:3000

Stripe Client Setup

The Stripe client is initialized in src/lib/stripe/client.ts:

import Stripe from "stripe";
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: "2023-10-16",
typescript: true,
});

Testing Stripe Integration

Use test card numbers for development:

Test Card Success: 4242 4242 4242 4242

Test Card Failure: 4000 0000 0000 0002

Test 3D Secure: 4000 0000 0000 3220

Webhook Development

Use the Stripe CLI to test webhooks locally:

# Login to Stripe CLI
stripe login
# Forward webhooks to your local server
stripe listen --forward-to localhost:3000/api/webhooks/stripe

Next Steps