hosting view fix

This commit is contained in:
Arvind Tiwari 2017-09-21 17:22:02 +05:30
parent 5d8fb71215
commit a792911dea
2 changed files with 28 additions and 23 deletions

View file

@ -4,7 +4,7 @@
{% load custom_tags %} {% load custom_tags %}
{% block content %} {% block content %}
{{order.pk}}
<div id="order-detail{{order.pk}}" class="order-detail-container"> <div id="order-detail{{order.pk}}" class="order-detail-container">
{% if messages %} {% if messages %}
<div class="alert alert-warning"> <div class="alert alert-warning">
@ -25,10 +25,10 @@
</div> </div>
<div class="order-details"> <div class="order-details">
{% if order %} {% if order %}
{% endif %}
<p> <p>
<strong>{% trans "Order #" %} {{order.id}}</strong> <strong>{% trans "Order #" %} {{order.id}}</strong>
</p> </p>
{% endif %}
<p> <p>
<strong>{% trans "Invoice Date" %}:</strong> <strong>{% trans "Invoice Date" %}:</strong>
<span id="order-created_at"> <span id="order-created_at">
@ -40,18 +40,17 @@
</span> </span>
</p> </p>
{% if order %} {% if order %}
<p>
<strong>{% trans "Status" %}: </strong>
<strong>
{% if order.status == 'Approved' %}
<span class="vm-color-online">{% trans "Approved" %}</span>
{% else %}
<span class="vm-status-failed">{% trans "Declined" %}</span>
{% endif %}
</strong>
</p>
{% endif %} {% endif %}
<p>
<strong>{% trans "Status" %}: </strong>
<strong>
{% if order.status == 'Approved' %}
<span class="vm-color-online">{% trans "Approved" %}</span>
{% else %}
<span class="vm-status-failed">{% trans "Declined" %}</span>
{% endif %}
</strong>
</p>
<hr> <hr>
<div> <div>
<address> <address>

View file

@ -655,10 +655,13 @@ class OrdersHostingDetailView(LoginRequiredMixin,
stripe_customer_id = self.request.session.get('customer') stripe_customer_id = self.request.session.get('customer')
customer = StripeCustomer.objects.filter(id=stripe_customer_id).first() customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
stripe_utils = StripeUtils() stripe_utils = StripeUtils()
card_details = stripe_utils.get_card_details( if customer:
customer.stripe_id, card_details = stripe_utils.get_card_details(
self.request.session.get('token') customer.stripe_id,
) self.request.session.get('token')
)
else:
card_details = None
if self.request.GET.get('page') == 'payment': if self.request.GET.get('page') == 'payment':
context['page_header_text'] = _('Confirm Order') context['page_header_text'] = _('Confirm Order')
@ -666,6 +669,7 @@ class OrdersHostingDetailView(LoginRequiredMixin,
context['page_header_text'] = _('Invoice') context['page_header_text'] = _('Invoice')
if obj is not None: if obj is not None:
# invoice for previous order
try: try:
manager = OpenNebulaManager( manager = OpenNebulaManager(
email=owner.email, password=owner.password email=owner.email, password=owner.password
@ -686,9 +690,11 @@ class OrdersHostingDetailView(LoginRequiredMixin,
'In order to create a VM, you need to create/upload your SSH KEY first.' 'In order to create a VM, you need to create/upload your SSH KEY first.'
) )
elif not card_details.get('response_object'): elif not card_details.get('response_object'):
# new order, failed to get card details
context['failed_payment'] = True context['failed_payment'] = True
context['card_details'] = card_details context['card_details'] = card_details
else: else:
# new order, confirm payment
context['site_url'] = reverse('hosting:create_virtual_machine') context['site_url'] = reverse('hosting:create_virtual_machine')
context['cc_last4'] = card_details.get('response_object').get( context['cc_last4'] = card_details.get('response_object').get(
'last4') 'last4')
@ -698,12 +704,12 @@ class OrdersHostingDetailView(LoginRequiredMixin,
return context return context
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if 'specs' not in self.request.session: # if 'specs' not in self.request.session:
return HttpResponseRedirect( # return HttpResponseRedirect(
reverse('hosting:create_virtual_machine') # reverse('hosting:create_virtual_machine')
) # )
if 'token' not in self.request.session: # if 'token' not in self.request.session:
return HttpResponseRedirect(reverse('hosting:payment')) # return HttpResponseRedirect(reverse('hosting:payment'))
self.object = self.get_object() self.object = self.get_object()
context = self.get_context_data(object=self.object) context = self.get_context_data(object=self.object)
if 'failed_payment' in context: if 'failed_payment' in context: