-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Subscriptions: attach stripe_subscription to Organization model? #9652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the big question in my mind is, will customers always have only 1 subscription? I think in the past we've created additional subscription objects to add on additional features/billing. I think this is likely something that we would also do in the future, so I don't think we can make that assumption. I think having the subscription assigned to the organization as the "primary" or main one is probably the best path forward. I think being explicit here is good, instead of relying on implicit data in the DB. We likely need some logic around what types of subscription can be the "main" subscription, if we're relying on incoming webhooks, and we'd need to filter out any additional subscriptions. I'm imagining the case in the future where we are selling support as an additional subscription upsell, have a customer with:
We need some way to not blow up in this scenario :) |
IIRC, for the cases that Eric mentions we are still using 1 subscription with multiple products. We have customers paying the regular plan + additional builders in the same subscription. I'm not saying that making the assumption that we will always have 1 subscription per customer is good, tho --just noticing that it's possible to have 1 subscription with multiple products on it. |
Currently, we have 0 users that have more than one subscription that isn't What we can't do is to have a different trial for each product. Just mentioning what we can do before going for multiple subscriptions :) So, +1 on having a "main" subscription. Another solutions could be to change our querysets to be related to the Subscriptions instead of the Organizations, And instead of querying subscriptions that are cancelled/trial-ended, we can make use of the stripe webhook to email users the exact time the subscription ends the trial. The only one query that we can't migrate by simply change that relation is
But we could add an attribute in the organization for that, something like Just a thought, I'm fine moving with the "main subscription" idea too, but will require a data migration. |
I'm good with a |
Instead of trying to replace the existing queries, I'm making use of djstripe events/webhooks. - Instead of a daily task to email users with a canceled subscription, we use a webhook to email users the exact time the subscription changes to "canceled" (this is the moment the subs ends, not when a user cancels a subscription, since it will remain active till the end of the cicle). - Instead of querying organizations with subs in trialing, we query the subs directly, and get the organization from them. With this, we don't depend on having just one subs per-organization, and also stop relying on our models a little less. The queries that are used to disable orgs aren't migrated yet, since they query canceled subscriptions (#9652 (comment)).
Currently, we only attach the stripe customer to the organization object, and we have a little helper to get the stripe subscription
readthedocs.org/readthedocs/organizations/models.py
Line 127 in 9e7787c
All good, but if we want to query organizations by their subscription status, then we have a little problem... A customer can have more than one subscription, and to have our query work around the "current" subscription, we need a subquery like
Which is... ugly
Luckily, we always have just one active subscription per customer (or a subscription that isn't canceled per customer),
so we are okay omitting the subquery if we filter subscriptions by a status different from
canceled
, but when we require querying by canceled subscriptions or without a given status, than we need to use the subqueryreadthedocs.org/readthedocs/organizations/querysets.py
Lines 41 to 202 in 9e7787c
So the question is: are we okay with using a subquery for those cases? Or maybe we should attach the current stripe subscription into the organization model? We would need to keep it up to date with the "current" subscription, but that shouldn't be complicated (we just need to listen to the
subscription.created
event), and I think queries will be more clear having just to writeOrganization.objects.filter(stripe_subscription__=...)
.The text was updated successfully, but these errors were encountered: