Payment Setup
Quick setup guide for enabling payments. Choose one payment provider (Stripe or Razorpay).
Prerequisites
- Complete the Quick Start steps
- Have a payment provider account (Stripe or Razorpay)
- Know which plan you want to enable (default: "pro")
Choose Your Provider
Option 1: Stripe
1. Create a Product in Stripe Dashboard
- Go to Stripe Dashboard → Products
- Click "Create product"
- Set name to "Pro Plan"
- Set price to $29/month (or your preferred pricing)
- Copy the Price ID (starts with
price_)
2. Update Database
node scripts/update-stripe-price.js pro <PRICE_ID>3. Configure Environment
- Set
PAYMENT_PROVIDER=stripein your.envfile - Ensure
STRIPE_SECRET_KEYandSTRIPE_WEBHOOK_SECRETare set
See Environment Variables for details.
4. Setup Webhooks (Required)
- Go to Stripe Dashboard → Developers → Webhooks
- Click "Add endpoint"
- Set endpoint URL to:
https://yourdomain.com/api/payments/webhook/stripe For local development: Use ngrok URL instead (see Local Webhook Testing section below)
- Select events:
checkout.session.completedinvoice.paidcustomer.subscription.updatedcustomer.subscription.deletedinvoice.payment_failed
- Copy the Webhook signing secret to
STRIPE_WEBHOOK_SECRETin your.env
Option 2: Razorpay
1. Create a Plan in Razorpay Dashboard
- Go to Razorpay Dashboard → Plans
- Click "Create Plan"
- Set name to "Pro Plan"
- Set price to ₹2900/month (or your preferred pricing)
- Copy the Plan ID (starts with
plan_)
2. Update Database
node scripts/update-razorpay-plan.js pro <PLAN_ID>3. Configure Environment
- Set
PAYMENT_PROVIDER=razorpayin your.envfile - Ensure
RAZORPAY_KEY_IDandRAZORPAY_KEY_SECRETare set
See Environment Variables for details.
4. Setup Webhooks (Required)
Generate Webhook Secret
Important: Unlike Stripe, you must create your own webhook secret for Razorpay.
Generate a secure random secret:
Option 1: Use openssl (macOS/Linux)
openssl rand -hex 32Option 2: Use Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"Option 3: Use Python
python3 -c "import secrets; print(secrets.token_hex(32))"Create Webhook in Razorpay Dashboard
- Go to Razorpay Dashboard → Settings → Webhooks
- Click "Add New Webhook"
- Set Webhook URL to:
https://yourdomain.com/api/payments/webhook/razorpay For local development: Use ngrok URL instead (see Local Webhook Testing section below)
- Set Secret to the random secret you generated above
- Select Active Events:
subscription.activatedsubscription.chargedsubscription.cancelledsubscription.pausedsubscription.resumedpayment.failed
- Click "Create Webhook"
Update Environment Variables
Add the webhook secret to your .env file:
RAZORPAY_WEBHOOK_SECRET=your_random_generated_secret_hereLocal Webhook Testing (Optional)
To test webhooks locally during development, use ngrok to expose your localhost to the internet.
1. Install ngrok
macOS (using Homebrew):
brew install ngrok/ngrok/ngrokWindows/Linux:
Download from: ngrok.com/download
Or using npm (if you have Node.js installed):
npm install -g ngrok2. Authenticate ngrok
Get your auth token from ngrok dashboard:
ngrok config add-authtoken YOUR_AUTH_TOKEN3. Start Your Development Server
Make sure your Next.js app is running:
pnpm devYour app should be running on http://localhost:3000.
4. Start ngrok
Expose your localhost to the internet:
ngrok http 3000You'll see output like:
ngrok
Session Status online
Account your-email@example.com (Plan: Free)
Version 3.x.x
Region United States (us)
Latency -
Web Interface http://127.0.0.1:4040
Forwarding http://abc123.ngrok.io -> http://localhost:3000
Forwarding https://abc123.ngrok.io -> http://localhost:3000Important: Copy the https://abc123.ngrok.io URL.
5. Update Webhook URLs
Update your webhook URLs in the payment provider dashboards to use the ngrok URL:
Stripe:
- Go to Stripe Dashboard → Developers → Webhooks
- Update the endpoint URL to:
https://your-ngrok-url.ngrok.io/api/payments/webhook/stripe
Razorpay:
- Go to Razorpay Dashboard → Settings → Webhooks
- Update the webhook URL to:
https://your-ngrok-url.ngrok.io/api/payments/webhook/razorpay
6. Test Webhook Delivery
- Visit your app at the ngrok URL
- Try to purchase a subscription
- Complete the payment using test credentials
- Check ngrok logs at
http://127.0.0.1:4040- you should see webhook requests - Verify subscription was created in your database
Troubleshooting
Webhook Events Not Received
- Check ngrok is still running:
http://127.0.0.1:4040 - Verify webhook URL in provider dashboard uses correct ngrok URL
- Check ngrok logs for any errors
ngrok Not Working
- Try a different region:
ngrok http 3000 --region=us - Check your internet connection
- Verify ngrok auth token is correct
Security Note: ⚠️ Never commit ngrok URLs or webhook secrets to version control. Always use environment variables.
Test Payment Flow
- Restart your development server
- Visit your app and try to upgrade to the Pro plan
- Complete a test payment using test credentials:
- Stripe: Card
4242 4242 4242 4242 - Razorpay: Card
5500 6700 0000 1002
- Stripe: Card
Next Steps
- Payments - View detailed payment documentation
- Configure additional plans if needed
- Test webhook events for subscription lifecycle management