From 3be7fbe2eee8e8e98c8734b3f518f33edfabd478 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 15 Aug 2017 16:05:52 +0530 Subject: [PATCH] Added name parameter for creating StripeCustomer and set description to this --- membership/models.py | 3 +-- utils/stripe_utils.py | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/membership/models.py b/membership/models.py index 6b6f4413..72b8073e 100644 --- a/membership/models.py +++ b/membership/models.py @@ -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') diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index d46cf54d..aaf3d9e9 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -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