bradleyfalzon / gopherci-web

website for gopherci.io

Home Page:https://gopherci.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detect customers with multiple active subscriptions

bradleyfalzon opened this issue · comments

This shouldn't be possible (handlers check this), but there may be some edge case (race condition with multiple requests) where it happens. So we should be notified if a customer has two subscriptions that aren't ended.

Just a question to learn. Is it possible, and is it a good idea to arrange the database schema in such a way that multiple unintended active subscriptions are physically not possible? For example, if the user row points to its active subscription (or null).

I am guessing the answer is no, but in that case what are the reasons?

Yes, it would be better if the schema could restrict which subscription a user could be on, i.e. a simple subscription_id on the users table.

I didn't do this because the way I use Stripe Subscriptions is by creating a separate customer in Stripe and each customer then has many subscriptions. There are possible bugs where a stripe customer could have multiple subscriptions, such as a failure between removing an existing subscription and subscribing to another (perhaps multiple requests are sent from the client, but I believe I can fix that with https://stripe.com/docs/api?lang=curl#idempotent_requests).

But ultimately, because Stripe manages the customers and they support multiple subscriptions, it may always be possible (and they support multiple subscriptions in our scenario when someone cancels an existing subscription and creates a new one). I originally implemented a few tables to manage plans, subscriptions, coupons myself, but I since reversed that decision relying on Stripe to help me get to an MVP sooner.

I've also been a part of a team who double billed a very large customer base about a week before Christmas.

For those reasons, I decided to also, early on, implement double billing alerting, so I would at least be notified about it and could rectify the situation proactively and early.

But this is my first implementation with the Stripe API, so I'm also looking for additional feedback or alternative solutions. I'm also interested in a few 3rd part services to make this integration a little easier (creating invoices), but I think payments is in a good place right now.