hosting payment page

This commit is contained in:
Arvind Tiwari 2018-04-25 15:55:58 +05:30
parent 3b3b73a2ce
commit f66d768ecb
6 changed files with 41 additions and 16 deletions

View file

@ -175,7 +175,7 @@
window.coresUnitPrice = 5;
}
if(typeof window.ramUnitPrice === 'undefined'){
window.coresUnitPrice = 2;
window.ramUnitPrice = 2;
}
if(typeof window.ssdUnitPrice === 'undefined'){
window.ssdUnitPrice = 0.6;

View file

@ -61,6 +61,7 @@
</div>
{% endplaceholder %}
{% url 'datacenterlight:index' as calculator_form_url %}
{% placeholder 'Datacenterlight Content' %}
{% placeholder 'datacenterlight_footer'%}

View file

@ -11,7 +11,7 @@
</script>
{% endif %}
<form id="order_form" method="POST" action="{% url 'datacenterlight:index' %}" data-toggle="validator" role="form">
<form id="order_form" method="POST" action="{{calculator_form_url}}" data-toggle="validator" role="form">
{% csrf_token %}
<div class="title">
<h3>{% trans "VM hosting" %} </h3>

View file

@ -219,12 +219,11 @@ $( document ).ready(function() {
window.coresUnitPrice = 5;
}
if(typeof window.ramUnitPrice === 'undefined'){
window.coresUnitPrice = 2;
window.ramUnitPrice = 2;
}
if(typeof window.ssdUnitPrice === 'undefined'){
window.ssdUnitPrice = 0.6;
}
console.log(coresUnitPrice, ramUnitPrice, ssdUnitPrice, cardPricing)
var total = (cardPricing['cpu'].value * window.coresUnitPrice) +
(cardPricing['ram'].value * window.ramUnitPrice) +
(cardPricing['storage'].value * window.ssdUnitPrice);

View file

@ -42,12 +42,13 @@
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 dcl-order-table-total">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 tbl-tot tbl-no-padding">
{%trans "Total" %} <span>{%trans "including VAT" %}</span>
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 tbl-no-padding">
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4"></div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 tbl-total">{{request.session.specs.price|intcomma}}
CHF<span class="dcl-price-month">/{% trans "Month" %}</span>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 tbl-total">
{{request.session.specs.price|intcomma}} CHF/{% trans "Month" %}
</div>
</div>
</div>

View file

@ -30,7 +30,7 @@ from stored_messages.api import mark_read
from stored_messages.models import Message
from stored_messages.settings import stored_messages_settings
from datacenterlight.models import VMTemplate
from datacenterlight.models import VMTemplate, VMPricing
from datacenterlight.tasks import create_vm_task
from datacenterlight.utils import get_cms_integration
from membership.models import CustomUser, StripeCustomer
@ -1020,18 +1020,34 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
storage = request.POST.get('storage')
storage_field = forms.IntegerField(validators=[self.validate_storage])
template_id = int(request.POST.get('config'))
pricing_name = request.POST.get('pricing_name')
vm_pricing = VMPricing.get_vm_pricing_by_name(pricing_name)
template = VMTemplate.objects.filter(
opennebula_vm_template_id=template_id).first()
template_data = VMTemplateSerializer(template).data
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 redirect(CreateVirtualMachinesView.as_view())
else:
vm_pricing_name = vm_pricing.name
try:
cores = cores_field.clean(cores)
except ValidationError as err:
msg = '{} : {}.'.format(cores, str(err))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='cores')
return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form")
return redirect(CreateVirtualMachinesView.as_view())
try:
memory = memory_field.clean(memory)
@ -1039,8 +1055,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
msg = '{} : {}.'.format(memory, str(err))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='memory')
return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form")
return redirect(CreateVirtualMachinesView.as_view())
try:
storage = storage_field.clean(storage)
@ -1048,15 +1063,24 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
msg = '{} : {}.'.format(storage, str(err))
messages.add_message(self.request, messages.ERROR, msg,
extra_tags='storage')
return HttpResponseRedirect(
reverse('datacenterlight:index') + "#order_form")
price = get_vm_price(cpu=cores, memory=memory,
disk_size=storage)
return redirect(CreateVirtualMachinesView.as_view())
price, vat, vat_percent = get_vm_price_with_vat(
cpu=cores,
memory=memory,
ssd_size=storage,
pricing_name=vm_pricing_name
)
specs = {
'cpu': cores,
'memory': memory,
'disk_size': storage,
'price': price
'price': price,
'vat': vat,
'vat_percent': vat_percent,
'total_price': price + vat,
'pricing_name': vm_pricing_name
}
request.session['specs'] = specs