diff --git a/datacenterlight/views.py b/datacenterlight/views.py index d82522e9..b20b212f 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -441,7 +441,7 @@ class OrderConfirmationView(DetailView): if not card_details.get('response_object') and not card_details.get('paid'): msg = card_details.get('error') messages.add_message(self.request, messages.ERROR, msg, extra_tags='failed_payment') - return HttpResponseRedirect(reverse('datacenterlight:payment')) + return HttpResponseRedirect(reverse('datacenterlight:payment') + '#dcl_payment_error') context = { 'site_url': reverse('datacenterlight:index'), @@ -472,7 +472,7 @@ class OrderConfirmationView(DetailView): if not charge_response.get('response_object') and not charge_response.get('paid'): msg = charge_response.get('error') messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error') - return HttpResponseRedirect(reverse('datacenterlight:payment')) + return HttpResponseRedirect(reverse('datacenterlight:payment') + '#dcl_payment_error') charge = charge_response.get('response_object') diff --git a/hosting/templates/hosting/payment.html b/hosting/templates/hosting/payment.html index cb7a4d8c..4c4ffa62 100644 --- a/hosting/templates/hosting/payment.html +++ b/hosting/templates/hosting/payment.html @@ -85,13 +85,29 @@
-

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

-
+ {% 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 %} + + {% endif %} + {% endfor %} + {% for error in form.non_field_errors %} +

+ {{ error|escape }} +

+ {% endfor %} +
+
- {% if not messages and not form.errors %} + {% if not messages and not form.non_field_errors %}

{% blocktrans %} You are not making any payment yet. After submitting your card @@ -137,22 +153,20 @@ {% endblocktrans %}

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

{% endif %} {% endfor %} - {% if form.errors %} - {% for error in form.non_field_errors %} -

- {{ error|escape }} -

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

+ {{ error|escape }} +

+ {% endfor %}
@@ -168,15 +182,6 @@

- {% if paymentError %} -
-
-

- {% bootstrap_alert paymentError alert_type='danger' %} -

-
-
- {% endif %} {% endif %} diff --git a/hosting/views.py b/hosting/views.py index 19ec5b2a..d1666b04 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -557,15 +557,12 @@ class PaymentVMView(LoginRequiredMixin, FormView): stripe_utils = StripeUtils() charge_response = stripe_utils.make_charge(amount=final_price, customer=customer.stripe_id) - charge = charge_response.get('response_object') # Check if the payment was approved - if not charge: - context.update({ - 'paymentError': charge_response.get('error'), - 'form': form - }) - return render(request, self.template_name, context) + if not charge_response.get('response_object') and not charge_response.get('paid'): + msg = charge_response.get('error') + messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error') + return HttpResponseRedirect(reverse('hosting:payment') + '#hosting_payment_error') charge = charge_response.get('response_object')