Rails, Stripe and Subscriptions - Model

ruby-on-rails, stripe-payments

Solution

Just store a flag indicating whether subscription is active or not which is set to true by default when you subscribe.

Then set up stripe callback hooks to notify your app if the subscription is expired/cancelled/whatever. Listen for customer.subscription.updated and look at the status field which can either by active, past_due, cancelled or unpaid.

You will be notified immediately by stripe so there is no need incur the overhead of checking constantly. If stripe for some reason cannot make the callback, it will retry several times with exponential backoff so it is very robust.

Don't implement subscriptions yourself and don't run a job periodically to sync with stripe. With stripes callback hooks both strategies are totally unnecessary.

Problem

In my site, I have all the Stripe integration working, but I am still trying to wrap my head around how to determine if a subscription is active. I thought about keeping everything in the local DB, but then i'd have duplicate data from Stripe. However, if Stripe is the master record, what if they are down and I can't determine if a user has an active subscription? Seems to me like there should be a way to sync everything together. Should I keep some sort of date of current subscription expiration with the account/user? What subscription information should be stored with the model? Should this be a part of the User model or as part of a separate "Subscription" model?

Original source