-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from 38 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
5570a73
Subscriptions: use djstripe for products/features
stsewd 703cd65
Fix tests
stsewd efde180
Updates
stsewd d207565
Linter
stsewd b7f9c85
More updates
stsewd 4e11f6f
Linter
stsewd a1cb32e
Merge branch 'main' into use-djstripe-for-features
stsewd 27f9003
Default
stsewd 2aa04f8
Default listed to False
stsewd 356f18d
Fix tests
stsewd 3c65b4b
Black
stsewd 2fc1cbb
Merge branch 'main' into use-djstripe-for-features
stsewd e432063
Fixes
stsewd 6462892
Fix
stsewd cd25bba
Merge branch 'main' into use-djstripe-for-features
stsewd 9864e44
Merge branch 'main' into use-djstripe-for-features
stsewd aeadfb6
Migrate new tests
stsewd 90f6928
Fix linter
stsewd 8409136
Migrate more features
stsewd 91284b9
Small fixes
stsewd 52a36c5
Document local testing
stsewd 3d9ea19
Include in index
stsewd 29faab5
Filter by active prices
stsewd f9b060c
Better description for page views logs
stsewd 2399515
Support for multiple products
stsewd a8950d3
Migration
stsewd 3084035
format
stsewd 45a1574
More docs
stsewd 8589904
Merge branch 'main' into use-djstripe-for-features
stsewd 9f6e3bf
Use new logic to get subscription
stsewd 03d5139
Fix
stsewd df0a7d5
Invert
stsewd dd42fd9
Linter
stsewd b89f7aa
Fix test on .com
stsewd f1486f6
Quantity
stsewd 6c38514
Tests
stsewd 95eb6f1
More tests
stsewd 19dd947
Fix test on .com
stsewd 87d1cd9
Merge branch 'main' into use-djstripe-for-features
stsewd 62f29d3
Avoid nesting
stsewd c0ac743
Merge branch 'main' into use-djstripe-for-features
stsewd aa92198
Merge branch 'main' into use-djstripe-for-features
stsewd 83e26d1
Update from review
stsewd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
Subscriptions | ||
============= | ||
|
||
Subscriptions are available on |com_brand|, | ||
we make use of Stripe to handle the payments and subscriptions. | ||
We use dj-stripe to handle the integration with Stripe. | ||
|
||
Local testing | ||
------------- | ||
|
||
To test subscriptions locally, you need to have access to the Stripe account, | ||
and define the following settings with the keys from Stripe test mode: | ||
|
||
- ``STRIPE_SECRET``: https://dashboard.stripe.com/test/apikeys | ||
- ``STRIPE_TEST_SECRET_KEY``: https://dashboard.stripe.com/test/apikeys | ||
- ``DJSTRIPE_WEBHOOK_SECRET``: https://dashboard.stripe.com/test/webhooks | ||
|
||
To test the webhook locally, you need to run your local instance with ngrok, for example: | ||
|
||
.. code-block:: bash | ||
|
||
ngrok http 80 | ||
inv docker.up --http-domain xxx.ngrok.io | ||
|
||
If this is your first time setting up subscriptions, you will to re-sync djstripe with Stripe: | ||
|
||
.. code-block:: bash | ||
|
||
inv docker.manage djstripe_sync_models | ||
|
||
The subscription settings (``RTD_PRODUCTS``) already mapped to match the Stripe prices from the test mode. | ||
To subscribe to any plan, you can use any `test card from Stripe <https://stripe.com/docs/testing>`__, | ||
for example: ``4242 4242 4242 4242`` (use any future date and any value for the other fields). | ||
|
||
Modeling | ||
-------- | ||
|
||
Subscriptions are attached to an organization (customer), | ||
and can have multiple prices of products attached to it. | ||
A product can have multiple prices, usually monthly and yearly. | ||
|
||
When a user subscribes to a plan (product), they are subscribing to a price of a product, | ||
for example, the monthly price of the "Basic plan" product. | ||
|
||
A subscription has a "main" product (``RTDProduct(extra=False)``), | ||
and can have several "extra" products (``RTDProduct(extra=True)``). | ||
For example, an organization can have a subscription with a "Basic Plan" product, and an "Extra builder" product. | ||
|
||
Each product is mapped to a set of features (``RTD_PRODUCTS``) that the user will have access to | ||
(different prices of the same product have the same features). | ||
If a subscription has multiple products, the features are multiplied by the quantity and added together. | ||
For example, if a subscription has a "Basic Plan" product with a two concurrent builders, | ||
and an "Extra builder" product with quantity three, the total number of concurrent builders the | ||
organization has will be five. | ||
|
||
Life cycle of a subscription | ||
---------------------------- | ||
|
||
When a new organization is created, a stripe customer is created for that organization, | ||
and this customer is subscribed to the trial product (``RTD_ORG_DEFAULT_STRIPE_SUBSCRIPTION_PRICE``). | ||
|
||
After the trial period is over, the subscription is canceled, | ||
and their organization is disabled. | ||
|
||
During or after the trial a user can upgrade their subscription to a paid plan | ||
(``RTDProduct(listed=True)``). | ||
|
||
Custom products | ||
--------------- | ||
|
||
We provide 3 paid plans that users can subscribe to: Basic, Advanced and Pro. | ||
Additionally, we provide an Enterprise plan, this plan is customized for each customer, | ||
and it's manually created by the RTD core team. | ||
|
||
To create a custom plan, you need to create a new product in Stripe, | ||
and add the product id to the ``RTD_PRODUCTS`` setting mapped to the features that the plan will provide. | ||
After that, you can create a subscription for the organization with the custom product, | ||
our appliction will automatically relate this new product to the organization. | ||
|
||
Extra products | ||
-------------- | ||
|
||
We have one extra product: Extra builder. | ||
|
||
To create a new extra product, you need to create a new product in Stripe, | ||
and add the product id to the ``RTD_PRODUCTS`` setting mapped to the features that the | ||
extra product will provide, this product should have the ``extra`` attribute set to ``True``. | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is clearer?
There was a problem hiding this comment.
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.