From 85d19c004be83d66f307a5eaa030bc6a9fdcc10a Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 26 Oct 2017 15:21:29 +0200 Subject: [PATCH] Remove redundant code in check_customer --- utils/stripe_utils.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index ac01b9d5..5299e4d5 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -126,21 +126,14 @@ class StripeUtils(object): } return card_details - def check_customer(self, id, user, token): - customers = self.stripe.Customer.list() - if not customers.get('data'): + def check_customer(self, stripe_cus_api_id, user, token): + try: + customer = stripe.Customer.retrieve(stripe_cus_api_id) + except stripe.InvalidRequestError: customer = self.create_customer(token, user.email, user.name) user.stripecustomer.stripe_id = customer.get( 'response_object').get('id') user.stripecustomer.save() - else: - try: - customer = stripe.Customer.retrieve(id) - except stripe.InvalidRequestError: - customer = self.create_customer(token, user.email, user.name) - user.stripecustomer.stripe_id = customer.get( - 'response_object').get('id') - user.stripecustomer.save() if type(customer) is dict: customer = customer['response_object'] return customer