Stripe subscriptions in Rails are one of the best-supported paths in the ecosystem — mostly thanks to Pay, the open-source gem that wraps Stripe (and Paddle/Braintree) in a Rails-native model layer. As of November 2026, Pay is at 12.4.0 (MIT, maintained by Jason Charnes, Chris Oliver and Collin Jilbert) and works with Stripe Checkout and the Customer Portal, which removes most of the UI you would otherwise build.
This is the setup I use on SaaS MVPs, including the parts generic tutorials skip: webhooks, plan changes, cancellations and failed payments.
The model: Pay’s tables, not your own
Pay keeps its own tables (pay_customers, pay_subscriptions) linked to your User/Account model, so Stripe stays the source of truth for billing state while your app reads a local cache of it.
bundle add pay
bin/rails pay:install:migrations
bin/rails db:migrate# app/models/user.rb
class User < ApplicationRecord
pay_customer
endEvery subscription-aware query in your app goes through user.payment_processor.subscriptions. Never mirror plan state in your own columns — drift is inevitable.
Checkout and the Customer Portal
The lowest-maintenance path is Stripe-hosted billing UI:
# app/controllers/checkouts_controller.rb
def create
session = current_user.payment_processor.checkout(
mode: :subscription,
line_items: [{ price: params[:price_id], quantity: 1 }],
success_url: url_for(root_url) + "?paid=1",
cancel_url: url_for(root_url),
)
redirect_to session.url, allow_other_host: true
endCustomers manage cards, upgrades, downgrades and cancellations in the Stripe-hosted Customer Portal via user.payment_processor.billing_portal_url. You configure products and prices in the Stripe dashboard; the app references price IDs from environment/credentials.
Webhooks are the real backend
Stripe only truly moves through webhooks. With Pay, mount the receiver and let it update its tables:
# config/routes.rb
mount Pay::Engine, at: "/pay", as: :pay_engineRegister https://your-domain/pay/webhooks/stripe in the Stripe dashboard (and in the Stripe CLI for local development):
stripe listen --forward-to localhost:3000/pay/webhooks/stripePay handles the common events (subscription created/updated/deleted, invoice paid/failed). Anything custom — provisioning side effects, dunning steps — goes in your own listener, inheriting from Pay’s webhook handlers or a plain ActiveJob:
# app/jobs/invoice_payment_failed_job.rb
class InvoicePaymentFailedJob < ApplicationJob
def perform(pay_customer_id)
customer = Pay::Customer.find(pay_customer_id)
# email the account owner, soften to read-only access after N days
end
endAuthorization from subscription state
Gate premium features on the synced status, never on the fact of a checkout session:
# app/models/user.rb
def premium?
payment_processor.subscriptions.where(status: %w[active trialing]).exists?
endFeature flags beat booleans: one premium? predicate reused in controllers and views, so a failed payment in Stripe flips access on the next deploy without code changes.
The failure modes tutorials skip
trial_endis not a hard cut-off: trials lapse at a timestamp; job ordering andsubscription.updatedevents both matter. Grant trial access fromtrialingstatus, not from a flag you set at signup.- Plan changes mid-cycle: proration is Stripe’s default; decide explicitly whether upgrades are immediate (
bill_immediately) or next cycle. - Cancellation timing:
cancel_at_period_end = truekeeps access until the period closes — make sure your UI says so, or customers think they’ve been charged twice. - Dunning:
invoice.payment_failedshould trigger a grace period (e.g. 7 days read-only), then downgrade. Without it, customers who forgot to update a card churn silently. - Test clocks: use Stripe’s test clocks to fast-forward invoices in test mode. Manual webhook poking is how bugs ship.
- Idempotency: every webhook handler and billing job must be safe to re-run; Stripe retries on non-2xx.
For cost context on the plan you’re supporting, my post on how much a SaaS MVP costs covers the Stripe line item among the others.
Receipts and compliance
Stripe emails receipts and invoices on its own; keep your transactional email for product flows (proposal accepted, onboarding, receipt summary pages). Put a tax solution (Stripe Tax) on checklist if you sell internationally, and never store card data — Checkout and the Portal mean you never touch PANs.
Where this fits your build
Subscription billing is one of the features that defines “MVP complete” for a SaaS: sign-up, teams, Stripe, an admin area. If you’re scoping that build, send me a short brief — I ship exactly this as part of my SaaS MVP development service, with Pay wired, webhooks tested, and the dunning flow included.
Conclusion
With Pay and Stripe Checkout, subscriptions stop being a build project and become a configuration of record: webhooks in, predicates out, dunning handled on day one. If you’d like the full billing surface — checkout, portal, webhooks, dunning and tests — shipped as part of your MVP, send me a short brief and book a discovery call.
Frequently asked questions
Pay gem vs rolling my own Stripe integration — which is better?
Pay is maintained, battle-tested and keeps your schema aligned with upstream; rolling your own means owning every webhook edge case forever. Use Pay unless you need a very unusual billing model.
Does Pay work with Stripe Customer Portal?
Yes — payment_processor.billing_portal_url redirects to it. You can still hand-roll pricing pages if you prefer the marketing control.
How do I test webhooks locally?
stripe listen --forward-to localhost:3000/pay/webhooks/stripe and stripe trigger invoice.payment_failed. Also consider request-spec coverage against the Pay controllers.
How do trials work with Pay?
Stripe manages trial timestamps; Pay syncs them. Check the subscription’s status and trial_ends_at in your authorization predicate rather than storing your own trial flag.
Can Pay handle metered/usage-based billing?
Stripe supports metered billing; Pay maps subscriptions but usage reporting is usually custom — record usage yourself and report metered events to Stripe.
What about VAT and taxes?
Enable Stripe Tax (per-country registration is on you) and let Stripe calculate, collect and remit. Keep invoice records for your accountant from day one.


