From 52ec9e7772a2923efb559a6ac46a4893e060fcee Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Mon, 13 Feb 2017 07:48:27 +0200 Subject: [PATCH] Remove support for settings-based plans Plans should be managed in Stripe itself. --- README.rst | 2 - .../commands/djstripe_init_plans.py | 24 ---- djstripe/settings.py | 3 - djstripe/sync.py | 24 +--- djstripe/templatetags/__init__.py | 5 - djstripe/templatetags/djstripe_tags.py | 33 ----- docs/installation.rst | 2 - docs/settings.rst | 117 ------------------ runtests.py | 23 ---- tests/test_djstripe_tags.py | 17 --- tests/test_sync.py | 68 +--------- 11 files changed, 3 insertions(+), 315 deletions(-) delete mode 100644 djstripe/management/commands/djstripe_init_plans.py delete mode 100644 djstripe/templatetags/__init__.py delete mode 100644 djstripe/templatetags/djstripe_tags.py delete mode 100644 tests/test_djstripe_tags.py diff --git a/README.rst b/README.rst index 92cc4bc88d..09af8d2a98 100644 --- a/README.rst +++ b/README.rst @@ -119,8 +119,6 @@ Run the commands:: python manage.py djstripe_init_customers - python manage.py djstripe_init_plans - If you haven't already, add JQuery and the Bootstrap 3.0.0+ JS and CSS to your base template: .. code-block:: html diff --git a/djstripe/management/commands/djstripe_init_plans.py b/djstripe/management/commands/djstripe_init_plans.py deleted file mode 100644 index f692f1e276..0000000000 --- a/djstripe/management/commands/djstripe_init_plans.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -""" -.. module:: djstripe.management.commands.djstripe_init_plans. - - :synopsis: dj-stripe - init_plans command. - -.. moduleauthor:: @kavdev, @pydanny - -""" -from __future__ import unicode_literals - -from django.core.management.base import BaseCommand - -from ...sync import sync_plans - - -class Command(BaseCommand): - """Make sure your Stripe account has the plans.""" - - help = "Make sure your Stripe account has the plans" - - def handle(self, *args, **options): - """Call sync_plans.""" - sync_plans() diff --git a/djstripe/settings.py b/djstripe/settings.py index 9314108c90..890b00939e 100644 --- a/djstripe/settings.py +++ b/djstripe/settings.py @@ -66,9 +66,6 @@ def _get_idempotency_key(object_type, action, livemode): get_idempotency_key = get_callback_function("DJSTRIPE_IDEMPOTENCY_KEY_CALLBACK", _get_idempotency_key) -PAYMENTS_PLANS = getattr(settings, "DJSTRIPE_PLANS", {}) -PLAN_HIERARCHY = getattr(settings, "DJSTRIPE_PLAN_HIERARCHY", {}) - PRORATION_POLICY = getattr(settings, 'DJSTRIPE_PRORATION_POLICY', False) PRORATION_POLICY_FOR_UPGRADES = getattr(settings, 'DJSTRIPE_PRORATION_POLICY_FOR_UPGRADES', False) CANCELLATION_AT_PERIOD_END = not getattr(settings, 'DJSTRIPE_PRORATION_POLICY', False) diff --git a/djstripe/sync.py b/djstripe/sync.py index 8cf29bb372..49e0118010 100644 --- a/djstripe/sync.py +++ b/djstripe/sync.py @@ -8,11 +8,9 @@ """ from __future__ import unicode_literals -from django.conf import settings - from stripe.error import InvalidRequestError -from .models import Customer, Plan +from .models import Customer def sync_subscriber(subscriber): @@ -27,23 +25,3 @@ def sync_subscriber(subscriber): except InvalidRequestError as e: print("ERROR: " + str(e)) return customer - - -def sync_plans(): - """Sync plans with Stripe api data.""" - for plan in settings.DJSTRIPE_PLANS: - stripe_plan = settings.DJSTRIPE_PLANS[plan] - if stripe_plan.get("stripe_plan_id"): - try: - # A few minor things are changed in the api-version of the create call - api_kwargs = dict(stripe_plan) - api_kwargs['id'] = api_kwargs['stripe_plan_id'] - api_kwargs['amount'] = api_kwargs['price'] - del(api_kwargs['stripe_plan_id']) - del(api_kwargs['price']) - del(api_kwargs['description']) - - Plan._api_create(**api_kwargs) - print("Plan created for {0}".format(plan)) - except Exception as e: - print("ERROR: " + str(e)) diff --git a/djstripe/templatetags/__init__.py b/djstripe/templatetags/__init__.py deleted file mode 100644 index 085c4ca96c..0000000000 --- a/djstripe/templatetags/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -.. module:: djstripe.templatetags. - - :synopsis: dj-stripe - Custom tags to be used in templates. -""" diff --git a/djstripe/templatetags/djstripe_tags.py b/djstripe/templatetags/djstripe_tags.py deleted file mode 100644 index 5d1e763cb5..0000000000 --- a/djstripe/templatetags/djstripe_tags.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -""" -.. module:: djstripe.templatetags.djstripe_tags. - - :synopsis: dj-stripe - Custom tags to be used in templates. - -.. moduleauthor:: @kavdev, @pydanny, @chrissmejia, @audreyr -""" -from __future__ import division - -from django.template import Library -from .. import settings as djstripe_settings - -register = Library() - - -@register.filter(name='djstripe_plan_level') -def djstripe_plan_level(name): - """ - Add support to levels over plans, then you can have different kind of plans with the level same access. - - Use: {{ |djstripe_plan_level }} - - Note: Custom settings setup is needed, please see the documentation for details. - """ - level = -1 - hierarchy_dict = djstripe_settings.PLAN_HIERARCHY - - for config_level in hierarchy_dict.values(): - if name in config_level["plans"]: - level = config_level["level"] - - return level diff --git a/docs/installation.rst b/docs/installation.rst index 89f5bef5c5..f712c04d9a 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -111,8 +111,6 @@ Run the commands:: python manage.py djstripe_init_customers - python manage.py djstripe_init_plans - Running Tests -------------- diff --git a/docs/settings.rst b/docs/settings.rst index f1faa662ae..a3174f52fe 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -57,123 +57,6 @@ For more information, see the `stripe documentation`_. .. _stripe documentation: https://stripe.com/docs/api/curl#idempotent_requests -DJSTRIPE_PLANS (={}) -==================== - -Payment plans. - -Possibly deprecated in favor of model based plans. - -Example: - -.. code-block:: python - - DJSTRIPE_PLANS = { - "monthly": { - "stripe_plan_id": "pro-monthly", - "name": "Web App Pro ($24.99/month)", - "description": "The monthly subscription plan to WebApp", - "price": 2499, # $24.99 - "currency": "usd", - "interval": "month", - "image": "img/pro-monthly.png" - }, - "yearly": { - "stripe_plan_id": "pro-yearly", - "name": "Web App Pro ($199/year)", - "description": "The annual subscription plan to WebApp", - "price": 19900, # $199.00 - "currency": "usd", - "interval": "year", - "image": "img/pro-yearly.png" - } - } - -.. note:: Stripe Plan creation - - Not all properties listed in the plans above are used by Stripe - i.e 'description' and 'image', - which are used to display the plans description and related image within specific templates. - - Although any arbitrary property you require can be added to each plan listed in DJ_STRIPE_PLANS, - only specific properties are used by Stripe. The full list of required and optional arguments can - be found here_. - -.. _here: https://stripe.com/docs/api/python#create_plan - -DJSTRIPE_PLAN_HIERARCHY (={}) -============================= - -Payment plans levels. - -Allows you to set levels of access to the plans. - -Example: - -.. code-block:: python - - DJSTRIPE_PLANS = { - "bronze-monthly": { - ... - }, - "bronze-yearly": { - ... - }, - "silver-monthly": { - ... - }, - "silver-yearly": { - ... - }, - "gold-monthly": { - ... - }, - "gold-yearly": { - ... - } - } - - DJSTRIPE_PLAN_HIERARCHY = { - "bronze": { - "level": 1, - "plans": [ - "bronze-monthly", - "bronze-yearly", - ] - }, - "silver": { - "level": 2, - "plans": [ - "silver-monthly", - "silver-yearly", - ] - }, - "gold": { - "level": 3, - "plans": [ - "gold-monthly", - "gold-yearly", - ] - }, - } - -Use: - -.. code-block:: python - - {% |djstripe_plan_level %} - -Example: - -.. code-block:: python - - {% elif customer.subscription.plan == plan.plan %} -

