Fix issue : stripe user created every time for unauthenticated user

This commit is contained in:
M.Ravi 2017-09-28 14:46:56 +02:00
parent e110fd10f2
commit 07aaa20efe

View file

@ -379,14 +379,40 @@ class PaymentOrderView(FormView):
email=this_user.get('email'), email=this_user.get('email'),
token=token) token=token)
else: else:
user_email = form.cleaned_data.get('email')
user_name = form.cleaned_data.get('name')
this_user = { this_user = {
'email': form.cleaned_data.get('email'), 'email': user_email,
'name': form.cleaned_data.get('name') 'name': user_name
} }
try:
custom_user = CustomUser.objects.get(email=user_email)
customer = StripeCustomer.objects.filter(
user_id=custom_user.id).first()
if customer is None:
logger.debug(
("User {email} is already registered with us."
"But, StripeCustomer does not exist for {email}."
"Hence, creating a new StripeCustomer.").format(
email=user_email
)
)
customer = StripeCustomer.create_stripe_api_customer( customer = StripeCustomer.create_stripe_api_customer(
email=this_user.get('email'), email=user_email,
token=token, token=token,
customer_name=form.cleaned_data.get('name')) customer_name=user_name)
except CustomUser.DoesNotExist:
logger.debug(
("StripeCustomer does not exist for {email}."
"Hence, creating a new StripeCustomer.").format(
email=user_email
)
)
customer = StripeCustomer.create_stripe_api_customer(
email=user_email,
token=token,
customer_name=user_name)
request.session['billing_address_data'] = form.cleaned_data request.session['billing_address_data'] = form.cleaned_data
request.session['user'] = this_user request.session['user'] = this_user
# Get or create stripe customer # Get or create stripe customer