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

Commit

Permalink
Remove support for settings-based plans
Browse files Browse the repository at this point in the history
Plans should be managed in Stripe itself.
  • Loading branch information
jleclanche committed May 30, 2017
1 parent d82a6a3 commit 52ec9e7
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 315 deletions.
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions djstripe/management/commands/djstripe_init_plans.py

This file was deleted.

3 changes: 0 additions & 3 deletions djstripe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 1 addition & 23 deletions djstripe/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))
5 changes: 0 additions & 5 deletions djstripe/templatetags/__init__.py

This file was deleted.

33 changes: 0 additions & 33 deletions djstripe/templatetags/djstripe_tags.py

This file was deleted.

2 changes: 0 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ Run the commands::

python manage.py djstripe_init_customers

python manage.py djstripe_init_plans

Running Tests
--------------

Expand Down
117 changes: 0 additions & 117 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{% <plan_name>|djstripe_plan_level %}
Example:

.. code-block:: python
{% elif customer.subscription.plan == plan.plan %}
<h4>Your Current Plan</h4>
{% elif customer.subscription|djstripe_plan_level < plan.plan|djstripe_plan_level %}
<h4>Upgrade</h4>
{% elif customer.subscription|djstripe_plan_level > plan.plan|djstripe_plan_level %}
<h4>Downgrade</h4>
{% endif %}
DJSTRIPE_PRORATION_POLICY (=False)
==================================

Expand Down
23 changes: 0 additions & 23 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 0 additions & 17 deletions tests/test_djstripe_tags.py

This file was deleted.

68 changes: 2 additions & 66 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())

0 comments on commit 52ec9e7

Please sign in to comment.