|
| 1 | +Subscriptions |
| 2 | +============= |
| 3 | + |
| 4 | +Subscriptions are available on |com_brand|, |
| 5 | +we make use of Stripe to handle the payments and subscriptions. |
| 6 | +We use dj-stripe to handle the integration with Stripe. |
| 7 | + |
| 8 | +Local testing |
| 9 | +------------- |
| 10 | + |
| 11 | +To test subscriptions locally, you need to have access to the Stripe account, |
| 12 | +and define the following settings with the keys from Stripe test mode: |
| 13 | + |
| 14 | +- ``STRIPE_SECRET``: https://dashboard.stripe.com/test/apikeys |
| 15 | +- ``STRIPE_TEST_SECRET_KEY``: https://dashboard.stripe.com/test/apikeys |
| 16 | +- ``DJSTRIPE_WEBHOOK_SECRET``: https://dashboard.stripe.com/test/webhooks |
| 17 | + |
| 18 | +To test the webhook locally, you need to run your local instance with ngrok, for example: |
| 19 | + |
| 20 | +.. code-block:: bash |
| 21 | +
|
| 22 | + ngrok http 80 |
| 23 | + inv docker.up --http-domain xxx.ngrok.io |
| 24 | +
|
| 25 | +If this is your first time setting up subscriptions, you will to re-sync djstripe with Stripe: |
| 26 | + |
| 27 | +.. code-block:: bash |
| 28 | +
|
| 29 | + inv docker.manage djstripe_sync_models |
| 30 | +
|
| 31 | +The subscription settings (``RTD_PRODUCTS``) already mapped to match the Stripe prices from the test mode. |
| 32 | +To subscribe to any plan, you can use any `test card from Stripe <https://stripe.com/docs/testing>`__, |
| 33 | +for example: ``4242 4242 4242 4242`` (use any future date and any value for the other fields). |
| 34 | + |
| 35 | +Modeling |
| 36 | +-------- |
| 37 | + |
| 38 | +Subscriptions are attached to an organization (customer), |
| 39 | +and can have multiple products attached to it. |
| 40 | +A product can have multiple prices, usually monthly and yearly. |
| 41 | + |
| 42 | +When a user subscribes to a plan (product), they are subscribing to a price of a product, |
| 43 | +for example, the monthly price of the "Basic plan" product. |
| 44 | + |
| 45 | +A subscription has a "main" product (``RTDProduct(extra=False)``), |
| 46 | +and can have several "extra" products (``RTDProduct(extra=True)``). |
| 47 | +For example, an organization can have a subscription with a "Basic Plan" product, and an "Extra builder" product. |
| 48 | + |
| 49 | +Each product is mapped to a set of features (``RTD_PRODUCTS``) that the user will have access to |
| 50 | +(different prices of the same product have the same features). |
| 51 | +If a subscription has multiple products, the features are multiplied by the quantity and added together. |
| 52 | +For example, if a subscription has a "Basic Plan" product with a two concurrent builders, |
| 53 | +and an "Extra builder" product with quantity three, the total number of concurrent builders the |
| 54 | +organization has will be five. |
| 55 | + |
| 56 | +Life cycle of a subscription |
| 57 | +---------------------------- |
| 58 | + |
| 59 | +When a new organization is created, a stripe customer is created for that organization, |
| 60 | +and this customer is subscribed to the trial product (``RTD_ORG_DEFAULT_STRIPE_SUBSCRIPTION_PRICE``). |
| 61 | + |
| 62 | +After the trial period is over, the subscription is canceled, |
| 63 | +and their organization is disabled. |
| 64 | + |
| 65 | +During or after the trial a user can upgrade their subscription to a paid plan |
| 66 | +(``RTDProduct(listed=True)``). |
| 67 | + |
| 68 | +Custom products |
| 69 | +--------------- |
| 70 | + |
| 71 | +We provide 3 paid plans that users can subscribe to: Basic, Advanced and Pro. |
| 72 | +Additionally, we provide an Enterprise plan, this plan is customized for each customer, |
| 73 | +and it's manually created by the RTD core team. |
| 74 | + |
| 75 | +To create a custom plan, you need to create a new product in Stripe, |
| 76 | +and add the product id to the ``RTD_PRODUCTS`` setting mapped to the features that the plan will provide. |
| 77 | +After that, you can create a subscription for the organization with the custom product, |
| 78 | +our appliction will automatically relate this new product to the organization. |
| 79 | + |
| 80 | +Extra products |
| 81 | +-------------- |
| 82 | + |
| 83 | +We have one extra product: Extra builder. |
| 84 | + |
| 85 | +To create a new extra product, you need to create a new product in Stripe, |
| 86 | +and add the product id to the ``RTD_PRODUCTS`` setting mapped to the features that the |
| 87 | +extra product will provide, this product should have the ``extra`` attribute set to ``True``. |
| 88 | + |
| 89 | +To subscribe an organization to an extra product, |
| 90 | +you just need to add the product to its subscription with the desired quantity, |
| 91 | +our appliction will automatically relate this new product to the organization. |
0 commit comments