stripe · payments · tutorial
Complete Guide to Stripe Integration
Step-by-step guide to integrating Stripe payments, handling webhooks, and managing subscriptions in your SaaS application.

Complete Guide to Stripe Integration
Learn how to integrate Stripe payments into your ShipSaaS application and handle subscriptions like a pro.
Why Stripe?
Stripe is the leading payment processor for SaaS applications, offering:
- Easy integration
- Comprehensive API
- Automatic tax calculation
- Built-in fraud prevention
- Support for 135+ currencies
Setting Up Stripe
1. Create a Stripe Account
Visit stripe.com and create an account. You'll get instant access to test mode.
2. Get Your API Keys
Navigate to Developers → API keys and copy:
- Publishable key (starts with pk_test_)
- Secret key (starts with sk_test_)
3. Add to Environment Variables
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
Creating Products
- Go to Products in your Stripe dashboard
- Click "Add product"
- Set up your pricing (monthly/yearly)
- Copy the Price ID
Handling Webhooks
Webhooks are crucial for keeping your database in sync with Stripe.
Important Events
checkout.session.completed- Payment successfulcustomer.subscription.updated- Subscription changedcustomer.subscription.deleted- Subscription cancelledinvoice.payment_failed- Payment failed
Testing Webhooks Locally
Use the Stripe CLI to test webhooks on your local machine:
stripe listen --forward-to localhost:3000/api/stripe/webhook
Best Practices
- Always verify webhook signatures
- Handle idempotency
- Log all payment events
- Test with Stripe test cards
- Monitor failed payments
Common Issues
Webhook Not Receiving Events
- Check webhook URL is publicly accessible
- Verify webhook secret matches
- Check Stripe dashboard logs
Payment Fails
- Verify API keys are correct
- Check customer has valid payment method
- Review Stripe dashboard for errors
Conclusion
With Stripe properly integrated, you can focus on building your product while Stripe handles the complexity of payments.
Need help? Check our troubleshooting guide or reach out on GitHub.