Stripe is the payment platform for SaaS. But setting it up correctly — with proper subscription management, webhook handling, and the Customer Portal — requires understanding how the pieces fit together. Here's the complete implementation guide.

Understanding Stripe's Object Model

Stripe's data model for subscriptions:

  • Product — what you're selling (e.g., "Pro Plan")
  • Price — how much it costs and how often (e.g., "$49/month" or "$490/year")
  • Customer — the person or company paying
  • Subscription — the relationship between a Customer and a Price
  • Payment Method — the credit card attached to the Customer

The Checkout Flow

The standard Stripe subscription checkout flow:

  1. User clicks "Upgrade to Pro"
  2. Your server creates a Stripe Checkout Session with the Price ID
  3. User is redirected to Stripe's hosted checkout page
  4. User enters their card details on Stripe's secure page
  5. Stripe creates the Subscription and calls your webhook
  6. Your webhook handler activates the user's subscription in your database
  7. User is redirected back to your app's success page

Webhook Handling

Webhooks are the critical part most developers get wrong. Your webhook endpoint must handle:

  • checkout.session.completed — activate the subscription
  • customer.subscription.updated — handle plan changes
  • customer.subscription.deleted — deactivate the subscription
  • invoice.payment_failed — send dunning email, possibly restrict access
  • invoice.payment_succeeded — ensure access is active

Always verify the webhook signature using Stripe's library to prevent spoofed requests.

Need Stripe Billing Implemented in Your SaaS?

I take 2 clients per month. Ship your SaaS in 2–4 weeks with a developer who has done it 350+ times.

Start on Fiverr →

Customer Portal

Stripe's Customer Portal is a pre-built UI where your users can manage their subscriptions — upgrade, downgrade, cancel, update payment method. Enable it with two lines of code and save weeks of building subscription management UI yourself.

Testing Your Billing Integration

Stripe provides a comprehensive set of test card numbers covering every billing scenario: successful payments, card declines, insufficient funds, 3D Secure challenges, and subscription cancellations. Use every single test card before you go live. The most common production billing bugs I've seen are in edge cases founders never tested: what happens when a trial expires and the card declines, what happens when a user upgrades mid-billing-cycle, and what happens when a webhook is delivered twice. Test all of these before your first real customer pays.