Added name parameter for creating StripeCustomer and set description to this
This commit is contained in:
parent
3b1cd200d6
commit
3be7fbe2ee
2 changed files with 7 additions and 7 deletions
|
@ -173,7 +173,6 @@ class StripeCustomer(models.Model):
|
|||
Check if there is a registered stripe customer with that email
|
||||
or create a new one
|
||||
"""
|
||||
stripe_customer = None
|
||||
try:
|
||||
stripe_utils = StripeUtils()
|
||||
stripe_customer = cls.objects.get(user__email=email)
|
||||
|
@ -189,7 +188,7 @@ class StripeCustomer(models.Model):
|
|||
user = CustomUser.objects.get(email=email)
|
||||
|
||||
stripe_utils = StripeUtils()
|
||||
stripe_data = stripe_utils.create_customer(token, email)
|
||||
stripe_data = stripe_utils.create_customer(token, email, user.name)
|
||||
if stripe_data.get('response_object'):
|
||||
stripe_cus_id = stripe_data.get('response_object').get('id')
|
||||
|
||||
|
|
|
@ -90,12 +90,12 @@ class StripeUtils(object):
|
|||
def check_customer(self, id, user, token):
|
||||
customers = self.stripe.Customer.all()
|
||||
if not customers.get('data'):
|
||||
customer = self.create_customer(token, user.email)
|
||||
customer = self.create_customer(token, user.email, user.name)
|
||||
else:
|
||||
try:
|
||||
customer = stripe.Customer.retrieve(id)
|
||||
except stripe.InvalidRequestError:
|
||||
customer = self.create_customer(token, user.email)
|
||||
customer = self.create_customer(token, user.email, user.name)
|
||||
user.stripecustomer.stripe_id = customer.get('response_object').get('id')
|
||||
user.stripecustomer.save()
|
||||
return customer
|
||||
|
@ -107,11 +107,12 @@ class StripeUtils(object):
|
|||
return customer
|
||||
|
||||
@handleStripeError
|
||||
def create_customer(self, token, email):
|
||||
|
||||
def create_customer(self, token, email, name=None):
|
||||
if name is None or name.strip() == "":
|
||||
name = email
|
||||
customer = self.stripe.Customer.create(
|
||||
source=token,
|
||||
description='description for testing',
|
||||
description=name,
|
||||
email=email
|
||||
)
|
||||
return customer
|
||||
|
|
Loading…
Reference in a new issue