Stripe makes the payment side of subscription billing straightforward. The complexity is in everything around it - handling webhooks reliably, managing plan upgrades and downgrades, free trials, failed payments, and cancellation flows. This guide covers the parts that most implementations get wrong.
- Never update subscription state in your database from the checkout success redirect - always use webhooks. Redirects fail.
- The webhook events you must handle:
customer.subscription.created,customer.subscription.updated,customer.subscription.deleted,invoice.payment_failed, andinvoice.payment_succeeded. - Stripe's Customer Portal handles upgrade, downgrade, cancellation, and payment method updates - use it and do not build your own.
- Store the
stripe_customer_idandstripe_subscription_idon your user record. You will need both constantly. - Test your failed payment flow before launch - most teams do not, and the first failed payment in production breaks access control.
The core objects you need to understand
Stripe's subscription model has four objects you will work with constantly. Understanding their relationship prevents most implementation bugs.
- Customer: the top-level object for a user. Store the
stripe_customer_idon your user record. All subscriptions, payment methods, and invoices belong to a customer. - Product and Price: your subscription plans. A product is a plan name ("Pro"). A price is the billing configuration - $49/month, $499/year. One product can have multiple prices.
- Subscription: the active billing agreement for a customer. It has a status (
active,trialing,past_due,canceled) and a current period end date. - Invoice: generated for each billing cycle. A subscription generates an invoice, Stripe attempts to collect it, and you get a webhook event with the result.
Webhooks - the part most teams get wrong
The most common Stripe implementation mistake is updating your database from the checkout success page redirect. This fails silently - the browser redirect is not reliable, users close the tab, networks time out.
The correct pattern: always use webhooks to update your database. When a subscription is created, Stripe fires customer.subscription.created. That webhook handler is where you update your user's plan in your database, not the checkout redirect.
The minimum webhook events to handle:
customer.subscription.created- grant access when a subscription activatescustomer.subscription.updated- handle plan changes and status transitionscustomer.subscription.deleted- revoke access when a subscription is cancelledinvoice.payment_succeeded- log successful renewal paymentsinvoice.payment_failed- handle failed payments, trigger dunning
Verify every webhook event with Stripe's signature verification. Do not process unverified payloads.
Free trials
Free trials in Stripe are set at the Price level using a trial_period_days value, or at subscription creation time using trial_end. During the trial, the subscription status is trialing. When the trial ends, Stripe automatically charges the payment method and transitions the status to active.
Require a payment method at trial start. Trials without a payment method on file have significantly higher conversion - users who provide card details convert at 60-80%. Users who do not are mostly browsing.
Building subscription billing for your SaaS?
Tripletic implements Stripe subscription billing for SaaS products - plans, webhooks, trials, upgrades, and the Customer Portal. We get it right the first time.
Talk to us →Plan upgrades and downgrades
Use Stripe's Customer Portal for subscription management rather than building it yourself. The Portal handles plan upgrades, downgrades, cancellation, and payment method updates. It is PCI-compliant, mobile-optimised, and Stripe keeps it up to date.
When a customer upgrades, Stripe prorates the billing by default - the customer is charged the difference immediately. When a customer downgrades, Stripe applies a credit to the next invoice by default. You can configure proration behaviour at the subscription update level.
Your customer.subscription.updated webhook handler must check the new plan and update your user's access level in your database. This is where most implementations have race conditions - make your webhook handlers idempotent using the Stripe event ID.
Frequently Asked Questions
Should I store subscription status in my own database?
Yes - always store the current subscription status and plan in your own database. Reading from Stripe on every request adds latency and creates a dependency. Your database is the source of truth for access control. Stripe is the source of truth for billing. Sync them via webhooks.
What happens when a payment fails?
Stripe retries failed payments according to your Smart Retries configuration (default: 4 retries over 7 days). During retries, the subscription status is past_due. If all retries fail, the subscription moves to canceled unless you configure it to stay past due. You should send dunning emails during this period - Stripe has a built-in Billing Emails feature for this.
How do I handle annual billing?
Create a separate Price for the annual plan with interval: year. Annual plans can be offered at a discount using the price amount directly. Stripe handles the annual renewal charge automatically. Store both the monthly and annual price IDs in your app config and let users switch between them in the Customer Portal.
Do I need a separate library for Stripe or just the API?
Stripe has official libraries for every major language and framework. Use the official library - it handles signature verification, retry logic, and version pinning. Never use raw HTTP requests to the Stripe API when an official library exists for your stack.