Payments
Learn how to configure and customize Stripe payments for your SaaS app, including subscription plans, webhook handling, billing portal, and testing.
Payments
Stripe integration is pre-configured. Here's how to activate and customize your payment system.
Quick Setup
- Create Stripe products in your dashboard
- Configure webhook endpoint
- Test the payment flow
Stripe Products Configuration
Create Your Plans
In Stripe Dashboard → Products, create:
Basic Plan
- Monthly: $9/month
- Annual: $90/year (save $18)
Pro Plan
- Monthly: $29/month
- Annual: $290/year (save $58)
Copy the price IDs to use in your pricing page.
Pricing Page Setup
Update app/pricing/page.tsx
with your price IDs:
const plans = [
{
name: 'Basic',
monthlyPriceId: 'price_1234567890',
annualPriceId: 'price_0987654321',
price: { monthly: 9, annual: 90 },
},
{
name: 'Pro',
monthlyPriceId: 'price_abcdefghij',
annualPriceId: 'price_jihgfedcba',
price: { monthly: 29, annual: 290 },
},
];
Payment Flow
Subscription Creation
- User clicks "Subscribe" on pricing page
- Redirects to Stripe Checkout with price ID
- User completes payment
- Webhook updates subscription in database
- User redirected to success page
Webhook Handling
The webhook endpoint (/api/webhooks/stripe
) handles:
customer.subscription.created
- New subscriptioncustomer.subscription.updated
- Plan changescustomer.subscription.deleted
- Cancellationsinvoice.payment_succeeded
- Successful paymentsinvoice.payment_failed
- Failed payments
Billing Portal
Users manage subscriptions via Stripe's hosted portal:
// Redirect to billing portal
const { url } = await stripe.billingPortal.sessions.create({
customer: user.stripe_customer_id,
return_url: `${process.env.NEXT_PUBLIC_SITE_URL}/billing`,
});
Accessible at /billing/portal
- handles upgrades, downgrades, cancellations.
Subscription Status
User subscription status is stored in the profiles
table:
// Check if user has active subscription
const hasActiveSubscription = user.subscription_status === 'active'
// Protect premium features
if (!hasActiveSubscription) {
return <UpgradeBanner />
}
Testing Payments
Test Mode Setup
- Use test API keys from Stripe
- Test card numbers:
4242 4242 4242 4242
- Any future date for expiry
- Any 3-digit CVC
Test Scenarios
- Successful payment
- Declined card
- Webhook delivery
- Subscription changes
Production Setup
Webhook Configuration
- Add webhook endpoint:
https://yourdomain.com/api/webhooks/stripe
- Select events:
customer.subscription.*
,invoice.*
- Copy webhook secret to
STRIPE_WEBHOOK_SECRET
Go Live
- Switch to live API keys
- Test with real payment methods
- Verify webhook delivery
- Monitor Stripe dashboard
Customization
Custom Checkout
Replace Stripe Checkout with embedded form using Stripe Elements for more control.
Usage-Based Billing
Add metered billing for API calls or usage limits using Stripe's usage records.
Multiple Payment Methods
Enable additional payment methods (ACH, SEPA, etc.) in Stripe settings.
Troubleshooting
Webhook not firing: Check endpoint URL and selected events
Payment failed: Verify API keys and test card numbers
Subscription not updating: Check webhook signature validation
Portal not loading: Verify customer ID exists