Fix issue : stripe user created every time for unauthenticated user
This commit is contained in:
parent
e110fd10f2
commit
07aaa20efe
1 changed files with 33 additions and 7 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
customer = StripeCustomer.create_stripe_api_customer(
|
try:
|
||||||
email=this_user.get('email'),
|
custom_user = CustomUser.objects.get(email=user_email)
|
||||||
token=token,
|
customer = StripeCustomer.objects.filter(
|
||||||
customer_name=form.cleaned_data.get('name'))
|
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(
|
||||||
|
email=user_email,
|
||||||
|
token=token,
|
||||||
|
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
|
||||||
|
@ -499,7 +525,7 @@ class OrderConfirmationView(DetailView):
|
||||||
stripe_subscription_obj = subscription_result.get('response_object')
|
stripe_subscription_obj = subscription_result.get('response_object')
|
||||||
# Check if the subscription was approved and is active
|
# Check if the subscription was approved and is active
|
||||||
if stripe_subscription_obj is None or \
|
if stripe_subscription_obj is None or \
|
||||||
stripe_subscription_obj.status != 'active':
|
stripe_subscription_obj.status != 'active':
|
||||||
msg = subscription_result.get('error')
|
msg = subscription_result.get('error')
|
||||||
messages.add_message(self.request, messages.ERROR, msg,
|
messages.add_message(self.request, messages.ERROR, msg,
|
||||||
extra_tags='failed_payment')
|
extra_tags='failed_payment')
|
||||||
|
|
Loading…
Reference in a new issue