Rails, Stripe and Subscriptions - Model

Question!

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?



Answers

"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?"

Store all the info in the Subscription model and associate that model to the User. Since subscriptions have their own meta data and they are really a different entity, it makes sense to store them separately.

"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?"

If you are checking the subscription on every request or login, it probably does not make sense to hit the stripe api every time... that is alot of overhead. It all really depends on your use case, but it may make sense to run a daily (or hourly) cron job that hits the stripe api to check for subscription expiration and then update the local Subscription store.



The way I approach it with the SaaS Rails Kit is to keep the info in the Subscription model, including a next_renewal_at field, and not leaving it up to Stripe to do the billing. Instead, I have a daily cron job that bills all subscriptions that have a new_renewal_at = today, so you know immediately if a charge failed.



This video can help you solving your question :)
By: admin