Setting Up Stripe and Lemon Squeezy for Payments
Easily integrate Stripe to accept payments seamlessly. Whether you're selling products, subscriptions, or services, Stripe provides a secure and scalable solution.
- Visit Stripe and sign up.
- Complete the verification and business setup.
- Go to Developers API Keys to find your Publishable Key and Secret Key.
Get Your API Keys
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:
Publishable Key (pk_*)
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)
Secret Key (sk_*)
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
Webhook Secret (whsec_*)
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
Setting Up Environment Variables
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.
Testing
- Use Stripe's test card numbers (e.g., 4242 4242 4242 4242)
- Verify successful payment flow in Stripe Dashboard
Switch API keys from test mode to live mode in Stripe Dashboard. And run npm run dev
Setting Up Lemon Squeezy Payments
Lemon Squeezy is a modern alternative to Stripe, specifically designed for digital products and subscriptions. Here's how to set it up:
1. Create Your Store
- 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)
2. Create Products
- 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
3. API Setup
- Navigate to Settings → API & Webhooks
- Generate a new API key
- Copy your Store ID from the dashboard
- Set up webhook endpoints for order notifications
4. Environment Setup
Add to your .env.local:
LEMON_API_KEY=your_api_key_here
LEMON_STORE_ID=your_store_id
LEMON_WEBHOOK_SECRET=your_webhook_secret
Testing Your Integration
- Test Mode is automatically enabled in development
- Use test card: 4242 4242 4242 4242
- Any future date for expiry
- Any 3 digits for CVC
- Monitor webhooks in your dashboard