Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Drop support for DJSTRIPE_DEFAULT_PLAN setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed May 30, 2017
1 parent 52ec9e7 commit 430dd04
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 84 deletions.
10 changes: 0 additions & 10 deletions djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down
8 changes: 0 additions & 8 deletions djstripe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 0 additions & 37 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
===========================================================================

Expand Down Expand Up @@ -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/$")
=====================================
Expand Down
29 changes: 0 additions & 29 deletions tests/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]")
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="[email protected]")
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))
Expand Down

0 comments on commit 430dd04

Please sign in to comment.