I've begun working on a SaaS idea I've had lately - it's simple but I'm excited about building it and hopefully turning it into something people want to use.
I'm slightly back-and-forth on what to store in the DB and how for it to scale well based on features I'll need eventually.
I'm using Stripe too.
Here's all I've got so far:
A Users table with:
When a customer signs up I ask for their Email and Password and create a new Stripe Customer and create a subscription to the only plan I've created so far with a 14 day trial.
I then store the Stripe Customer ID in the database.
What sort of information should I store regarding payments and billing in my own database? I was thinking about a new table called Billing and store when the users trial will expire (provided from Stripe), am I thinking about this wrong? Anything else pivotal?
Hi, if you're still interested in this, here is how we are handling the Stripe data at NLP Cloud: https://juliensalinas.com/en/storing-stripe-payment-data-database/
Basically, we store everything in local DB as a PostgreSQL JSONB field as soon as we make a request or receive a webhook.
Doing this you have the best of both worlds:
Hope it helps
Just stumbled onto this thread as I am at the same decision point wiht my product.
I think I'm going to start off with just storing the Stripe customer ID on the user, with a subscription object that holds the subscription ID, status, expiry date.
I'll extend the expiry each time I get a successful payment event from Stripe.
Not sure if anyone will see this, but thoughts?
Hello! What did you end up doing? Do you have any feedback on your choice? I'm currently reflecting on this exact subject regarding our SaaS and cannot wrap my head around the best option between:
Any feedback could probably help. Thanks in advance :)
I wouldn't recommend hitting Stripe's API to fetch billing information as-needed. For example, if you wanted to check if the current user has a subscription, that will add latency if you hit Stripe's API every time you needed to know that. It's very simple to keep local billing data in sync with Stripe's system using webhooks, e.g.
customer.updated
,customer.source.created
,customer.subscription.created
, etc.I have a billing table that looks something like this:
That's all the information I've ever needed to know.
cc @csallen, code blocks don't really look right recently. A lot of extra white space is added.
I'll check it out, thanks for the heads up
For our billing pages, we just pull in the history from Stripe. If you can get away with it, a single source of truth is best.
~25,000 Stripe users later and I don't regret it. We've had to create a FakeCharge and a ShopifyCharge in our main DB (Postgres) to fudge it a little for alternate billing. Hopefully you never need to do that. When getting user.charges (Rails ActiveRecord syntax here), it just grabs data from those two tables plus Stripe then sorts them all by date.
When creating charges/users in Stripe, I suggest storing some metadata like User id so you can figure out what happened if a user is deleted/updated.
I agree, I would try to leverage Stripe APIs to fetch any subscription or payment data if needed.