Remove redundant code in check_customer

This commit is contained in:
M.Ravi 2017-10-26 15:21:29 +02:00
parent 692f82cba4
commit 85d19c004b

View file

@ -126,21 +126,14 @@ class StripeUtils(object):
} }
return card_details return card_details
def check_customer(self, id, user, token): def check_customer(self, stripe_cus_api_id, user, token):
customers = self.stripe.Customer.list() try:
if not customers.get('data'): customer = stripe.Customer.retrieve(stripe_cus_api_id)
except stripe.InvalidRequestError:
customer = self.create_customer(token, user.email, user.name) customer = self.create_customer(token, user.email, user.name)
user.stripecustomer.stripe_id = customer.get( user.stripecustomer.stripe_id = customer.get(
'response_object').get('id') 'response_object').get('id')
user.stripecustomer.save() 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: if type(customer) is dict:
customer = customer['response_object'] customer = customer['response_object']
return customer return customer