Payments
Set up Stripe payments and subscriptions for your SaaS application.
This SaaS boilerplate uses Stripe for payment processing and subscription management. Stripe provides a secure, reliable platform for accepting payments and managing recurring subscriptions.
Stripe Account Setup
Step 1: Create a Stripe Account
- Go to Stripe and sign up for an account
- Complete your account verification
Step 2: Get Your API Keys
In your Stripe dashboard, go to Developers → API keys and copy your keys:
STRIPE_SECRET_KEY="sk_test_..."NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."
Important: Use test keys for development and live keys for production.
Webhook Configuration
What are Webhooks?
Stripe uses webhooks to notify your application about events that happen in your Stripe account, such as successful payments or subscription updates.
Step 1: Set Up Webhook Endpoint
For local development, you can use the Stripe CLI to forward webhook events to your local server:
Install Stripe CLI
After installation, run the following commands:
stripe loginstripe listen --forward-to localhost:3000/api/webhook/stripeThe CLI will output a webhook signing secret just copy that secret and paste it in your
STRIPE_WEBHOOK_SECRET
.For production, create a webhook endpoint in your Stripe dashboard:
- Go to the Webhooks page in your Stripe dashboard
- Click "Add endpoint"
- Enter your endpoint URL:
https://your-domain/api/webhook/stripe
- Select the following events to listen for:
checkout.session.completed
customer.subscription.updated
customer.subscription.deleted
invoice.payment_succeeded
- Click "Add endpoint" to create the webhook
After creating the webhook, copy the webhook secret and add it to your
.env
file asSTRIPE_WEBHOOK_SECRET="whsec_..."
.
Creating Products and Prices
- recurring subscriptions: Open
data/pricing.ts
You’ll see Monthly (Standard, Pro) and Yearly (Standard, Pro). just go stripe, create products that match the names and amounts inpricing.ts
. after create products, copy the price IDprice_123...
and paste it into the matching entry inpricing.ts
. - One‑time (lifetime): Open
one-time-payment.md
in your project root, copy the prompt paste it into your AI editor. It will generate the code for one-time payments. Then create two one‑time products (Standard, Pro) matchingpricing.ts
and paste their price IDs back intopricing.ts
. - Changing names or prices? Edit
pricing.ts
first (update names/amounts). Next, create Stripe products with the same amounts. Finally, paste the new price IDs intopricing.ts
.
- Go to the Products page in your Stripe dashboard
- Click "Add product"
- Enter the product details (name, description, images)
- Add pricing information:
- For one-time payments, select "One time"
- For subscriptions, select "Recurring" and set the billing period
- Click "Save product"
- Copy the price ID (e.g.
price_123...
)
Production Best Practices
- Monitor Disputes: Check Dashboard → Radar daily and respond fast to avoid chargebacks
- Turn Off Test Mode: Switch to live keys and clear all test data before going live
- Multiple Payment Methods: Enable UPI, wallets, international cards for global users
- Custom UI: Use Stripe's Appearance API to match your site's design with responsive mobile-first approach
- Auto Receipts: Configure automatic receipts and branded invoices for user trust
- Environment Separation: Keep test and production completely separate for API keys and logging
Stripe setup on your app
Files to check
- Pricing Schema
prisma/schema.prisma
- Stripe API
lib/stripe.ts
- Stripe API endpoint
app/api/webhook/stripe.ts
- Stripe Checkout API endpoint
app/api/checkout/route.ts
- Stripe Customer Portal API endpoint
app/api/portal/route.ts