diff --git a/hosting/static/hosting/css/commons.css b/hosting/static/hosting/css/commons.css index 1ebae4b4..e8ba9ceb 100644 --- a/hosting/static/hosting/css/commons.css +++ b/hosting/static/hosting/css/commons.css @@ -6,6 +6,11 @@ max-width: 768px; } +.dashboard-container.wide { + padding-top: 90px; + max-width: 980px; +} + .content-dashboard{ min-height: calc(100vh - 70px); width: 80%; @@ -233,4 +238,27 @@ -webkit-transform: translate(-50%,-50%); -ms-transform: translate(-50%,-50%); transform: translate(-50%,-50%); +} + +.settings-container { + padding: 8px; +} + +.settings-container h4 { + margin-bottom: 15px; + color: #999; +} + +.settings-container .card-expiry-element, +.settings-container .card-cvc-element { + padding: 0 15px; +} + +.settings-container .stripe-payment-btn { + float: none; + position: static; +} + +.credit-card-form { + max-width: 360px; } \ No newline at end of file diff --git a/hosting/templates/hosting/settings.html b/hosting/templates/hosting/settings.html new file mode 100644 index 00000000..c540918e --- /dev/null +++ b/hosting/templates/hosting/settings.html @@ -0,0 +1,151 @@ +{% extends "hosting/base_short.html" %} +{% load staticfiles bootstrap3 i18n %} + +{% block content %} +
+
+

{% trans "My Settings" %}

+
+ +
+
+
+

{%trans "Billing Address"%}

+
+
+ {% for field in form %} + {% csrf_token %} + {% bootstrap_field field show_label=False type='fields'%} + {% endfor %} +
+
+
+

{%trans "Credit Card"%}

+
+
+
+ {% if credit_card_data.last4 %} +
+
Credit Card
+
Last 4: *****{{credit_card_data.last4}}
+
Type: {{credit_card_data.cc_brand}}
+ +
+
+
+ {% if not messages and not form.non_field_errors %} +

+ {% blocktrans %}You are not making any payment yet. After submitting your card information, you will be taken to the Confirm Order Page.{% endblocktrans %} +

+ {% endif %} +
+ {% for message in messages %} + {% if 'failed_payment' or 'make_charge_error' in message.tags %} +
  • +

    {{ message|safe }}

    +
+ {% endif %} + {% endfor %} + {% for error in form.non_field_errors %} +

+ {{ error|escape }} +

+ {% endfor %} +
+
+
+
+ +
+
+
+ {% endif %} +

{% trans "Add new Card" %}

+
+ +
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+ + +
+
+ +
+ {% if not messages and not form.non_field_errors %} +

+ {% blocktrans %}You are not making any payment here. After submitting your card information, you will be taken to the Confirm Order Page.{% endblocktrans %} +

+ {% endif %} +
+ {% for message in messages %} + {% if 'failed_payment' or 'make_charge_error' in message.tags %} +
  • +

    {{ message|safe }}

    +
+ {% endif %} + {% endfor %} + + {% for error in form.non_field_errors %} +

+ {{ error|escape }} +

+ {% endfor %} +
+
+
+ +
+
+
+ +
+

+
+
+
+
+
+
+
+
+ + + {% if stripe_key %} + {% get_current_language as LANGUAGE_CODE %} + + {%endif%} + + {% if credit_card_data.last4 and credit_card_data.cc_brand %} + + {%endif%} +{%endblock%} diff --git a/hosting/views.py b/hosting/views.py index dba74c8f..a860dfc9 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -40,20 +40,6 @@ CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a backend connection error. please try again in a few minutes." -class SettingsView(View): - template_name = "hosting/settings.html" - - def get_context_data(self, **kwargs): - context = { - - } - return context - - def get(self, request, *args, **kwargs): - context = self.get_context_data() - return render(request, self.template_name, context) - - class DjangoHostingView(ProcessVMSelectionMixin, View): template_name = "hosting/django.html" @@ -489,6 +475,52 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): return self.form_invalid(form) +class SettingsView(LoginRequiredMixin, FormView): + template_name = "hosting/settings.html" + login_url = reverse_lazy('hosting:login') + form_class = BillingAddressForm + + def get_form_kwargs(self): + current_billing_address = self.request.user.billing_addresses.first() + form_kwargs = super(SettingsView, self).get_form_kwargs() + if not current_billing_address: + return form_kwargs + + form_kwargs.update({ + 'initial': { + 'cardholder_name': current_billing_address.cardholder_name, + 'street_address': current_billing_address.street_address, + 'city': current_billing_address.city, + 'postal_code': current_billing_address.postal_code, + 'country': current_billing_address.country, + } + }) + return form_kwargs + + def get_context_data(self, **kwargs): + context = super(SettingsView, self).get_context_data(**kwargs) + # Get user + user = self.request.user + + # Get user last order + last_hosting_order = HostingOrder.objects.filter( + customer__user=user).last() + + # If user has already an hosting order, get the credit card data from + # it + if last_hosting_order: + credit_card_data = last_hosting_order.get_cc_data() + context.update({ + 'credit_card_data': credit_card_data if credit_card_data else None, + }) + + context.update({ + 'stripe_key': settings.STRIPE_API_PUBLIC_KEY + }) + + return context + + class PaymentVMView(LoginRequiredMixin, FormView): template_name = 'hosting/payment.html' login_url = reverse_lazy('hosting:login')