summaryrefslogtreecommitdiff
path: root/fundraising
diff options
context:
space:
mode:
authorÇağıl <cagilulusahin@gmail.com>2019-07-16 19:54:16 +0100
committerCarlton Gibson <carlton.gibson@noumenal.es>2019-07-16 20:54:16 +0200
commitc676fbbacba830bfb49b7540eb729f31a7ea9c16 (patch)
treed8bd3494e4c67ee8eb158ff1eea42335f03154e3 /fundraising
parentf351df48dc5a1ea4849ccceba9cb43fbf71cb168 (diff)
Add management command that creates missing plans for fundraising subscriptions (#906)
Diffstat (limited to 'fundraising')
-rw-r--r--fundraising/management/commands/create_stripe_plans.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/fundraising/management/commands/create_stripe_plans.py b/fundraising/management/commands/create_stripe_plans.py
new file mode 100644
index 00000000..f1705946
--- /dev/null
+++ b/fundraising/management/commands/create_stripe_plans.py
@@ -0,0 +1,54 @@
+import logging
+
+import stripe
+from django.core.management import BaseCommand
+
+logger = logging.getLogger(__name__)
+
+
+class Command(BaseCommand):
+ def handle(self, **kwargs):
+ try:
+ stripe.Plan.retrieve("monthly")
+ print("Monthly plan exists, not creating!")
+ except stripe.error.InvalidRequestError:
+ name = "Monthly donation"
+ logger.info("Creating plan: {0}".format(name))
+ stripe.Plan.create(
+ id="monthly",
+ amount=100,
+ interval="month",
+ interval_count=1,
+ product={"name": name},
+ currency="usd",
+ )
+ try:
+ stripe.Plan.retrieve("quarterly")
+ print("Quarterly plan exists, not creating!")
+ except stripe.error.InvalidRequestError:
+ name = "Quarterly donation"
+ logger.info("Creating plan: {0}".format(name))
+ stripe.Plan.create(
+ id="quarterly",
+ amount=100,
+ interval="month",
+ interval_count=3,
+ nickname=name,
+ product={"name": name},
+ currency="usd",
+ )
+ try:
+ stripe.Plan.retrieve("yearly")
+ print("Yearly plan exists, not creating!")
+ except stripe.error.InvalidRequestError:
+ name = "Yearly donation"
+ logger.info("Creating plan: {0}".format(name))
+ stripe.Plan.create(
+ id="yearly",
+ amount=100,
+ interval="year",
+ interval_count=1,
+ nickname=name,
+ product={"name": name},
+ currency="usd",
+ )