Your Current Plan

- {% elif customer.subscription|djstripe_plan_level < plan.plan|djstripe_plan_level %} -

Upgrade

- {% elif customer.subscription|djstripe_plan_level > plan.plan|djstripe_plan_level %} -

Downgrade

- {% endif %} - DJSTRIPE_PRORATION_POLICY (=False) ================================== diff --git a/runtests.py b/runtests.py index 936fdd1225..b37cb4909c 100644 --- a/runtests.py +++ b/runtests.py @@ -130,29 +130,6 @@ def run_test_suite(args): "interval": "month" } }, - DJSTRIPE_PLAN_HIERARCHY={ - "bronze": { - "level": 1, - "plans": [ - "test0", - "test", - ] - }, - "silver": { - "level": 2, - "plans": [ - "test2", - "test_deletion", - ] - }, - "gold": { - "level": 3, - "plans": [ - "test_trial", - "unidentified_test_plan", - ] - }, - }, DJSTRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS=( "(admin)", "test_url_name", diff --git a/tests/test_djstripe_tags.py b/tests/test_djstripe_tags.py deleted file mode 100644 index d3d0ee773e..0000000000 --- a/tests/test_djstripe_tags.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.template import Template, Context -from django.test import TestCase - - -class TestHierarchy(TestCase): - - def test_unknow_hierarchy(self): - template = Template('{% load djstripe_tags %}{{ "test999"|djstripe_plan_level }}') - context = Context({}) - rendered = template.render(context) - self.assertEqual(rendered, "-1") - - def test_correct_hierarchy(self): - template = Template('{% load djstripe_tags %}{{ "test_deletion"|djstripe_plan_level }}') - context = Context({}) - rendered = template.render(context) - self.assertEqual(rendered, "2") diff --git a/tests/test_sync.py b/tests/test_sync.py index 9fc147ab25..f4f9a67ded 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -9,14 +9,13 @@ from copy import deepcopy import sys -from django.conf import settings from django.contrib.auth import get_user_model from django.test.testcases import TestCase from mock import patch -from stripe.error import StripeError, InvalidRequestError +from stripe.error import InvalidRequestError from djstripe.models import Customer -from djstripe.sync import sync_subscriber, sync_plans +from djstripe.sync import sync_subscriber from . import FAKE_CUSTOMER @@ -53,66 +52,3 @@ def test_sync_fail(self, stripe_customer_create_mock, api_retrieve_mock, _sync_m sync_subscriber(self.user) self.assertEqual("ERROR: No such customer:", sys.stdout.getvalue().strip()) - - -class TestSyncPlans(TestCase): - - @patch("stripe.Plan.create") - def test_plan_created(self, plan_create_mock): - sync_plans() - self.assertTrue("Plan created for test", sys.stdout.getvalue().strip()) - - plan_create_mock.assert_any_call( - api_key=settings.STRIPE_SECRET_KEY, - amount=1000, - interval="month", - name="Test Plan 0", - currency="usd", - id="test_id_0" - ) - - plan_create_mock.assert_any_call( - api_key=settings.STRIPE_SECRET_KEY, - amount=2500, - interval="month", - name="Test Plan 1", - currency="usd", - id="test_id" - ) - - plan_create_mock.assert_any_call( - api_key=settings.STRIPE_SECRET_KEY, - amount=5000, - interval="month", - name="Test Plan 2", - currency="usd", - id="test_id_2" - ) - - plan_create_mock.assert_any_call( - api_key=settings.STRIPE_SECRET_KEY, - amount=5000, - interval="month", - name="Test Plan 3", - currency="usd", - id="test_id_3" - ) - - plan_create_mock.assert_any_call( - api_key=settings.STRIPE_SECRET_KEY, - amount=7000, - interval="month", - name="Test Plan 4", - currency="usd", - id="test_id_4", - trial_period_days=7 - ) - - self.assertEqual(5, plan_create_mock.call_count) - - @patch("stripe.Plan.create") - def test_plan_exists(self, plan_create_mock): - plan_create_mock.side_effect = StripeError("Plan already exists.") - - sync_plans() - self.assertTrue("ERROR: Plan already exists.", sys.stdout.getvalue().strip())