+ {% 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 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')