Skip to content

Subscriptions: use djstripe for products/features #10238

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

Merged
merged 43 commits into from
Aug 10, 2023
Merged

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Apr 12, 2023

Instead of relying on our subscription models, we are now relying on the djstripe models, but the features of each subscription are still attached to our subscription models. In the new modeling, we have features attached to stripe products.

I'm using some data classes to make the representation instead of using plain dictionaries, they are more verbose than a plain dictionary, but are easier to manipulate in the code.

After this change has been deployed, we won't be needing our subscription models anymore. The available products are defined in .com, since in .org we don't have subscriptions. If we feel like we can have this in the DB, we can also switch the data classes to be Django models.

Closes #9313

@stsewd stsewd marked this pull request as ready for review April 18, 2023 23:57
@stsewd stsewd requested review from a team as code owners April 18, 2023 23:57
@stsewd stsewd requested review from agjohnson and benjaoming April 18, 2023 23:57
@stsewd stsewd requested review from ericholscher and humitos and removed request for a team and agjohnson April 18, 2023 23:58
@stsewd
Copy link
Member Author

stsewd commented Apr 19, 2023

Don't think this needs a review from the frontend team, but I did a small change in two templates.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty straightforward to me. Is there a doc that explains the architecture here, where we have some kind of price in Stripe that links to a set of features defined in the settings?

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 💯 -- I left a suggestion to rename our own classes and remove the RTD prefix since I think it only adds more characters and less clarity in the end.

id__in=stripe_products_id,
prices__subscription_items__subscription__rtd_organization=organization,
).values_list("id", flat=True)
# TODO: maybe we should merge features from multiple products?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand a little more on this? I'm not sure to understand this question.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A subscription can have multiple products, (like the normal basic plan + an extra builder). Right now we are just selecting one product, instead of doing that we could:

  • Select the first feature found from iterating over all products (or select the one with the larger value)
  • Merge the features from all products (basic plan has 2 builders, and the extra builder plan has 1, so we merge the values of all of them, returning a feature with the number 3)
  • Alternative we can just create a custom product that includes all things from the basic plan + the extra builder.

Since we already have this case in one of our subscriptions, we should make a decision how we want to handle this, cc @ericholscher

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, good point. I'd like to make it easy to inclucde "addons" to an existing plan, if at all possible. This gives us a bit more flexibility in how we're defining products (eg. the extra builder).

I don't have a strong preference for how it's actually implemented. I think selecting the largest is probably the most obvious, and we'd just need to update the +1 builder to be 3 total builders basically? But I'm not 100% sure.

@stsewd
Copy link
Member Author

stsewd commented Aug 1, 2023

Okay, added support for "extra products". They are now listed in the subscription detail view, and the get_feature function respects the quantity from the subscription and adds all features of the same type.

Screenshot 2023-07-31 at 20-17-38 Organization Subscription - Read the Docs for Business

@stsewd stsewd requested a review from ericholscher August 2, 2023 01:30
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's pretty close. Glad to be getting this refactor shipped 👍

Comment on lines 39 to 40
and can have multiple prices of products attached to it.
A product can have multiple prices, usually monthly and yearly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's multiple prices of products, and also products can have multiple prices? I don't quite understand why we would have 2 different prices for the same product on a subscription?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and can have multiple prices of products attached to it.
A product can have multiple prices, usually monthly and yearly.
and can have multiple products attached to it.
A product can have multiple prices, usually monthly and yearly.

I think this is clearer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A subscription is attached to a price, not a product, but don't think you can have a subscription attached to several prices of the same product, yeah.


To subscribe an organization to an extra product,
you just need to add the product to its subscription with the desired quantity,
our appliction will automatically relate this new product to the organization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪄

@stsewd
Copy link
Member Author

stsewd commented Aug 8, 2023

Anything else needed to merge this PR?

The only answer missing is in #10238 (comment), I can apply that change if needed.

@ericholscher
Copy link
Member

I think we're good to ship this on my side. Merging that comment update is probably useful to clarify things 👍

@stsewd stsewd merged commit f64b0d1 into main Aug 10, 2023
@stsewd stsewd deleted the use-djstripe-for-features branch August 10, 2023 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subscriptions: use djstripe for Plan and PlanFeature models
4 participants