Easily integrate Stripe to accept payments seamlessly. Whether you're selling products, subscriptions, or services, Stripe provides a secure and scalable solution.
To securely process payments, you'll need three different types of API keys from Stripe. Here's a detailed guide on how to get and use each one:
Used on the frontend to initialize Stripe and identify your account. Safe to expose in client-side code.
• Go to Stripe Dashboard → Developers → API Keys
• Look for the key starting with 'pk_test_' (test mode) or 'pk_live_' (live mode)
Used on the backend to authenticate API requests. Must be kept secure and never exposed to clients.
• Found in Stripe Dashboard → Developers → API Keys
• Starts with 'test_' or 'live_'
• Used in your API routes or server-side code
• ⚠️ Never expose this key in frontend code or public repositories
Used to verify webhook events from Stripe. Essential for handling payment confirmations and other events.
• Go to Developers → Webhooks → Add Endpoint
• Enter your webhook URL (e.g., https://your-domain.com/api/stripe/webhook)
• Select events to listen for (e.g., payment_intent.succeeded)
• Copy the Signing Secret provided
Add these to your .env.local file:
STRIPE_PUBLIC_KEY=pk_test_your_publishable_key
STRIPE_SECRET_KEY=sk_test_your_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
Remember to update these keys when moving to production, replacing test keys with live keys.
Lemon Squeezy is a modern alternative to Stripe, specifically designed for digital products and subscriptions. Here's how to set it up:
• Sign up at lemonsqueezy.com
• Create a new store from the dashboard
• Complete your store profile and branding
• Add payment methods (Stripe Connect will be set up automatically)
• Go to Products → Add Product
• Choose product type (One-time, Subscription, or License)
• Set up pricing, variants, and download files if applicable
• Configure product options and checkout settings
• Navigate to Settings → API & Webhooks
• Generate a new API key
• Copy your Store ID from the dashboard
• Set up webhook endpoints for order notifications
Add to your .env.local:
LEMON_API_KEY=your_api_key_here
LEMON_STORE_ID=your_store_id
LEMON_WEBHOOK_SECRET=your_webhook_secret