| 
									
										
										
										
											2018-02-20 15:06:24 +01:00
										 |  |  | import logging | 
					
						
							| 
									
										
										
										
											2017-09-21 14:29:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  | from django import forms | 
					
						
							|  |  |  | from django.conf import settings | 
					
						
							| 
									
										
										
										
											2016-12-20 18:05:20 -05:00
										 |  |  | from django.contrib import messages | 
					
						
							| 
									
										
										
										
											2017-09-09 02:10:25 +05:30
										 |  |  | from django.contrib.auth import login, authenticate | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  | from django.core.exceptions import ValidationError | 
					
						
							| 
									
										
										
										
											2017-06-29 17:34:40 +03:00
										 |  |  | from django.core.urlresolvers import reverse | 
					
						
							| 
									
										
										
										
											2018-10-02 10:02:02 +02:00
										 |  |  | from django.http import HttpResponseRedirect, JsonResponse, Http404 | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  | from django.shortcuts import render | 
					
						
							| 
									
										
										
										
											2017-09-22 12:38:05 +02:00
										 |  |  | from django.utils.translation import get_language, ugettext_lazy as _ | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  | from django.views.decorators.cache import cache_control | 
					
						
							| 
									
										
										
										
											2018-02-23 19:05:45 +05:30
										 |  |  | from django.views.generic import FormView, CreateView, DetailView | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 08:19:29 +02:00
										 |  |  | from hosting.forms import ( | 
					
						
							| 
									
										
										
										
											2019-06-24 04:32:27 +02:00
										 |  |  |     HostingUserLoginForm, GenericPaymentForm, ProductPaymentForm, | 
					
						
							|  |  |  |     UserHostingKeyForm | 
					
						
							| 
									
										
										
										
											2018-10-03 08:19:29 +02:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2018-09-25 02:12:38 +02:00
										 |  |  | from hosting.models import ( | 
					
						
							| 
									
										
										
										
											2019-07-01 23:09:42 +05:30
										 |  |  |     HostingBill, HostingOrder, UserCardDetail, GenericProduct, UserHostingKey | 
					
						
							| 
									
										
										
										
											2018-09-25 02:12:38 +02:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-06-30 12:27:18 +05:30
										 |  |  | from membership.models import CustomUser, StripeCustomer | 
					
						
							| 
									
										
										
										
											2019-07-01 23:09:42 +05:30
										 |  |  | from opennebula_api.models import OpenNebulaManager | 
					
						
							| 
									
										
										
										
											2017-09-23 21:24:42 +05:30
										 |  |  | from opennebula_api.serializers import VMTemplateSerializer | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  | from utils.forms import ( | 
					
						
							|  |  |  |     BillingAddressForm, BillingAddressFormSignup, UserBillingAddressForm, | 
					
						
							|  |  |  |     BillingAddress | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2019-11-15 11:58:15 +05:30
										 |  |  | from utils.hosting_utils import ( | 
					
						
							| 
									
										
										
										
											2019-12-07 19:26:21 +05:30
										 |  |  |     get_vm_price_with_vat, get_all_public_keys, get_vat_rate_for_country, | 
					
						
							|  |  |  |     get_vm_price_for_given_vat | 
					
						
							| 
									
										
										
										
											2019-11-15 11:58:15 +05:30
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  | from utils.stripe_utils import StripeUtils | 
					
						
							| 
									
										
										
										
											2017-08-27 15:23:19 +05:30
										 |  |  | from utils.tasks import send_plain_email_task | 
					
						
							| 
									
										
										
										
											2018-10-01 07:52:17 +02:00
										 |  |  | from .cms_models import DCLCalculatorPluginModel | 
					
						
							| 
									
										
										
										
											2018-02-20 15:06:24 +01:00
										 |  |  | from .forms import ContactForm | 
					
						
							| 
									
										
										
										
											2018-04-15 21:03:31 +02:00
										 |  |  | from .models import VMTemplate, VMPricing | 
					
						
							| 
									
										
										
										
											2019-12-25 20:11:15 +05:30
										 |  |  | from .utils import ( | 
					
						
							|  |  |  |     get_cms_integration, create_vm, clear_all_session_vars, validate_vat_number | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-04-24 03:01:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 14:29:49 +02:00
										 |  |  | logger = logging.getLogger(__name__) | 
					
						
							| 
									
										
										
										
											2017-07-03 23:53:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 11:45:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 13:19:05 +05:30
										 |  |  | class ContactUsView(FormView): | 
					
						
							|  |  |  |     template_name = "datacenterlight/contact_form.html" | 
					
						
							|  |  |  |     form_class = ContactForm | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def get(self, request, *args, **kwargs): | 
					
						
							|  |  |  |         return HttpResponseRedirect(reverse('datacenterlight:index')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def form_invalid(self, form): | 
					
						
							|  |  |  |         if self.request.is_ajax(): | 
					
						
							|  |  |  |             return self.render_to_response( | 
					
						
							|  |  |  |                 self.get_context_data(contact_form=form)) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2018-03-27 19:19:26 +05:30
										 |  |  |             return render( | 
					
						
							|  |  |  |                 self.request, 'datacenterlight/index.html', | 
					
						
							|  |  |  |                 self.get_context_data(contact_form=form) | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-08-27 13:19:05 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     def form_valid(self, form): | 
					
						
							|  |  |  |         form.save() | 
					
						
							| 
									
										
										
										
											2017-10-11 00:36:17 +05:30
										 |  |  |         from_emails = { | 
					
						
							|  |  |  |             'glasfaser': 'glasfaser@ungleich.ch' | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         from_page = self.request.POST.get('from_page') | 
					
						
							| 
									
										
										
										
											2017-08-27 15:23:19 +05:30
										 |  |  |         email_data = { | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  |             'subject': "{dcl_text} Message from {sender}".format( | 
					
						
							|  |  |  |                 dcl_text=settings.DCL_TEXT, | 
					
						
							|  |  |  |                 sender=form.cleaned_data.get('email') | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2017-08-27 15:23:19 +05:30
										 |  |  |             'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, | 
					
						
							| 
									
										
										
										
											2018-11-11 17:01:19 +01:00
										 |  |  |             'to': [from_emails.get(from_page, 'support@ungleich.ch')], | 
					
						
							| 
									
										
										
										
											2017-08-27 15:23:19 +05:30
										 |  |  |             'body': "\n".join( | 
					
						
							|  |  |  |                 ["%s=%s" % (k, v) for (k, v) in form.cleaned_data.items()]), | 
					
						
							|  |  |  |             'reply_to': [form.cleaned_data.get('email')], | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         send_plain_email_task.delay(email_data) | 
					
						
							| 
									
										
										
										
											2017-08-27 13:19:05 +05:30
										 |  |  |         if self.request.is_ajax(): | 
					
						
							|  |  |  |             return self.render_to_response( | 
					
						
							|  |  |  |                 self.get_context_data(success=True, contact_form=form)) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2018-03-27 19:19:26 +05:30
										 |  |  |             return render( | 
					
						
							|  |  |  |                 self.request, 'datacenterlight/index.html', | 
					
						
							|  |  |  |                 self.get_context_data(success=True, contact_form=form) | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-04-24 03:01:05 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 23:53:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-20 18:05:20 -05:00
										 |  |  | class IndexView(CreateView): | 
					
						
							|  |  |  |     template_name = "datacenterlight/index.html" | 
					
						
							|  |  |  |     success_url = "/datacenterlight#requestform" | 
					
						
							|  |  |  |     success_message = "Thank you, we will contact you as soon as possible" | 
					
						
							| 
									
										
										
										
											2017-06-29 17:34:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  |     def validate_cores(self, value): | 
					
						
							|  |  |  |         if (value > 48) or (value < 1): | 
					
						
							| 
									
										
										
										
											2017-08-01 00:01:19 +05:30
										 |  |  |             raise ValidationError(_('Invalid number of cores')) | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def validate_memory(self, value): | 
					
						
							| 
									
										
										
										
											2018-10-01 07:52:17 +02:00
										 |  |  |         if 'pid' in self.request.POST: | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 plugin = DCLCalculatorPluginModel.objects.get( | 
					
						
							|  |  |  |                              id=self.request.POST['pid'] | 
					
						
							|  |  |  |                          ) | 
					
						
							|  |  |  |             except DCLCalculatorPluginModel.DoesNotExist as dne: | 
					
						
							|  |  |  |                 logger.error( | 
					
						
							|  |  |  |                     str(dne) + " plugin_id: " + self.request.POST['pid'] | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 raise ValidationError(_('Invalid calculator properties')) | 
					
						
							|  |  |  |             if plugin.enable_512mb_ram: | 
					
						
							|  |  |  |                 if value % 1 == 0 or value == 0.5: | 
					
						
							|  |  |  |                     logger.debug( | 
					
						
							|  |  |  |                         "Given ram {value} is either 0.5 or a" | 
					
						
							|  |  |  |                         " whole number".format(value=value) | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     if (value > 200) or (value < 0.5): | 
					
						
							|  |  |  |                         raise ValidationError(_('Invalid RAM size')) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     raise ValidationError(_('Invalid RAM size')) | 
					
						
							|  |  |  |             elif (value > 200) or (value < 1) or (value % 1 != 0): | 
					
						
							|  |  |  |                 raise ValidationError(_('Invalid RAM size')) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2017-08-01 00:01:19 +05:30
										 |  |  |             raise ValidationError(_('Invalid RAM size')) | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def validate_storage(self, value): | 
					
						
							|  |  |  |         if (value > 2000) or (value < 10): | 
					
						
							| 
									
										
										
										
											2017-08-01 00:01:19 +05:30
										 |  |  |             raise ValidationError(_('Invalid storage size')) | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |     @cache_control(no_cache=True, must_revalidate=True, no_store=True) | 
					
						
							| 
									
										
										
										
											2017-06-11 16:32:38 +05:30
										 |  |  |     def get(self, request, *args, **kwargs): | 
					
						
							| 
									
										
										
										
											2018-10-05 11:01:49 +02:00
										 |  |  |         clear_all_session_vars(request) | 
					
						
							| 
									
										
										
										
											2018-03-22 03:30:43 +05:30
										 |  |  |         return HttpResponseRedirect(reverse('datacenterlight:cms_index')) | 
					
						
							| 
									
										
										
										
											2017-06-11 16:32:38 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     def post(self, request): | 
					
						
							|  |  |  |         cores = request.POST.get('cpu') | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  |         cores_field = forms.IntegerField(validators=[self.validate_cores]) | 
					
						
							| 
									
										
										
										
											2017-06-11 16:32:38 +05:30
										 |  |  |         memory = request.POST.get('ram') | 
					
						
							| 
									
										
										
										
											2018-10-01 07:52:17 +02:00
										 |  |  |         memory_field = forms.FloatField(validators=[self.validate_memory]) | 
					
						
							| 
									
										
										
										
											2017-06-11 16:32:38 +05:30
										 |  |  |         storage = request.POST.get('storage') | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  |         storage_field = forms.IntegerField(validators=[self.validate_storage]) | 
					
						
							| 
									
										
										
										
											2017-06-11 16:32:38 +05:30
										 |  |  |         template_id = int(request.POST.get('config')) | 
					
						
							| 
									
										
										
										
											2018-04-15 21:03:31 +02:00
										 |  |  |         pricing_name = request.POST.get('pricing_name') | 
					
						
							|  |  |  |         vm_pricing = VMPricing.get_vm_pricing_by_name(pricing_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-03 22:00:41 +05:30
										 |  |  |         template = VMTemplate.objects.filter( | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |             opennebula_vm_template_id=template_id | 
					
						
							|  |  |  |         ).first() | 
					
						
							| 
									
										
										
										
											2017-07-27 12:05:01 +05:30
										 |  |  |         template_data = VMTemplateSerializer(template).data | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |         referer_url = request.META['HTTP_REFERER'] | 
					
						
							| 
									
										
										
										
											2017-06-29 17:34:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-15 21:03:31 +02:00
										 |  |  |         if vm_pricing is None: | 
					
						
							|  |  |  |             vm_pricing_name_msg = _( | 
					
						
							|  |  |  |                 "Incorrect pricing name. Please contact support" | 
					
						
							|  |  |  |                 "{support_email}".format( | 
					
						
							|  |  |  |                     support_email=settings.DCL_SUPPORT_FROM_ADDRESS | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             messages.add_message( | 
					
						
							|  |  |  |                 self.request, messages.ERROR, vm_pricing_name_msg, | 
					
						
							|  |  |  |                 extra_tags='pricing' | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             return HttpResponseRedirect(referer_url + "#order_form") | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             vm_pricing_name = vm_pricing.name | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  |         try: | 
					
						
							|  |  |  |             cores = cores_field.clean(cores) | 
					
						
							|  |  |  |         except ValidationError as err: | 
					
						
							| 
									
										
										
										
											2017-07-26 01:55:31 +05:30
										 |  |  |             msg = '{} : {}.'.format(cores, str(err)) | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |             messages.add_message( | 
					
						
							|  |  |  |                 self.request, messages.ERROR, msg, extra_tags='cores' | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             return HttpResponseRedirect(referer_url + "#order_form") | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             memory = memory_field.clean(memory) | 
					
						
							|  |  |  |         except ValidationError as err: | 
					
						
							| 
									
										
										
										
											2017-07-26 01:55:31 +05:30
										 |  |  |             msg = '{} : {}.'.format(memory, str(err)) | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |             messages.add_message( | 
					
						
							|  |  |  |                 self.request, messages.ERROR, msg, extra_tags='memory' | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             return HttpResponseRedirect(referer_url + "#order_form") | 
					
						
							| 
									
										
										
										
											2017-07-14 11:34:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             storage = storage_field.clean(storage) | 
					
						
							|  |  |  |         except ValidationError as err: | 
					
						
							| 
									
										
										
										
											2017-07-26 01:55:31 +05:30
										 |  |  |             msg = '{} : {}.'.format(storage, str(err)) | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |             messages.add_message( | 
					
						
							|  |  |  |                 self.request, messages.ERROR, msg, extra_tags='storage' | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             return HttpResponseRedirect(referer_url + "#order_form") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 06:11:44 +05:30
										 |  |  |         price, vat, vat_percent, discount = get_vm_price_with_vat( | 
					
						
							| 
									
										
										
										
											2018-04-15 13:42:39 +02:00
										 |  |  |             cpu=cores, | 
					
						
							|  |  |  |             memory=memory, | 
					
						
							| 
									
										
										
										
											2018-04-16 03:26:51 +02:00
										 |  |  |             ssd_size=storage, | 
					
						
							| 
									
										
										
										
											2018-04-15 13:42:39 +02:00
										 |  |  |             pricing_name=vm_pricing_name | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |         specs = { | 
					
						
							|  |  |  |             'cpu': cores, | 
					
						
							| 
									
										
										
										
											2017-06-11 16:32:38 +05:30
										 |  |  |             'memory': memory, | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |             'disk_size': storage, | 
					
						
							| 
									
										
										
										
											2018-04-16 01:31:16 +02:00
										 |  |  |             'price': price, | 
					
						
							| 
									
										
										
										
											2018-04-15 21:03:31 +02:00
										 |  |  |             'vat': vat, | 
					
						
							| 
									
										
										
										
											2018-04-17 21:38:28 +02:00
										 |  |  |             'vat_percent': vat_percent, | 
					
						
							| 
									
										
										
										
											2018-05-07 06:11:44 +05:30
										 |  |  |             'discount': discount, | 
					
						
							| 
									
										
										
										
											2018-10-18 06:58:18 +02:00
										 |  |  |             'total_price': round(price + vat - discount['amount'], 2), | 
					
						
							| 
									
										
										
										
											2018-04-15 21:03:31 +02:00
										 |  |  |             'pricing_name': vm_pricing_name | 
					
						
							| 
									
										
										
										
											2017-06-11 16:32:38 +05:30
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |         request.session['specs'] = specs | 
					
						
							|  |  |  |         request.session['template'] = template_data | 
					
						
							|  |  |  |         return HttpResponseRedirect(reverse('datacenterlight:payment')) | 
					
						
							| 
									
										
										
										
											2016-12-20 18:05:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-21 01:24:04 -05:00
										 |  |  |     def get_success_url(self): | 
					
						
							|  |  |  |         success_url = reverse('datacenterlight:index') | 
					
						
							|  |  |  |         success_url += "#requestform" | 
					
						
							|  |  |  |         return success_url | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-24 03:01:05 +05:30
										 |  |  |     def get_context_data(self, **kwargs): | 
					
						
							|  |  |  |         context = super(IndexView, self).get_context_data(**kwargs) | 
					
						
							|  |  |  |         context.update({ | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |             'base_url': "{0}://{1}".format( | 
					
						
							|  |  |  |                 self.request.scheme, self.request.get_host() | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2017-08-27 13:19:05 +05:30
										 |  |  |             'contact_form': ContactForm | 
					
						
							| 
									
										
										
										
											2017-04-24 03:01:05 +05:30
										 |  |  |         }) | 
					
						
							|  |  |  |         return context | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-07 01:20:16 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-29 13:14:13 +05:30
										 |  |  | class WhyDataCenterLightView(IndexView): | 
					
						
							|  |  |  |     template_name = "datacenterlight/whydatacenterlight.html" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | class PaymentOrderView(FormView): | 
					
						
							| 
									
										
										
										
											2017-09-01 23:06:57 +05:30
										 |  |  |     template_name = 'datacenterlight/landing_payment.html' | 
					
						
							| 
									
										
										
										
											2017-09-08 23:46:29 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     def get_form_class(self): | 
					
						
							|  |  |  |         if self.request.user.is_authenticated(): | 
					
						
							|  |  |  |             return BillingAddressForm | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             return BillingAddressFormSignup | 
					
						
							| 
									
										
										
										
											2017-07-01 15:53:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |     def get_context_data(self, **kwargs): | 
					
						
							|  |  |  |         context = super(PaymentOrderView, self).get_context_data(**kwargs) | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |         if 'billing_address_data' in self.request.session: | 
					
						
							|  |  |  |             billing_address_data = self.request.session['billing_address_data'] | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             billing_address_data = {} | 
					
						
							| 
									
										
										
										
											2017-10-08 17:21:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if self.request.user.is_authenticated(): | 
					
						
							|  |  |  |             if billing_address_data: | 
					
						
							|  |  |  |                 billing_address_form = BillingAddressForm( | 
					
						
							|  |  |  |                     initial=billing_address_data | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 billing_address_form = BillingAddressForm( | 
					
						
							| 
									
										
										
										
											2017-10-08 19:24:58 +02:00
										 |  |  |                     instance=self.request.user.billing_addresses.first() | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2018-07-04 00:50:44 +02:00
										 |  |  |             user = self.request.user | 
					
						
							|  |  |  |             if hasattr(user, 'stripecustomer'): | 
					
						
							|  |  |  |                 stripe_customer = user.stripecustomer | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 stripe_customer = None | 
					
						
							|  |  |  |             cards_list = UserCardDetail.get_all_cards_list( | 
					
						
							|  |  |  |                 stripe_customer=stripe_customer | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             context.update({'cards_list': cards_list}) | 
					
						
							| 
									
										
										
										
											2017-10-08 17:29:10 +02:00
										 |  |  |         else: | 
					
						
							|  |  |  |             billing_address_form = BillingAddressFormSignup( | 
					
						
							|  |  |  |                 initial=billing_address_data | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-10-08 17:21:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |         context.update({ | 
					
						
							| 
									
										
										
										
											2017-07-01 04:29:11 +05:30
										 |  |  |             'stripe_key': settings.STRIPE_API_PUBLIC_KEY, | 
					
						
							| 
									
										
										
										
											2017-09-06 00:12:13 +05:30
										 |  |  |             'site_url': reverse('datacenterlight:index'), | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |             'login_form': HostingUserLoginForm(prefix='login_form'), | 
					
						
							| 
									
										
										
										
											2018-03-27 19:19:26 +05:30
										 |  |  |             'billing_address_form': billing_address_form, | 
					
						
							| 
									
										
										
										
											2018-04-15 21:03:31 +02:00
										 |  |  |             'cms_integration': get_cms_integration('default'), | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-09-22 08:20:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |         if ('generic_payment_type' in self.request.session and | 
					
						
							|  |  |  |                 self.request.session['generic_payment_type'] == 'generic'): | 
					
						
							| 
									
										
										
										
											2018-10-03 08:19:29 +02:00
										 |  |  |             if 'product_id' in self.request.session: | 
					
						
							|  |  |  |                 product = GenericProduct.objects.get( | 
					
						
							|  |  |  |                     id=self.request.session['product_id'] | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 context.update({'generic_payment_form': ProductPaymentForm( | 
					
						
							|  |  |  |                     prefix='generic_payment_form', | 
					
						
							|  |  |  |                     initial={'product_name': product.product_name, | 
					
						
							|  |  |  |                              'amount': float(product.get_actual_price()), | 
					
						
							|  |  |  |                              'recurring': product.product_is_subscription, | 
					
						
							|  |  |  |                              'description': product.product_description, | 
					
						
							| 
									
										
										
										
											2018-10-03 22:53:24 +02:00
										 |  |  |                              }, | 
					
						
							|  |  |  |                     product_id=product.id | 
					
						
							| 
									
										
										
										
											2018-10-03 08:19:29 +02:00
										 |  |  |                 ), }) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 context.update({'generic_payment_form': GenericPaymentForm( | 
					
						
							|  |  |  |                     prefix='generic_payment_form', | 
					
						
							|  |  |  |                 ), }) | 
					
						
							| 
									
										
										
										
											2018-09-22 08:20:49 +02:00
										 |  |  |         else: | 
					
						
							|  |  |  |             context.update({ | 
					
						
							|  |  |  |                 'vm_pricing': VMPricing.get_vm_pricing_by_name( | 
					
						
							|  |  |  |                     self.request.session['specs']['pricing_name'] | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |         return context | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @cache_control(no_cache=True, must_revalidate=True, no_store=True) | 
					
						
							|  |  |  |     def get(self, request, *args, **kwargs): | 
					
						
							| 
									
										
										
										
											2018-10-03 07:55:56 +02:00
										 |  |  |         if (('type' in request.GET and request.GET['type'] == 'generic') | 
					
						
							|  |  |  |                 or 'product_slug' in kwargs): | 
					
						
							|  |  |  |             request.session['generic_payment_type'] = 'generic' | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             if 'generic_payment_details' in request.session: | 
					
						
							|  |  |  |                 request.session.pop('generic_payment_details') | 
					
						
							| 
									
										
										
										
											2018-10-03 09:36:00 +02:00
										 |  |  |                 request.session.pop('product_id') | 
					
						
							| 
									
										
										
										
											2018-10-02 10:02:02 +02:00
										 |  |  |             if 'product_slug' in kwargs: | 
					
						
							|  |  |  |                 logger.debug("Product slug is " + kwargs['product_slug']) | 
					
						
							|  |  |  |                 try: | 
					
						
							|  |  |  |                     product = GenericProduct.objects.get( | 
					
						
							|  |  |  |                         product_slug=kwargs['product_slug'] | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 except GenericProduct.DoesNotExist as dne: | 
					
						
							|  |  |  |                     logger.error( | 
					
						
							|  |  |  |                         "Product '{}' does " | 
					
						
							|  |  |  |                         "not exist".format(kwargs['product_slug']) | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     raise Http404() | 
					
						
							|  |  |  |                 request.session['product_id'] = product.id | 
					
						
							| 
									
										
										
										
											2018-09-22 08:20:49 +02:00
										 |  |  |         elif 'specs' not in request.session: | 
					
						
							| 
									
										
										
										
											2017-09-08 23:46:29 +05:30
										 |  |  |             return HttpResponseRedirect(reverse('datacenterlight:index')) | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |         return self.render_to_response(self.get_context_data()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def post(self, request, *args, **kwargs): | 
					
						
							| 
									
										
										
										
											2018-09-25 02:12:38 +02:00
										 |  |  |         if 'product' in request.POST: | 
					
						
							|  |  |  |             # query for the supplied product | 
					
						
							|  |  |  |             product = None | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 product = GenericProduct.objects.get( | 
					
						
							| 
									
										
										
										
											2018-09-26 09:15:24 +02:00
										 |  |  |                     id=request.POST['generic_payment_form-product_name'] | 
					
						
							| 
									
										
										
										
											2018-09-25 02:12:38 +02:00
										 |  |  |                 ) | 
					
						
							|  |  |  |             except GenericProduct.DoesNotExist as dne: | 
					
						
							|  |  |  |                 logger.error( | 
					
						
							|  |  |  |                     "The requested product '{}' does not exist".format( | 
					
						
							|  |  |  |                         request.POST['generic_payment_form-product_name'] | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             except GenericProduct.MultipleObjectsReturned as mpe: | 
					
						
							|  |  |  |                 logger.error( | 
					
						
							|  |  |  |                     "There seem to be more than one product with " | 
					
						
							|  |  |  |                     "the name {}".format( | 
					
						
							|  |  |  |                         request.POST['generic_payment_form-product_name'] | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 product = GenericProduct.objects.all( | 
					
						
							| 
									
										
										
										
											2018-09-26 21:23:46 +02:00
										 |  |  |                     product_name=request. | 
					
						
							|  |  |  |                     POST['generic_payment_form-product_name'] | 
					
						
							| 
									
										
										
										
											2018-09-25 02:12:38 +02:00
										 |  |  |                 ).first() | 
					
						
							|  |  |  |             if product is None: | 
					
						
							|  |  |  |                 return JsonResponse({}) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 return JsonResponse({ | 
					
						
							|  |  |  |                     'amount': product.get_actual_price(), | 
					
						
							|  |  |  |                     'isSubscription': product.product_is_subscription | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |         if 'login_form' in request.POST: | 
					
						
							| 
									
										
										
										
											2018-03-05 18:41:13 +05:30
										 |  |  |             login_form = HostingUserLoginForm( | 
					
						
							|  |  |  |                 data=request.POST, prefix='login_form' | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |             if login_form.is_valid(): | 
					
						
							|  |  |  |                 email = login_form.cleaned_data.get('email') | 
					
						
							|  |  |  |                 password = login_form.cleaned_data.get('password') | 
					
						
							|  |  |  |                 auth_user = authenticate(email=email, password=password) | 
					
						
							|  |  |  |                 if auth_user: | 
					
						
							|  |  |  |                     login(self.request, auth_user) | 
					
						
							| 
									
										
										
										
											2018-10-05 08:58:54 +02:00
										 |  |  |                     if 'product_slug' in kwargs: | 
					
						
							|  |  |  |                         return HttpResponseRedirect( | 
					
						
							|  |  |  |                             reverse('show_product', | 
					
						
							|  |  |  |                                     kwargs={ | 
					
						
							|  |  |  |                                         'product_slug': kwargs['product_slug']} | 
					
						
							|  |  |  |                                     ) | 
					
						
							|  |  |  |                         ) | 
					
						
							| 
									
										
										
										
											2017-10-12 22:50:54 +02:00
										 |  |  |                     return HttpResponseRedirect( | 
					
						
							|  |  |  |                         reverse('datacenterlight:payment') | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 context = self.get_context_data() | 
					
						
							|  |  |  |                 context['login_form'] = login_form | 
					
						
							|  |  |  |                 return self.render_to_response(context) | 
					
						
							|  |  |  |         if request.user.is_authenticated(): | 
					
						
							|  |  |  |             address_form = BillingAddressForm( | 
					
						
							|  |  |  |                 data=request.POST, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             address_form = BillingAddressFormSignup( | 
					
						
							|  |  |  |                 data=request.POST, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         if address_form.is_valid(): | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             # Check if we are in a generic payment case and handle the generic | 
					
						
							|  |  |  |             # payment details form before we go on to verify payment | 
					
						
							|  |  |  |             if ('generic_payment_type' in request.session and | 
					
						
							|  |  |  |                     self.request.session['generic_payment_type'] == 'generic'): | 
					
						
							| 
									
										
										
										
											2018-10-03 09:36:43 +02:00
										 |  |  |                 if 'product_id' in request.session: | 
					
						
							|  |  |  |                     generic_payment_form = ProductPaymentForm( | 
					
						
							|  |  |  |                         data=request.POST, prefix='generic_payment_form', | 
					
						
							|  |  |  |                         product_id=request.session['product_id'] | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     generic_payment_form = GenericPaymentForm( | 
					
						
							|  |  |  |                         data=request.POST, prefix='generic_payment_form' | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                 if generic_payment_form.is_valid(): | 
					
						
							|  |  |  |                     logger.debug("Generic payment form is valid.") | 
					
						
							| 
									
										
										
										
											2018-10-03 09:36:43 +02:00
										 |  |  |                     if 'product_id' in request.session: | 
					
						
							|  |  |  |                         product = generic_payment_form.product | 
					
						
							|  |  |  |                     else: | 
					
						
							|  |  |  |                         product = generic_payment_form.cleaned_data.get( | 
					
						
							|  |  |  |                             'product_name' | 
					
						
							|  |  |  |                         ) | 
					
						
							| 
									
										
										
										
											2019-11-15 13:11:11 +05:30
										 |  |  |                     user_country_vat_rate = get_vat_rate_for_country( | 
					
						
							|  |  |  |                         address_form.cleaned_data["country"] | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2018-09-25 02:13:39 +02:00
										 |  |  |                     gp_details = { | 
					
						
							| 
									
										
										
										
											2018-09-26 09:15:24 +02:00
										 |  |  |                         "product_name": product.product_name, | 
					
						
							| 
									
										
										
										
											2019-11-15 13:11:11 +05:30
										 |  |  |                         "vat_rate": user_country_vat_rate * 100, | 
					
						
							|  |  |  |                         "vat_amount": round( | 
					
						
							|  |  |  |                             float(product.product_price) * | 
					
						
							|  |  |  |                             user_country_vat_rate, 2), | 
					
						
							|  |  |  |                         "vat_country": address_form.cleaned_data["country"], | 
					
						
							|  |  |  |                         "amount_before_vat": round( | 
					
						
							|  |  |  |                             float(product.product_price), 2), | 
					
						
							| 
									
										
										
										
											2019-11-15 11:58:15 +05:30
										 |  |  |                         "amount": product.get_actual_price( | 
					
						
							| 
									
										
										
										
											2019-11-15 12:23:44 +05:30
										 |  |  |                             vat_rate=get_vat_rate_for_country( | 
					
						
							|  |  |  |                                 address_form.cleaned_data["country"]) | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                         ), | 
					
						
							|  |  |  |                         "recurring": generic_payment_form.cleaned_data.get( | 
					
						
							|  |  |  |                             'recurring' | 
					
						
							|  |  |  |                         ), | 
					
						
							|  |  |  |                         "description": generic_payment_form.cleaned_data.get( | 
					
						
							|  |  |  |                             'description' | 
					
						
							|  |  |  |                         ), | 
					
						
							| 
									
										
										
										
											2018-10-05 11:10:10 +02:00
										 |  |  |                         "product_id": product.id, | 
					
						
							| 
									
										
										
										
											2019-11-15 19:47:11 +05:30
										 |  |  |                         "product_slug": product.product_slug, | 
					
						
							|  |  |  |                         "recurring_interval": | 
					
						
							|  |  |  |                             product.product_subscription_interval | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  |                     request.session["generic_payment_details"] = ( | 
					
						
							| 
									
										
										
										
											2018-09-25 02:13:39 +02:00
										 |  |  |                         gp_details | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                     ) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     logger.debug("Generic payment form invalid") | 
					
						
							|  |  |  |                     context = self.get_context_data() | 
					
						
							|  |  |  |                     context['generic_payment_form'] = generic_payment_form | 
					
						
							|  |  |  |                     context['billing_address_form'] = address_form | 
					
						
							|  |  |  |                     return self.render_to_response(context) | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |             token = address_form.cleaned_data.get('token') | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |             if token is '': | 
					
						
							|  |  |  |                 card_id = address_form.cleaned_data.get('card') | 
					
						
							|  |  |  |                 try: | 
					
						
							|  |  |  |                     user_card_detail = UserCardDetail.objects.get(id=card_id) | 
					
						
							|  |  |  |                     if not request.user.has_perm( | 
					
						
							|  |  |  |                             'view_usercarddetail', user_card_detail | 
					
						
							|  |  |  |                     ): | 
					
						
							|  |  |  |                         raise UserCardDetail.DoesNotExist( | 
					
						
							|  |  |  |                             _("{user} does not have permission to access the " | 
					
						
							|  |  |  |                               "card").format(user=request.user.email) | 
					
						
							|  |  |  |                         ) | 
					
						
							|  |  |  |                 except UserCardDetail.DoesNotExist as e: | 
					
						
							|  |  |  |                     ex = str(e) | 
					
						
							|  |  |  |                     logger.error("Card Id: {card_id}, Exception: {ex}".format( | 
					
						
							| 
									
										
										
										
											2018-09-22 08:20:49 +02:00
										 |  |  |                         card_id=card_id, ex=ex | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |                     ) | 
					
						
							|  |  |  |                     msg = _("An error occurred. Details: {}".format(ex)) | 
					
						
							|  |  |  |                     messages.add_message( | 
					
						
							|  |  |  |                         self.request, messages.ERROR, msg, | 
					
						
							|  |  |  |                         extra_tags='make_charge_error' | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     return HttpResponseRedirect( | 
					
						
							|  |  |  |                         reverse('datacenterlight:payment') + '#payment_error' | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 request.session['card_id'] = user_card_detail.id | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 request.session['token'] = token | 
					
						
							| 
									
										
										
										
											2017-09-09 00:05:13 +05:30
										 |  |  |             if request.user.is_authenticated(): | 
					
						
							| 
									
										
										
										
											2017-09-09 02:10:25 +05:30
										 |  |  |                 this_user = { | 
					
						
							| 
									
										
										
										
											2017-09-09 00:05:13 +05:30
										 |  |  |                     'email': request.user.email, | 
					
						
							|  |  |  |                     'name': request.user.name | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |                 customer = StripeCustomer.get_or_create( | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |                     email=this_user.get('email'), token=token | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2017-09-09 00:05:13 +05:30
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |                 user_email = address_form.cleaned_data.get('email') | 
					
						
							|  |  |  |                 user_name = address_form.cleaned_data.get('name') | 
					
						
							| 
									
										
										
										
											2017-09-09 02:10:25 +05:30
										 |  |  |                 this_user = { | 
					
						
							| 
									
										
										
										
											2017-09-28 14:46:56 +02:00
										 |  |  |                     'email': user_email, | 
					
						
							|  |  |  |                     'name': user_name | 
					
						
							| 
									
										
										
										
											2017-09-09 00:05:13 +05:30
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-09-28 14:46:56 +02:00
										 |  |  |                 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( | 
					
						
							|  |  |  |                             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) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 10:54:26 +05:30
										 |  |  |             billing_address = address_form.save() | 
					
						
							|  |  |  |             request.session["billing_address_id"] = billing_address.id | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |             request.session['billing_address_data'] = address_form.cleaned_data | 
					
						
							| 
									
										
										
										
											2017-09-09 02:10:25 +05:30
										 |  |  |             request.session['user'] = this_user | 
					
						
							| 
									
										
										
										
											2017-06-22 13:21:07 +05:30
										 |  |  |             # Get or create stripe customer | 
					
						
							|  |  |  |             if not customer: | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |                 address_form.add_error( | 
					
						
							|  |  |  |                     "__all__", "Invalid credit card" | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2017-08-30 10:04:19 +02:00
										 |  |  |                 return self.render_to_response( | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |                     self.get_context_data( | 
					
						
							|  |  |  |                         billing_address_form=address_form | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2017-09-28 15:56:09 +02:00
										 |  |  |             if type(customer) is StripeCustomer: | 
					
						
							|  |  |  |                 request.session['customer'] = customer.stripe_id | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 request.session['customer'] = customer | 
					
						
							| 
									
										
										
										
											2019-07-01 08:57:39 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-25 22:40:57 +05:30
										 |  |  |             vat_number = address_form.cleaned_data.get('vat_number').strip() | 
					
						
							|  |  |  |             if vat_number: | 
					
						
							|  |  |  |                 validate_result = validate_vat_number( | 
					
						
							|  |  |  |                     stripe_customer_id=request.session['customer'], | 
					
						
							| 
									
										
										
										
											2019-12-26 10:54:26 +05:30
										 |  |  |                     billing_address_id=billing_address.id | 
					
						
							| 
									
										
										
										
											2019-12-25 22:27:14 +05:30
										 |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2019-12-25 21:02:43 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 10:54:26 +05:30
										 |  |  |                 if 'error' in validate_result and validate_result['error']: | 
					
						
							| 
									
										
										
										
											2019-12-25 22:40:57 +05:30
										 |  |  |                     messages.add_message( | 
					
						
							|  |  |  |                         request, messages.ERROR, validate_result["error"], | 
					
						
							|  |  |  |                         extra_tags='vat_error' | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     return HttpResponseRedirect( | 
					
						
							|  |  |  |                         reverse('datacenterlight:payment') + '#vat_error' | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 request.session["vat_validation_status"] = validate_result["status"] | 
					
						
							| 
									
										
										
										
											2019-12-25 20:11:15 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-01 08:57:39 +05:30
										 |  |  |             # For generic payment we take the user directly to confirmation | 
					
						
							|  |  |  |             if ('generic_payment_type' in request.session and | 
					
						
							|  |  |  |                     self.request.session['generic_payment_type'] == 'generic'): | 
					
						
							|  |  |  |                 return HttpResponseRedirect( | 
					
						
							|  |  |  |                     reverse('datacenterlight:order_confirmation')) | 
					
						
							| 
									
										
										
										
											2019-07-01 20:30:06 +05:30
										 |  |  |             else: | 
					
						
							|  |  |  |                 self.request.session['order_confirm_url'] = reverse('datacenterlight:order_confirmation') | 
					
						
							|  |  |  |                 return HttpResponseRedirect( | 
					
						
							|  |  |  |                     reverse('datacenterlight:add_ssh_key')) | 
					
						
							| 
									
										
										
										
											2017-06-21 13:14:58 +05:30
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2017-10-08 13:50:43 +02:00
										 |  |  |             context = self.get_context_data() | 
					
						
							|  |  |  |             context['billing_address_form'] = address_form | 
					
						
							|  |  |  |             return self.render_to_response(context) | 
					
						
							| 
									
										
										
										
											2017-06-22 13:21:07 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-29 19:23:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 04:32:27 +02:00
										 |  |  | class OrderConfirmationView(DetailView, FormView): | 
					
						
							|  |  |  |     form_class = UserHostingKeyForm | 
					
						
							| 
									
										
										
										
											2017-06-22 13:21:07 +05:30
										 |  |  |     template_name = "datacenterlight/order_detail.html" | 
					
						
							| 
									
										
										
										
											2017-09-02 02:02:05 +05:30
										 |  |  |     payment_template_name = 'datacenterlight/landing_payment.html' | 
					
						
							| 
									
										
										
										
											2017-06-22 13:21:07 +05:30
										 |  |  |     context_object_name = "order" | 
					
						
							|  |  |  |     model = HostingOrder | 
					
						
							| 
									
										
										
										
											2017-07-01 15:53:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 04:32:27 +02:00
										 |  |  |     def get_form_kwargs(self): | 
					
						
							|  |  |  |         kwargs = super(OrderConfirmationView, self).get_form_kwargs() | 
					
						
							|  |  |  |         kwargs.update({'request': self.request}) | 
					
						
							|  |  |  |         return kwargs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-30 12:08:07 +05:30
										 |  |  |     @cache_control(no_cache=True, must_revalidate=True, no_store=True) | 
					
						
							| 
									
										
										
										
											2017-06-29 13:08:24 +05:30
										 |  |  |     def get(self, request, *args, **kwargs): | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |         context = {} | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |         if (('specs' not in request.session or 'user' not in request.session) | 
					
						
							|  |  |  |                 and 'generic_payment_type' not in request.session): | 
					
						
							| 
									
										
										
										
											2017-06-29 13:08:24 +05:30
										 |  |  |             return HttpResponseRedirect(reverse('datacenterlight:index')) | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |         if 'token' in self.request.session: | 
					
						
							|  |  |  |             token = self.request.session['token'] | 
					
						
							|  |  |  |             stripe_utils = StripeUtils() | 
					
						
							|  |  |  |             card_details = stripe_utils.get_cards_details_from_token( | 
					
						
							|  |  |  |                 token | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             if not card_details.get('response_object'): | 
					
						
							|  |  |  |                 return HttpResponseRedirect(reverse('hosting:payment')) | 
					
						
							|  |  |  |             card_details_response = card_details['response_object'] | 
					
						
							|  |  |  |             context['cc_last4'] = card_details_response['last4'] | 
					
						
							|  |  |  |             context['cc_brand'] = card_details_response['brand'] | 
					
						
							| 
									
										
										
										
											2019-07-09 18:40:41 +05:30
										 |  |  |             context['cc_exp_year'] = card_details_response['exp_year'] | 
					
						
							| 
									
										
										
										
											2019-07-09 19:03:09 +05:30
										 |  |  |             context['cc_exp_month'] = '{:02d}'.format(card_details_response['exp_month']) | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |         else: | 
					
						
							|  |  |  |             card_id = self.request.session.get('card_id') | 
					
						
							|  |  |  |             card_detail = UserCardDetail.objects.get(id=card_id) | 
					
						
							|  |  |  |             context['cc_last4'] = card_detail.last4 | 
					
						
							|  |  |  |             context['cc_brand'] = card_detail.brand | 
					
						
							| 
									
										
										
										
											2019-07-09 18:40:41 +05:30
										 |  |  |             context['cc_exp_year'] = card_detail.exp_year | 
					
						
							| 
									
										
										
										
											2019-07-09 19:03:09 +05:30
										 |  |  |             context['cc_exp_month'] ='{:02d}'.format(card_detail.exp_month) | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ('generic_payment_type' in request.session and | 
					
						
							| 
									
										
										
										
											2018-09-23 13:27:33 +02:00
										 |  |  |                 self.request.session['generic_payment_type'] == 'generic'): | 
					
						
							| 
									
										
										
										
											2019-12-25 20:11:15 +05:30
										 |  |  |             if request.session["vat_validation_status"] == "verified": | 
					
						
							|  |  |  |                 request.session['generic_payment_details']['vat_rate'] = 0 | 
					
						
							|  |  |  |                 request.session['generic_payment_details']['vat_amount'] = 0 | 
					
						
							|  |  |  |                 request.session['generic_payment_details']['amount'] = request.session['generic_payment_details']['amount_before_vat'] | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             context.update({ | 
					
						
							|  |  |  |                 'generic_payment_details': | 
					
						
							|  |  |  |                     request.session['generic_payment_details'], | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2019-12-07 19:26:21 +05:30
										 |  |  |             vm_specs = request.session.get('specs') | 
					
						
							|  |  |  |             user_vat_country = ( | 
					
						
							|  |  |  |                 request.session.get('billing_address_data').get("country") | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             user_country_vat_rate = get_vat_rate_for_country(user_vat_country) | 
					
						
							|  |  |  |             price, vat, vat_percent, discount = get_vm_price_for_given_vat( | 
					
						
							|  |  |  |                 cpu=vm_specs['cpu'], | 
					
						
							|  |  |  |                 memory=vm_specs['memory'], | 
					
						
							|  |  |  |                 ssd_size=vm_specs['disk_size'], | 
					
						
							|  |  |  |                 pricing_name=vm_specs['pricing_name'], | 
					
						
							|  |  |  |                 vat_rate=user_country_vat_rate * 100 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             vm_specs["price"] = price | 
					
						
							| 
									
										
										
										
											2019-12-25 20:11:15 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 10:55:01 +05:30
										 |  |  |             vat_number = request.session.get('billing_address_data').get("vat_number") | 
					
						
							| 
									
										
										
										
											2019-12-26 11:50:15 +05:30
										 |  |  |             billing_address = BillingAddress.objects.get(id=request.session["billing_address_id"]) | 
					
						
							| 
									
										
										
										
											2019-12-26 10:55:01 +05:30
										 |  |  |             if vat_number: | 
					
						
							|  |  |  |                 validate_result = validate_vat_number( | 
					
						
							|  |  |  |                     stripe_customer_id=request.session['customer'], | 
					
						
							|  |  |  |                     billing_address_id=billing_address.id | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 if 'error' in validate_result and validate_result['error']: | 
					
						
							|  |  |  |                     messages.add_message( | 
					
						
							|  |  |  |                         request, messages.ERROR, validate_result["error"], | 
					
						
							|  |  |  |                         extra_tags='vat_error' | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     return HttpResponseRedirect( | 
					
						
							|  |  |  |                         reverse('datacenterlight:payment') + '#vat_error' | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 request.session["vat_validation_status"] = validate_result["status"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-25 22:45:55 +05:30
										 |  |  |             if ("vat_validation_status" in request.session and | 
					
						
							|  |  |  |                     request.session["vat_validation_status"] == "verified"): | 
					
						
							| 
									
										
										
										
											2019-12-25 20:11:15 +05:30
										 |  |  |                 vm_specs["vat_percent"] = 0 | 
					
						
							|  |  |  |                 vm_specs["vat"] = 0 | 
					
						
							|  |  |  |                 vm_specs["total_price"] = price | 
					
						
							|  |  |  |                 vm_specs["vat_validation_status"] = "verified" | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 vm_specs["vat"] = vat | 
					
						
							|  |  |  |                 vm_specs["vat_percent"] = vat_percent | 
					
						
							|  |  |  |                 vm_specs["total_price"] = round(price + vat - discount['amount'], 2) | 
					
						
							| 
									
										
										
										
											2019-12-25 22:45:55 +05:30
										 |  |  |                 vm_specs["vat_validation_status"] = request.session["vat_validation_status"] if "vat_validation_status" in request.session else "" | 
					
						
							| 
									
										
										
										
											2019-12-25 20:11:15 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-07 19:42:46 +05:30
										 |  |  |             vm_specs["vat_country"] = user_vat_country | 
					
						
							| 
									
										
										
										
											2019-12-07 19:26:21 +05:30
										 |  |  |             vm_specs["discount"] = discount | 
					
						
							| 
									
										
										
										
											2019-12-18 19:33:44 +05:30
										 |  |  |             request.session['specs'] = vm_specs | 
					
						
							| 
									
										
										
										
											2019-12-07 19:26:21 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             context.update({ | 
					
						
							| 
									
										
										
										
											2019-12-07 19:26:21 +05:30
										 |  |  |                 'vm': vm_specs, | 
					
						
							| 
									
										
										
										
											2019-06-24 04:32:27 +02:00
										 |  |  |                 'form': UserHostingKeyForm(request=self.request), | 
					
						
							| 
									
										
										
										
											2019-06-24 17:24:35 +02:00
										 |  |  |                 'keys': get_all_public_keys(self.request.user) | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |         context.update({ | 
					
						
							| 
									
										
										
										
											2017-07-01 04:29:11 +05:30
										 |  |  |             'site_url': reverse('datacenterlight:index'), | 
					
						
							| 
									
										
										
										
											2017-09-28 18:27:26 +05:30
										 |  |  |             'page_header_text': _('Confirm Order'), | 
					
						
							| 
									
										
										
										
											2018-03-27 19:19:26 +05:30
										 |  |  |             'billing_address_data': ( | 
					
						
							|  |  |  |                 request.session.get('billing_address_data') | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2018-05-07 05:07:58 +05:30
										 |  |  |             'cms_integration': get_cms_integration('default'), | 
					
						
							| 
									
										
										
										
											2018-07-04 02:53:43 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2017-06-30 11:06:58 +05:30
										 |  |  |         return render(request, self.template_name, context) | 
					
						
							| 
									
										
										
										
											2017-07-01 15:53:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-29 13:08:24 +05:30
										 |  |  |     def post(self, request, *args, **kwargs): | 
					
						
							| 
									
										
										
										
											2019-06-25 03:48:29 +02:00
										 |  |  |         user = request.session.get('user') | 
					
						
							|  |  |  |         stripe_api_cus_id = request.session.get('customer') | 
					
						
							|  |  |  |         stripe_utils = StripeUtils() | 
					
						
							| 
									
										
										
										
											2019-06-24 04:32:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 09:57:18 +02:00
										 |  |  |         if 'token' in request.session: | 
					
						
							|  |  |  |             card_details = stripe_utils.get_cards_details_from_token( | 
					
						
							|  |  |  |                 request.session.get('token') | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             if not card_details.get('response_object'): | 
					
						
							|  |  |  |                 msg = card_details.get('error') | 
					
						
							|  |  |  |                 messages.add_message(self.request, messages.ERROR, msg, | 
					
						
							|  |  |  |                                      extra_tags='failed_payment') | 
					
						
							|  |  |  |                 response = { | 
					
						
							|  |  |  |                     'status': False, | 
					
						
							|  |  |  |                     'redirect': "{url}#{section}".format( | 
					
						
							| 
									
										
										
										
											2018-10-06 07:31:38 +02:00
										 |  |  |                         url=(reverse( | 
					
						
							|  |  |  |                             'show_product', | 
					
						
							|  |  |  |                             kwargs={'product_slug': | 
					
						
							|  |  |  |                                     request.session['generic_payment_details'] | 
					
						
							|  |  |  |                                     ['product_slug']} | 
					
						
							|  |  |  |                         ) if 'generic_payment_details' in request.session else | 
					
						
							| 
									
										
										
										
											2018-10-05 11:10:10 +02:00
										 |  |  |                                 reverse('datacenterlight:payment') | 
					
						
							| 
									
										
										
										
											2018-10-06 07:31:38 +02:00
										 |  |  |                         ), | 
					
						
							| 
									
										
										
										
											2018-07-05 09:57:18 +02:00
										 |  |  |                         section='payment_error'), | 
					
						
							|  |  |  |                     'msg_title': str(_('Error.')), | 
					
						
							|  |  |  |                     'msg_body': str( | 
					
						
							|  |  |  |                         _('There was a payment related error.' | 
					
						
							|  |  |  |                           ' On close of this popup, you will be' | 
					
						
							|  |  |  |                           ' redirected back to the payment page.') | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return JsonResponse(response) | 
					
						
							|  |  |  |             card_details_response = card_details['response_object'] | 
					
						
							|  |  |  |             card_details_dict = { | 
					
						
							|  |  |  |                 'last4': card_details_response['last4'], | 
					
						
							|  |  |  |                 'brand': card_details_response['brand'], | 
					
						
							|  |  |  |                 'card_id': card_details_response['card_id'] | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-09-22 08:20:49 +02:00
										 |  |  |             stripe_customer_obj = StripeCustomer.objects.filter( | 
					
						
							|  |  |  |                 stripe_id=stripe_api_cus_id).first() | 
					
						
							| 
									
										
										
										
											2018-07-05 09:57:18 +02:00
										 |  |  |             if stripe_customer_obj: | 
					
						
							|  |  |  |                 ucd = UserCardDetail.get_user_card_details( | 
					
						
							|  |  |  |                     stripe_customer_obj, card_details_response | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 if not ucd: | 
					
						
							|  |  |  |                     acc_result = stripe_utils.associate_customer_card( | 
					
						
							|  |  |  |                         stripe_api_cus_id, request.session['token'], | 
					
						
							|  |  |  |                         set_as_default=True | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     if acc_result['response_object'] is None: | 
					
						
							|  |  |  |                         msg = _( | 
					
						
							|  |  |  |                             'An error occurred while associating the card.' | 
					
						
							|  |  |  |                             ' Details: {details}'.format( | 
					
						
							|  |  |  |                                 details=acc_result['error'] | 
					
						
							|  |  |  |                             ) | 
					
						
							|  |  |  |                         ) | 
					
						
							|  |  |  |                         messages.add_message(self.request, messages.ERROR, msg, | 
					
						
							|  |  |  |                                              extra_tags='failed_payment') | 
					
						
							|  |  |  |                         response = { | 
					
						
							|  |  |  |                             'status': False, | 
					
						
							|  |  |  |                             'redirect': "{url}#{section}".format( | 
					
						
							| 
									
										
										
										
											2018-10-06 07:31:38 +02:00
										 |  |  |                                 url=(reverse( | 
					
						
							|  |  |  |                                     'show_product', | 
					
						
							|  |  |  |                                     kwargs={'product_slug': | 
					
						
							|  |  |  |                                             request.session | 
					
						
							|  |  |  |                                             ['generic_payment_details'] | 
					
						
							|  |  |  |                                             ['product_slug']} | 
					
						
							|  |  |  |                                     ) if 'generic_payment_details' in | 
					
						
							|  |  |  |                                      request.session else | 
					
						
							| 
									
										
										
										
											2018-10-05 11:10:10 +02:00
										 |  |  |                                      reverse('datacenterlight:payment') | 
					
						
							| 
									
										
										
										
											2018-10-06 07:31:38 +02:00
										 |  |  |                                 ), | 
					
						
							| 
									
										
										
										
											2018-07-05 09:57:18 +02:00
										 |  |  |                                 section='payment_error'), | 
					
						
							|  |  |  |                             'msg_title': str(_('Error.')), | 
					
						
							|  |  |  |                             'msg_body': str( | 
					
						
							|  |  |  |                                 _('There was a payment related error.' | 
					
						
							|  |  |  |                                   ' On close of this popup, you will be redirected' | 
					
						
							|  |  |  |                                   ' back to the payment page.') | 
					
						
							|  |  |  |                             ) | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         return JsonResponse(response) | 
					
						
							|  |  |  |         elif 'card_id' in request.session: | 
					
						
							|  |  |  |             card_id = request.session.get('card_id') | 
					
						
							|  |  |  |             user_card_detail = UserCardDetail.objects.get(id=card_id) | 
					
						
							|  |  |  |             card_details_dict = { | 
					
						
							|  |  |  |                 'last4': user_card_detail.last4, | 
					
						
							|  |  |  |                 'brand': user_card_detail.brand, | 
					
						
							|  |  |  |                 'card_id': user_card_detail.card_id | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2017-09-22 21:30:42 +02:00
										 |  |  |             response = { | 
					
						
							|  |  |  |                 'status': False, | 
					
						
							|  |  |  |                 'redirect': "{url}#{section}".format( | 
					
						
							|  |  |  |                     url=reverse('datacenterlight:payment'), | 
					
						
							|  |  |  |                     section='payment_error'), | 
					
						
							|  |  |  |                 'msg_title': str(_('Error.')), | 
					
						
							|  |  |  |                 'msg_body': str( | 
					
						
							|  |  |  |                     _('There was a payment related error.' | 
					
						
							|  |  |  |                       ' On close of this popup, you will be redirected back to' | 
					
						
							|  |  |  |                       ' the payment page.')) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-04-20 20:25:24 +05:30
										 |  |  |             return JsonResponse(response) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |         if ('generic_payment_type' in request.session and | 
					
						
							|  |  |  |                 self.request.session['generic_payment_type'] == 'generic'): | 
					
						
							|  |  |  |             gp_details = self.request.session['generic_payment_details'] | 
					
						
							|  |  |  |             if gp_details['recurring']: | 
					
						
							|  |  |  |                 # generic recurring payment | 
					
						
							|  |  |  |                 logger.debug("Commencing a generic recurring payment") | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 # generic one time payment | 
					
						
							|  |  |  |                 logger.debug("Commencing a one time payment") | 
					
						
							|  |  |  |                 charge_response = stripe_utils.make_charge( | 
					
						
							|  |  |  |                     amount=gp_details['amount'], | 
					
						
							|  |  |  |                     customer=stripe_api_cus_id | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 stripe_onetime_charge = charge_response.get('response_object') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 # Check if the payment was approved | 
					
						
							|  |  |  |                 if not stripe_onetime_charge: | 
					
						
							|  |  |  |                     msg = charge_response.get('error') | 
					
						
							|  |  |  |                     messages.add_message(self.request, messages.ERROR, msg, | 
					
						
							|  |  |  |                                          extra_tags='failed_payment') | 
					
						
							|  |  |  |                     response = { | 
					
						
							|  |  |  |                         'status': False, | 
					
						
							|  |  |  |                         'redirect': "{url}#{section}".format( | 
					
						
							| 
									
										
										
										
											2018-10-05 11:10:10 +02:00
										 |  |  |                             url=(reverse('show_product', kwargs={ | 
					
						
							| 
									
										
										
										
											2018-10-06 07:31:38 +02:00
										 |  |  |                                 'product_slug': gp_details['product_slug']} | 
					
						
							| 
									
										
										
										
											2018-10-05 11:10:10 +02:00
										 |  |  |                                          ) if 'generic_payment_details' in | 
					
						
							|  |  |  |                                               request.session else | 
					
						
							|  |  |  |                                  reverse('datacenterlight:payment') | 
					
						
							|  |  |  |                                  ), | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                             section='payment_error'), | 
					
						
							|  |  |  |                         'msg_title': str(_('Error.')), | 
					
						
							|  |  |  |                         'msg_body': str( | 
					
						
							|  |  |  |                             _('There was a payment related error.' | 
					
						
							|  |  |  |                               ' On close of this popup, you will be redirected' | 
					
						
							|  |  |  |                               ' back to the payment page.')) | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     return JsonResponse(response) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ('generic_payment_type' not in request.session or | 
					
						
							|  |  |  |                 (request.session['generic_payment_details']['recurring'])): | 
					
						
							| 
									
										
										
										
											2019-11-15 19:47:11 +05:30
										 |  |  |             recurring_interval = 'month' | 
					
						
							| 
									
										
										
										
											2018-09-24 22:27:25 +02:00
										 |  |  |             if 'generic_payment_details' in request.session: | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                 amount_to_be_charged = ( | 
					
						
							|  |  |  |                     round( | 
					
						
							|  |  |  |                         request.session['generic_payment_details']['amount'], | 
					
						
							|  |  |  |                         2 | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2018-10-03 09:35:20 +02:00
										 |  |  |                 plan_name = "generic-{0}-{1:.2f}".format( | 
					
						
							| 
									
										
										
										
											2018-09-26 23:00:57 +02:00
										 |  |  |                     request.session['generic_payment_details']['product_id'], | 
					
						
							|  |  |  |                     amount_to_be_charged | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                 stripe_plan_id = plan_name | 
					
						
							| 
									
										
										
										
											2019-11-15 19:47:11 +05:30
										 |  |  |                 recurring_interval = request.session['generic_payment_details']['recurring_interval'] | 
					
						
							|  |  |  |                 if recurring_interval == "year": | 
					
						
							|  |  |  |                     plan_name = "{}-yearly".format(plan_name) | 
					
						
							|  |  |  |                     stripe_plan_id = plan_name | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 template = request.session.get('template') | 
					
						
							|  |  |  |                 specs = request.session.get('specs') | 
					
						
							|  |  |  |                 vm_template_id = template.get('id', 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 cpu = specs.get('cpu') | 
					
						
							|  |  |  |                 memory = specs.get('memory') | 
					
						
							|  |  |  |                 disk_size = specs.get('disk_size') | 
					
						
							|  |  |  |                 amount_to_be_charged = specs.get('total_price') | 
					
						
							|  |  |  |                 plan_name = StripeUtils.get_stripe_plan_name( | 
					
						
							|  |  |  |                     cpu=cpu, | 
					
						
							|  |  |  |                     memory=memory, | 
					
						
							|  |  |  |                     disk_size=disk_size, | 
					
						
							|  |  |  |                     price=amount_to_be_charged | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 stripe_plan_id = StripeUtils.get_stripe_plan_id( | 
					
						
							|  |  |  |                     cpu=cpu, | 
					
						
							|  |  |  |                     ram=memory, | 
					
						
							|  |  |  |                     ssd=disk_size, | 
					
						
							|  |  |  |                     version=1, | 
					
						
							|  |  |  |                     app='dcl', | 
					
						
							|  |  |  |                     price=amount_to_be_charged | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             stripe_plan = stripe_utils.get_or_create_stripe_plan( | 
					
						
							|  |  |  |                 amount=amount_to_be_charged, | 
					
						
							|  |  |  |                 name=plan_name, | 
					
						
							| 
									
										
										
										
											2019-11-15 19:47:11 +05:30
										 |  |  |                 stripe_plan_id=stripe_plan_id, | 
					
						
							|  |  |  |                 interval=recurring_interval | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             subscription_result = stripe_utils.subscribe_customer_to_plan( | 
					
						
							|  |  |  |                 stripe_api_cus_id, | 
					
						
							|  |  |  |                 [{"plan": stripe_plan.get( | 
					
						
							|  |  |  |                     'response_object').stripe_plan_id}]) | 
					
						
							|  |  |  |             stripe_subscription_obj = subscription_result.get('response_object') | 
					
						
							|  |  |  |             # Check if the subscription was approved and is active | 
					
						
							|  |  |  |             if (stripe_subscription_obj is None | 
					
						
							|  |  |  |                     or stripe_subscription_obj.status != 'active'): | 
					
						
							|  |  |  |                 # At this point, we have created a Stripe API card and | 
					
						
							|  |  |  |                 # associated it with the customer; but the transaction failed | 
					
						
							|  |  |  |                 # due to some reason. So, we would want to dissociate this card | 
					
						
							|  |  |  |                 # here. | 
					
						
							|  |  |  |                 # ... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 msg = subscription_result.get('error') | 
					
						
							|  |  |  |                 messages.add_message(self.request, messages.ERROR, msg, | 
					
						
							|  |  |  |                                      extra_tags='failed_payment') | 
					
						
							|  |  |  |                 response = { | 
					
						
							|  |  |  |                     'status': False, | 
					
						
							|  |  |  |                     'redirect': "{url}#{section}".format( | 
					
						
							| 
									
										
										
										
											2018-10-06 07:31:38 +02:00
										 |  |  |                         url=(reverse( | 
					
						
							|  |  |  |                             'show_product', | 
					
						
							|  |  |  |                             kwargs={'product_slug': | 
					
						
							|  |  |  |                                     request.session['generic_payment_details'] | 
					
						
							|  |  |  |                                     ['product_slug']} | 
					
						
							|  |  |  |                         ) if 'generic_payment_details' in request.session else | 
					
						
							| 
									
										
										
										
											2018-10-05 11:10:10 +02:00
										 |  |  |                                 reverse('datacenterlight:payment') | 
					
						
							| 
									
										
										
										
											2018-10-06 07:31:38 +02:00
										 |  |  |                         ), | 
					
						
							|  |  |  |                         section='payment_error' | 
					
						
							|  |  |  |                     ), | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                     'msg_title': str(_('Error.')), | 
					
						
							|  |  |  |                     'msg_body': str( | 
					
						
							|  |  |  |                         _('There was a payment related error.' | 
					
						
							|  |  |  |                           ' On close of this popup, you will be redirected back to' | 
					
						
							|  |  |  |                           ' the payment page.')) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return JsonResponse(response) | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 11:45:21 +02:00
										 |  |  |         # Create user if the user is not logged in and if he is not already | 
					
						
							|  |  |  |         # registered | 
					
						
							| 
									
										
										
										
											2017-09-22 12:38:05 +02:00
										 |  |  |         if not request.user.is_authenticated(): | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |             try: | 
					
						
							|  |  |  |                 custom_user = CustomUser.objects.get( | 
					
						
							|  |  |  |                     email=user.get('email')) | 
					
						
							| 
									
										
										
										
											2017-10-08 21:01:25 +02:00
										 |  |  |                 stripe_customer = StripeCustomer.objects.filter( | 
					
						
							| 
									
										
										
										
											2017-09-22 21:20:00 +02:00
										 |  |  |                     user_id=custom_user.id).first() | 
					
						
							| 
									
										
										
										
											2017-10-08 21:01:25 +02:00
										 |  |  |                 if stripe_customer is None: | 
					
						
							|  |  |  |                     stripe_customer = StripeCustomer.objects.create( | 
					
						
							|  |  |  |                         user=custom_user, stripe_id=stripe_api_cus_id | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                 stripe_customer_id = stripe_customer.id | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |             except CustomUser.DoesNotExist: | 
					
						
							| 
									
										
										
										
											2017-09-22 11:45:21 +02:00
										 |  |  |                 logger.debug( | 
					
						
							|  |  |  |                     "Customer {} does not exist.".format(user.get('email'))) | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |                 password = CustomUser.get_random_password() | 
					
						
							| 
									
										
										
										
											2017-09-22 13:46:22 +02:00
										 |  |  |                 base_url = "{0}://{1}".format(self.request.scheme, | 
					
						
							|  |  |  |                                               self.request.get_host()) | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |                 custom_user = CustomUser.register( | 
					
						
							| 
									
										
										
										
											2017-09-21 14:29:49 +02:00
										 |  |  |                     user.get('name'), password, | 
					
						
							|  |  |  |                     user.get('email'), | 
					
						
							| 
									
										
										
										
											2017-09-22 13:46:22 +02:00
										 |  |  |                     app='dcl', base_url=base_url, send_email=True, | 
					
						
							| 
									
										
										
										
											2017-09-22 12:01:09 +02:00
										 |  |  |                     account_details=password | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |                 ) | 
					
						
							|  |  |  |                 logger.debug("Created user {}.".format(user.get('email'))) | 
					
						
							| 
									
										
										
										
											2017-09-21 14:29:49 +02:00
										 |  |  |                 stripe_customer = StripeCustomer.objects. \ | 
					
						
							|  |  |  |                     create(user=custom_user, stripe_id=stripe_api_cus_id) | 
					
						
							|  |  |  |                 stripe_customer_id = stripe_customer.id | 
					
						
							| 
									
										
										
										
											2017-09-22 12:46:33 +02:00
										 |  |  |                 new_user = authenticate(username=custom_user.email, | 
					
						
							|  |  |  |                                         password=password) | 
					
						
							|  |  |  |                 login(request, new_user) | 
					
						
							| 
									
										
										
										
											2019-07-03 05:13:02 +05:30
										 |  |  |                 if 'new_user_hosting_key_id' in self.request.session: | 
					
						
							|  |  |  |                     user_hosting_key = UserHostingKey.objects.get(id=self.request.session['new_user_hosting_key_id']) | 
					
						
							|  |  |  |                     user_hosting_key.user = new_user | 
					
						
							|  |  |  |                     user_hosting_key.save() | 
					
						
							| 
									
										
										
										
											2019-07-01 23:09:42 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |                 owner = new_user | 
					
						
							|  |  |  |                 manager = OpenNebulaManager( | 
					
						
							|  |  |  |                     email=owner.email, | 
					
						
							|  |  |  |                     password=owner.password | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 keys_to_save = get_all_public_keys(new_user) | 
					
						
							|  |  |  |                 manager.save_key_in_opennebula_user('\n'.join(keys_to_save)) | 
					
						
							| 
									
										
										
										
											2017-09-21 14:29:49 +02:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2017-09-28 15:56:09 +02:00
										 |  |  |             # We assume that if the user is here, his/her StripeCustomer | 
					
						
							|  |  |  |             # object already exists | 
					
						
							|  |  |  |             stripe_customer_id = request.user.stripecustomer.id | 
					
						
							|  |  |  |             custom_user = request.user | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-05 20:36:43 +02:00
										 |  |  |         if 'token' in request.session: | 
					
						
							|  |  |  |             ucd = UserCardDetail.get_or_create_user_card_detail( | 
					
						
							|  |  |  |                 stripe_customer=self.request.user.stripecustomer, | 
					
						
							|  |  |  |                 card_details=card_details_response | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             UserCardDetail.save_default_card_local( | 
					
						
							|  |  |  |                 self.request.user.stripecustomer.stripe_id, | 
					
						
							|  |  |  |                 ucd.card_id | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             card_id = request.session.get('card_id') | 
					
						
							|  |  |  |             user_card_detail = UserCardDetail.objects.get(id=card_id) | 
					
						
							|  |  |  |             card_details_dict = { | 
					
						
							|  |  |  |                 'last4': user_card_detail.last4, | 
					
						
							|  |  |  |                 'brand': user_card_detail.brand, | 
					
						
							|  |  |  |                 'card_id': user_card_detail.card_id | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if not user_card_detail.preferred: | 
					
						
							|  |  |  |                 UserCardDetail.set_default_card( | 
					
						
							|  |  |  |                     stripe_api_cus_id=stripe_api_cus_id, | 
					
						
							|  |  |  |                     stripe_source_id=user_card_detail.card_id | 
					
						
							| 
									
										
										
										
											2018-07-05 09:57:18 +02:00
										 |  |  |                 ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 06:41:09 +05:30
										 |  |  |         # Save billing address | 
					
						
							|  |  |  |         billing_address_data = request.session.get('billing_address_data') | 
					
						
							|  |  |  |         logger.debug('billing_address_data is {}'.format(billing_address_data)) | 
					
						
							|  |  |  |         billing_address_data.update({ | 
					
						
							|  |  |  |             'user': custom_user.id | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-07-03 23:22:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |         if 'generic_payment_type' in request.session: | 
					
						
							|  |  |  |             stripe_cus = StripeCustomer.objects.filter( | 
					
						
							|  |  |  |                 stripe_id=stripe_api_cus_id | 
					
						
							|  |  |  |             ).first() | 
					
						
							|  |  |  |             billing_address = BillingAddress( | 
					
						
							|  |  |  |                 cardholder_name=billing_address_data['cardholder_name'], | 
					
						
							|  |  |  |                 street_address=billing_address_data['street_address'], | 
					
						
							|  |  |  |                 city=billing_address_data['city'], | 
					
						
							|  |  |  |                 postal_code=billing_address_data['postal_code'], | 
					
						
							| 
									
										
										
										
											2019-12-21 08:51:11 +05:30
										 |  |  |                 country=billing_address_data['country'], | 
					
						
							|  |  |  |                 vat_number=billing_address_data['vat_number'] | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             ) | 
					
						
							|  |  |  |             billing_address.save() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             order = HostingOrder.create( | 
					
						
							|  |  |  |                 price=self.request | 
					
						
							|  |  |  |                           .session['generic_payment_details']['amount'], | 
					
						
							|  |  |  |                 customer=stripe_cus, | 
					
						
							|  |  |  |                 billing_address=billing_address, | 
					
						
							|  |  |  |                 vm_pricing=VMPricing.get_default_pricing() | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Create a Hosting Bill | 
					
						
							|  |  |  |             HostingBill.create(customer=stripe_cus, | 
					
						
							|  |  |  |                                billing_address=billing_address) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Create Billing Address for User if he does not have one | 
					
						
							|  |  |  |             if not stripe_cus.user.billing_addresses.count(): | 
					
						
							|  |  |  |                 billing_address_data.update({ | 
					
						
							|  |  |  |                     'user': stripe_cus.user.id | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |                 billing_address_user_form = UserBillingAddressForm( | 
					
						
							|  |  |  |                     billing_address_data | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 billing_address_user_form.is_valid() | 
					
						
							|  |  |  |                 billing_address_user_form.save() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if self.request.session['generic_payment_details']['recurring']: | 
					
						
							|  |  |  |                 # Associate the given stripe subscription with the order | 
					
						
							|  |  |  |                 order.set_subscription_id( | 
					
						
							|  |  |  |                     stripe_subscription_obj.id, card_details_dict | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 # Associate the given stripe charge id with the order | 
					
						
							|  |  |  |                 order.set_stripe_charge(stripe_onetime_charge) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Set order status approved | 
					
						
							|  |  |  |             order.set_approved() | 
					
						
							| 
									
										
										
										
											2018-09-25 02:14:11 +02:00
										 |  |  |             order.generic_payment_description = gp_details["description"] | 
					
						
							|  |  |  |             order.generic_product_id = gp_details["product_id"] | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |             order.save() | 
					
						
							|  |  |  |             # send emails | 
					
						
							|  |  |  |             context = { | 
					
						
							|  |  |  |                 'name': user.get('name'), | 
					
						
							|  |  |  |                 'email': user.get('email'), | 
					
						
							|  |  |  |                 'amount': gp_details['amount'], | 
					
						
							|  |  |  |                 'description': gp_details['description'], | 
					
						
							|  |  |  |                 'recurring': gp_details['recurring'], | 
					
						
							| 
									
										
										
										
											2018-09-25 02:14:11 +02:00
										 |  |  |                 'product_name': gp_details['product_name'], | 
					
						
							| 
									
										
										
										
											2018-09-26 09:15:24 +02:00
										 |  |  |                 'product_id': gp_details['product_id'], | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                 'order_id': order.id | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             email_data = { | 
					
						
							| 
									
										
										
										
											2018-09-23 13:26:48 +02:00
										 |  |  |                 'subject': (settings.DCL_TEXT + | 
					
						
							|  |  |  |                             " Payment received from %s" % context['email']), | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, | 
					
						
							|  |  |  |                 'to': ['info@ungleich.ch'], | 
					
						
							|  |  |  |                 'body': "\n".join( | 
					
						
							|  |  |  |                     ["%s=%s" % (k, v) for (k, v) in context.items()]), | 
					
						
							|  |  |  |                 'reply_to': [context['email']], | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             send_plain_email_task.delay(email_data) | 
					
						
							| 
									
										
										
										
											2019-11-15 22:58:47 +05:30
										 |  |  |             recurring_text = _(" This is a monthly recurring plan.") | 
					
						
							|  |  |  |             if gp_details['recurring_interval'] == "year": | 
					
						
							|  |  |  |                 recurring_text = _(" This is an yearly recurring plan.") | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             email_data = { | 
					
						
							| 
									
										
										
										
											2018-09-26 22:42:30 +02:00
										 |  |  |                 'subject': _("Confirmation of your payment"), | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, | 
					
						
							|  |  |  |                 'to': [user.get('email')], | 
					
						
							| 
									
										
										
										
											2018-09-26 22:21:59 +02:00
										 |  |  |                 'body': _("Hi {name},\n\n" | 
					
						
							| 
									
										
										
										
											2018-09-26 22:31:06 +02:00
										 |  |  |                           "thank you for your order!\n" | 
					
						
							|  |  |  |                           "We have just received a payment of CHF {amount:.2f}" | 
					
						
							|  |  |  |                           " from you.{recurring}\n\n" | 
					
						
							| 
									
										
										
										
											2018-09-26 22:42:30 +02:00
										 |  |  |                           "Cheers,\nYour Data Center Light team".format( | 
					
						
							| 
									
										
										
										
											2018-09-23 13:26:48 +02:00
										 |  |  |                                  name=user.get('name'), | 
					
						
							|  |  |  |                                  amount=gp_details['amount'], | 
					
						
							|  |  |  |                                  recurring=( | 
					
						
							| 
									
										
										
										
											2019-11-15 22:58:47 +05:30
										 |  |  |                                      recurring_text | 
					
						
							| 
									
										
										
										
											2018-09-26 22:51:34 +02:00
										 |  |  |                                      if gp_details['recurring'] else '' | 
					
						
							| 
									
										
										
										
											2018-09-23 13:26:48 +02:00
										 |  |  |                                  ) | 
					
						
							|  |  |  |                              ) | 
					
						
							| 
									
										
										
										
											2018-09-26 22:51:34 +02:00
										 |  |  |                           ), | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                 'reply_to': ['info@ungleich.ch'], | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             send_plain_email_task.delay(email_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             response = { | 
					
						
							|  |  |  |                 'status': True, | 
					
						
							|  |  |  |                 'redirect': ( | 
					
						
							| 
									
										
										
										
											2018-09-23 17:19:24 +02:00
										 |  |  |                     reverse('hosting:orders') | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  |                     if request.user.is_authenticated() | 
					
						
							|  |  |  |                     else reverse('datacenterlight:index') | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 'msg_title': str(_('Thank you for the payment.')), | 
					
						
							|  |  |  |                 'msg_body': str( | 
					
						
							|  |  |  |                     _('You will soon receive a confirmation email of the ' | 
					
						
							|  |  |  |                       'payment. You can always contact us at ' | 
					
						
							|  |  |  |                       'info@ungleich.ch for any question that you may have.') | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-10-05 11:01:49 +02:00
										 |  |  |             clear_all_session_vars(request) | 
					
						
							| 
									
										
										
										
											2018-09-23 13:15:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             return JsonResponse(response) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 12:38:05 +02:00
										 |  |  |         user = { | 
					
						
							|  |  |  |             'name': custom_user.name, | 
					
						
							|  |  |  |             'email': custom_user.email, | 
					
						
							|  |  |  |             'pass': custom_user.password, | 
					
						
							|  |  |  |             'request_scheme': request.scheme, | 
					
						
							|  |  |  |             'request_host': request.get_host(), | 
					
						
							|  |  |  |             'language': get_language(), | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-09-22 11:45:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 20:25:24 +05:30
										 |  |  |         create_vm( | 
					
						
							|  |  |  |             billing_address_data, stripe_customer_id, specs, | 
					
						
							|  |  |  |             stripe_subscription_obj, card_details_dict, request, | 
					
						
							|  |  |  |             vm_template_id, template, user | 
					
						
							| 
									
										
										
										
											2018-04-18 23:50:52 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 21:20:00 +02:00
										 |  |  |         response = { | 
					
						
							|  |  |  |             'status': True, | 
					
						
							| 
									
										
										
										
											2018-02-28 04:09:19 +05:30
										 |  |  |             'redirect': ( | 
					
						
							|  |  |  |                 reverse('hosting:virtual_machines') | 
					
						
							|  |  |  |                 if request.user.is_authenticated() | 
					
						
							|  |  |  |                 else reverse('datacenterlight:index') | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2017-09-22 21:20:00 +02:00
										 |  |  |             'msg_title': str(_('Thank you for the order.')), | 
					
						
							|  |  |  |             'msg_body': str( | 
					
						
							|  |  |  |                 _('Your VM will be up and running in a few moments.' | 
					
						
							|  |  |  |                   ' We will send you a confirmation email as soon as' | 
					
						
							|  |  |  |                   ' it is ready.')) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-20 20:25:24 +05:30
										 |  |  |         return JsonResponse(response) |