From 1f1565fdaa188e6d7dc7378c8f8fa2e5403e36b5 Mon Sep 17 00:00:00 2001 From: yackob03 Date: Mon, 11 Nov 2013 11:58:30 -0500 Subject: [PATCH] Fix the bug where trying to unsubscribe a customer with no subscription throws an error. --- endpoints/api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/endpoints/api.py b/endpoints/api.py index bac8d10c9..4d31518ef 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -1217,8 +1217,10 @@ def subscribe(user, plan, token, accepted_plans): cus = stripe.Customer.retrieve(user.stripe_id) if plan_found['price'] == 0: - cus.cancel_subscription() - cus.save() + if cus.subscription is not None: + # We only have to cancel the subscription if they actually have one + cus.cancel_subscription() + cus.save() response_json = { 'plan': plan,