Supply interval param for creating the subscription

{month, year} work; needs testing for others
This commit is contained in:
PCoder 2019-09-19 15:13:52 +05:30
parent 5201b9a443
commit 665c327fc5
2 changed files with 6 additions and 3 deletions

View file

@ -278,7 +278,8 @@ class StripeUtils(object):
client.put("/v1/stripe_plans", json.dumps({"plans": list(stripe_plans)})) client.put("/v1/stripe_plans", json.dumps({"plans": list(stripe_plans)}))
@handleStripeError @handleStripeError
def get_or_create_stripe_plan(self, amount, name, stripe_plan_id): def get_or_create_stripe_plan(self, amount, name, stripe_plan_id,
interval=INTERVAL):
""" """
This function checks if a StripePlan with the given This function checks if a StripePlan with the given
stripe_plan_id already exists. If it exists then the function stripe_plan_id already exists. If it exists then the function
@ -290,6 +291,8 @@ class StripeUtils(object):
:param stripe_plan_id: The id of the Stripe plan to be :param stripe_plan_id: The id of the Stripe plan to be
created. Use get_stripe_plan_id_string function to created. Use get_stripe_plan_id_string function to
obtain the name of the plan to be created obtain the name of the plan to be created
:param interval: The interval for subscription {month, year}. Defaults
to month if not provided
:return: The StripePlan object if it exists else creates a :return: The StripePlan object if it exists else creates a
Plan object in Stripe and a local StripePlan and Plan object in Stripe and a local StripePlan and
returns it. Returns None in case of Stripe error returns it. Returns None in case of Stripe error
@ -309,7 +312,7 @@ class StripeUtils(object):
logger.debug("Plan {} does not exist in Stripe, Creating") logger.debug("Plan {} does not exist in Stripe, Creating")
plan_obj = self.stripe.Plan.create( plan_obj = self.stripe.Plan.create(
amount=amount, amount=amount,
interval=self.INTERVAL, interval=interval,
name=name, name=name,
currency=self.CURRENCY, currency=self.CURRENCY,
id=stripe_plan_id) id=stripe_plan_id)

View file

@ -295,7 +295,7 @@ class ProductOrder(Resource):
plan_id = get_plan_id_from_product(product_obj) plan_id = get_plan_id_from_product(product_obj)
res = stripe_utils.get_or_create_stripe_plan( res = stripe_utils.get_or_create_stripe_plan(
stripe_plan_id=plan_id, amount=product_obj["price"], stripe_plan_id=plan_id, amount=product_obj["price"],
name=plan_id name=plan_id, interval=product_obj["recurring_period"],
) )
if res["response_object"]: if res["response_object"]:
logging.debug("Obtained plan {}".format(plan_id)) logging.debug("Obtained plan {}".format(plan_id))