Refactor and correct some logic
This commit is contained in:
parent
57f0757fa3
commit
c13015eabd
1 changed files with 11 additions and 23 deletions
|
@ -421,8 +421,10 @@ class PaymentOrderView(FormView):
|
||||||
return self.render_to_response(
|
return self.render_to_response(
|
||||||
self.get_context_data(form=form))
|
self.get_context_data(form=form))
|
||||||
request.session['token'] = token
|
request.session['token'] = token
|
||||||
request.session[
|
if type(customer) is StripeCustomer:
|
||||||
'customer'] = customer.id if request.user.is_authenticated() else customer
|
request.session['customer'] = customer.stripe_id
|
||||||
|
else:
|
||||||
|
request.session['customer'] = customer
|
||||||
return HttpResponseRedirect(
|
return HttpResponseRedirect(
|
||||||
reverse('datacenterlight:order_confirmation'))
|
reverse('datacenterlight:order_confirmation'))
|
||||||
else:
|
else:
|
||||||
|
@ -441,14 +443,7 @@ class OrderConfirmationView(DetailView):
|
||||||
return HttpResponseRedirect(reverse('datacenterlight:index'))
|
return HttpResponseRedirect(reverse('datacenterlight:index'))
|
||||||
if 'token' not in request.session:
|
if 'token' not in request.session:
|
||||||
return HttpResponseRedirect(reverse('datacenterlight:payment'))
|
return HttpResponseRedirect(reverse('datacenterlight:payment'))
|
||||||
stripe_customer_id = request.session.get('customer')
|
stripe_api_cus_id = request.session.get('customer')
|
||||||
if request.user.is_authenticated():
|
|
||||||
customer = StripeCustomer.objects.filter(
|
|
||||||
id=stripe_customer_id).first()
|
|
||||||
stripe_api_cus_id = customer.stripe_id
|
|
||||||
else:
|
|
||||||
stripe_api_cus_id = stripe_customer_id
|
|
||||||
|
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
card_details = stripe_utils.get_card_details(stripe_api_cus_id,
|
card_details = stripe_utils.get_card_details(stripe_api_cus_id,
|
||||||
request.session.get(
|
request.session.get(
|
||||||
|
@ -471,15 +466,8 @@ class OrderConfirmationView(DetailView):
|
||||||
template = request.session.get('template')
|
template = request.session.get('template')
|
||||||
specs = request.session.get('specs')
|
specs = request.session.get('specs')
|
||||||
user = request.session.get('user')
|
user = request.session.get('user')
|
||||||
stripe_customer_id = request.session.get('customer')
|
stripe_api_cus_id = request.session.get('customer')
|
||||||
if request.user.is_authenticated():
|
|
||||||
customer = StripeCustomer.objects.filter(
|
|
||||||
id=stripe_customer_id).first()
|
|
||||||
stripe_api_cus_id = customer.stripe_id
|
|
||||||
else:
|
|
||||||
stripe_api_cus_id = stripe_customer_id
|
|
||||||
vm_template_id = template.get('id', 1)
|
vm_template_id = template.get('id', 1)
|
||||||
|
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
card_details = stripe_utils.get_card_details(stripe_api_cus_id,
|
card_details = stripe_utils.get_card_details(stripe_api_cus_id,
|
||||||
request.session.get(
|
request.session.get(
|
||||||
|
@ -537,7 +525,7 @@ class OrderConfirmationView(DetailView):
|
||||||
'msg_title': str(_('Error.')),
|
'msg_title': str(_('Error.')),
|
||||||
'msg_body': str(
|
'msg_body': str(
|
||||||
_('There was a payment related error.<br/>'
|
_('There was a payment related error.<br/>'
|
||||||
'Details: {error_detail}<br/>'
|
'Details: {error_detail}<br/>'
|
||||||
'On close of this popup, you will be redirected back to'
|
'On close of this popup, you will be redirected back to'
|
||||||
' the payment page.'.format(error_detail=msg)))
|
' the payment page.'.format(error_detail=msg)))
|
||||||
}
|
}
|
||||||
|
@ -573,10 +561,10 @@ class OrderConfirmationView(DetailView):
|
||||||
password=password)
|
password=password)
|
||||||
login(request, new_user)
|
login(request, new_user)
|
||||||
else:
|
else:
|
||||||
customer = StripeCustomer.objects.filter(
|
# We assume that if the user is here, his/her StripeCustomer
|
||||||
id=stripe_customer_id).first()
|
# object already exists
|
||||||
custom_user = customer.user
|
stripe_customer_id = request.user.stripecustomer.id
|
||||||
stripe_customer_id = customer.id
|
custom_user = request.user
|
||||||
|
|
||||||
# Save billing address
|
# Save billing address
|
||||||
billing_address_data = request.session.get('billing_address_data')
|
billing_address_data = request.session.get('billing_address_data')
|
||||||
|
|
Loading…
Reference in a new issue