diff --git a/stripe_utils.py b/stripe_utils.py index d963997..f70de51 100644 --- a/stripe_utils.py +++ b/stripe_utils.py @@ -278,7 +278,8 @@ class StripeUtils(object): client.put("/v1/stripe_plans", json.dumps({"plans": list(stripe_plans)})) @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 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 created. Use get_stripe_plan_id_string function to 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 Plan object in Stripe and a local StripePlan and 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") plan_obj = self.stripe.Plan.create( amount=amount, - interval=self.INTERVAL, + interval=interval, name=name, currency=self.CURRENCY, id=stripe_plan_id) diff --git a/ucloud_pay.py b/ucloud_pay.py index 67d5ac8..0667a33 100644 --- a/ucloud_pay.py +++ b/ucloud_pay.py @@ -295,7 +295,7 @@ class ProductOrder(Resource): plan_id = get_plan_id_from_product(product_obj) res = stripe_utils.get_or_create_stripe_plan( stripe_plan_id=plan_id, amount=product_obj["price"], - name=plan_id + name=plan_id, interval=product_obj["recurring_period"], ) if res["response_object"]: logging.debug("Obtained plan {}".format(plan_id))