Merged master into task/3622/decouple_opennebula_dcl_flow
This commit is contained in:
		
				commit
				
					
						6b7ae88f74
					
				
			
		
					 19 changed files with 296 additions and 142 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,7 @@ from .forms import BetaAccessForm
 | 
			
		|||
from .models import BetaAccess, BetaAccessVMType, BetaAccessVM, VMTemplate
 | 
			
		||||
from django.contrib import messages
 | 
			
		||||
from django.core.urlresolvers import reverse
 | 
			
		||||
from django.core.mail import EmailMessage
 | 
			
		||||
from utils.mailer import BaseEmail
 | 
			
		||||
from django.shortcuts import render
 | 
			
		||||
from django.shortcuts import redirect
 | 
			
		||||
| 
						 | 
				
			
			@ -12,12 +13,14 @@ from django.core.exceptions import ValidationError
 | 
			
		|||
from django.views.decorators.cache import cache_control
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.utils.translation import ugettext_lazy as _
 | 
			
		||||
from utils.forms import BillingAddressForm
 | 
			
		||||
from hosting.models import HostingOrder
 | 
			
		||||
from utils.forms import BillingAddressForm, UserBillingAddressForm
 | 
			
		||||
from utils.models import BillingAddress
 | 
			
		||||
from hosting.models import HostingOrder, HostingBill
 | 
			
		||||
from utils.stripe_utils import StripeUtils
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
from membership.models import CustomUser, StripeCustomer
 | 
			
		||||
from opennebula_api.models import OpenNebulaManager
 | 
			
		||||
from opennebula_api.serializers import VirtualMachineTemplateSerializer, VMTemplateSerializer
 | 
			
		||||
from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer, VMTemplateSerializer
 | 
			
		||||
from datacenterlight.tasks import create_vm_task
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -423,6 +426,10 @@ class OrderConfirmationView(DetailView):
 | 
			
		|||
        customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
 | 
			
		||||
        stripe_utils = StripeUtils()
 | 
			
		||||
        card_details = stripe_utils.get_card_details(customer.stripe_id, request.session.get('token'))
 | 
			
		||||
        if not card_details.get('response_object') and not card_details.get('paid'):
 | 
			
		||||
            msg = card_details.get('error')
 | 
			
		||||
            messages.add_message(self.request, messages.ERROR, msg, extra_tags='failed_payment')
 | 
			
		||||
            return HttpResponseRedirect(reverse('datacenterlight:payment') + '#payment_error')
 | 
			
		||||
        context = {
 | 
			
		||||
            'site_url': reverse('datacenterlight:index'),
 | 
			
		||||
            'cc_last4': card_details.get('response_object').get('last4'),
 | 
			
		||||
| 
						 | 
				
			
			@ -438,6 +445,8 @@ class OrderConfirmationView(DetailView):
 | 
			
		|||
        customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
 | 
			
		||||
        billing_address_data = request.session.get('billing_address_data')
 | 
			
		||||
        billing_address_id = request.session.get('billing_address')
 | 
			
		||||
        billing_address = BillingAddress.objects.filter(
 | 
			
		||||
            id=billing_address_id).first()
 | 
			
		||||
        vm_template_id = template.get('id', 1)
 | 
			
		||||
        final_price = specs.get('price')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -445,15 +454,12 @@ class OrderConfirmationView(DetailView):
 | 
			
		|||
        stripe_utils = StripeUtils()
 | 
			
		||||
        charge_response = stripe_utils.make_charge(amount=final_price,
 | 
			
		||||
                                                   customer=customer.stripe_id)
 | 
			
		||||
        charge = charge_response.get('response_object')
 | 
			
		||||
 | 
			
		||||
        # Check if the payment was approved
 | 
			
		||||
        if not charge:
 | 
			
		||||
            context = {}
 | 
			
		||||
            context.update({
 | 
			
		||||
                'paymentError': charge_response.get('error')
 | 
			
		||||
            })
 | 
			
		||||
            return render(request, self.payment_template_name, context)
 | 
			
		||||
        if not charge_response.get('response_object') and not charge_response.get('paid'):
 | 
			
		||||
            msg = charge_response.get('error')
 | 
			
		||||
            messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error')
 | 
			
		||||
            return HttpResponseRedirect(reverse('datacenterlight:payment') + '#payment_error')
 | 
			
		||||
 | 
			
		||||
        charge = charge_response.get('response_object')
 | 
			
		||||
        create_vm_task.delay(vm_template_id, user, specs, template, stripe_customer_id, billing_address_data,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue