From 430dd04583786401766f39a7a88f9c2c7bb7a964 Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Mon, 27 Feb 2017 05:14:43 +0200 Subject: [PATCH] Drop support for DJSTRIPE_DEFAULT_PLAN setting --- djstripe/models.py | 10 ---------- djstripe/settings.py | 8 -------- docs/settings.rst | 37 ------------------------------------- tests/test_customer.py | 29 ----------------------------- 4 files changed, 84 deletions(-) diff --git a/djstripe/models.py b/djstripe/models.py index 98aae5fffe..5928e99277 100644 --- a/djstripe/models.py +++ b/djstripe/models.py @@ -207,10 +207,6 @@ def get_or_create(cls, subscriber, livemode=djstripe_settings.STRIPE_LIVE_MODE): @classmethod def create(cls, subscriber, idempotency_key=None): - trial_days = None - if djstripe_settings.trial_period_for_subscriber_callback: - trial_days = djstripe_settings.trial_period_for_subscriber_callback(subscriber) - stripe_customer = cls._api_create( email=subscriber.email, idempotency_key=idempotency_key, @@ -221,12 +217,6 @@ def create(cls, subscriber, idempotency_key=None): defaults={"subscriber": subscriber, "livemode": stripe_customer["livemode"]} ) - if djstripe_settings.DEFAULT_PLAN and trial_days: - customer.subscribe( - plan=djstripe_settings.DEFAULT_PLAN, - trial_end=timezone.now() + timezone.timedelta(days=trial_days) - ) - return customer def purge(self): diff --git a/djstripe/settings.py b/djstripe/settings.py index 890b00939e..309af43095 100644 --- a/djstripe/settings.py +++ b/djstripe/settings.py @@ -70,14 +70,6 @@ def _get_idempotency_key(object_type, action, livemode): PRORATION_POLICY_FOR_UPGRADES = getattr(settings, 'DJSTRIPE_PRORATION_POLICY_FOR_UPGRADES', False) CANCELLATION_AT_PERIOD_END = not getattr(settings, 'DJSTRIPE_PRORATION_POLICY', False) -DEFAULT_PLAN = getattr(settings, "DJSTRIPE_DEFAULT_PLAN", None) - -# Try to find the new settings variable first. If that fails, revert to the -# old variable. -trial_period_for_subscriber_callback = ( - get_callback_function("DJSTRIPE_TRIAL_PERIOD_FOR_SUBSCRIBER_CALLBACK") or - get_callback_function("DJSTRIPE_TRIAL_PERIOD_FOR_USER_CALLBACK")) - DJSTRIPE_WEBHOOK_URL = getattr(settings, "DJSTRIPE_WEBHOOK_URL", r"^webhook/$") # Webhook event callbacks allow an application to take control of what happens diff --git a/docs/settings.rst b/docs/settings.rst index a3174f52fe..4973144ec9 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -27,14 +27,6 @@ For more information on API versioning, see the `stripe documentation`_. .. _stripe documentation: https://stripe.com/docs/upgrades -DJSTRIPE_DEFAULT_PLAN (=None) -============================= - -Payment plans default. - -Possibly deprecated in favor of model based plans. - - DJSTRIPE_IDEMPOTENCY_KEY_CALLBACK (=djstripe.settings._get_idempotency_key) =========================================================================== @@ -178,35 +170,6 @@ Examples: .. note:: This callback only becomes active when ``DJSTRIPE_SUBSCRIBER_MODEL`` is set. -DJSTRIPE_TRIAL_PERIOD_FOR_SUBSCRIBER_CALLBACK (=None) -===================================================== - -Used by ``djstripe.models.Customer`` only when creating stripe customers when you have a default plan set via ``DJSTRIPE_DEFAULT_PLAN``. - -This is called to dynamically add a trial period to a subscriber's plan. It must be a callable or importable string to a callable that takes a subscriber object and returns the number of days the trial period should last. - -Examples: - -.. code-block:: python - - def static_trial_period(subscriber): - """ Adds a static trial period of 7 days to each subscriber's account.""" - return 7 - - - def dynamic_trial_period(subscriber): - """ - Adds a static trial period of 7 days to each subscriber's plan, - unless they've accepted our month-long promotion. - """ - - if subscriber.coupons.get(slug="monthlongtrial"): - return 30 - else: - return 7 - -.. note:: This setting was named ``DJSTRIPE_TRIAL_PERIOD_FOR_USER_CALLBACK`` prior to version 0.4 - DJSTRIPE_WEBHOOK_URL (=r"^webhook/$") ===================================== diff --git a/tests/test_customer.py b/tests/test_customer.py index b1fc12f6bb..0986038196 100644 --- a/tests/test_customer.py +++ b/tests/test_customer.py @@ -377,35 +377,6 @@ def test_charge_card_source(self, charge_create_mock, charge_retrieve_mock, defa source=self.card, ) - @patch("djstripe.models.djstripe_settings.trial_period_for_subscriber_callback", return_value=7) - @patch("stripe.Customer.create", return_value=deepcopy(FAKE_CUSTOMER_II)) - def test_create_trial_callback_without_default_plan(self, create_mock, callback_mock): - user = get_user_model().objects.create_user(username="test", email="test@gmail.com") - Customer.create(user, idempotency_key="foo") - - create_mock.assert_called_once_with( - api_key=settings.STRIPE_SECRET_KEY, email=user.email, idempotency_key="foo", - metadata={"djstripe_subscriber": user.id} - ) - callback_mock.assert_called_once_with(user) - - @patch("djstripe.models.Customer.subscribe") - @patch("djstripe.models.djstripe_settings.DEFAULT_PLAN") - @patch("djstripe.models.djstripe_settings.trial_period_for_subscriber_callback", return_value=7) - @patch("stripe.Customer.create", return_value=deepcopy(FAKE_CUSTOMER_II)) - def test_create_default_plan(self, create_mock, callback_mock, default_plan_fake, subscribe_mock): - user = get_user_model().objects.create_user(username="test", email="test@gmail.com") - Customer.create(user, idempotency_key="foo") - - create_mock.assert_called_once_with( - api_key=settings.STRIPE_SECRET_KEY, email=user.email, idempotency_key="foo", - metadata={"djstripe_subscriber": user.id} - ) - callback_mock.assert_called_once_with(user) - - self.assertTrue(subscribe_mock.called) - self.assertTrue(1, subscribe_mock.call_count) - @patch("djstripe.models.Account.get_default_account") @patch("stripe.Subscription.retrieve", return_value=deepcopy(FAKE_SUBSCRIPTION)) @patch("stripe.Customer.retrieve", return_value=deepcopy(FAKE_CUSTOMER))