From 34acf2310b484920b6dd93fca030d88030128ad8 Mon Sep 17 00:00:00 2001 From: Siarhei Puhach Date: Thu, 3 Aug 2017 12:47:34 +0300 Subject: [PATCH] Added stripe failed payment error handler --- datacenterlight/views.py | 4 ++++ hosting/templates/hosting/payment.html | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 10e2d791..7dd2a76f 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -426,6 +426,10 @@ class OrderConfirmationView(DetailView): customer = StripeCustomer.objects.filter(id=stripe_customer_id).first() stripe_utils = StripeUtils() card_details = stripe_utils.get_card_details(customer.stripe_id, request.session.get('token')) + if not card_details.get('response_object') and not card_details.get('paid'): + msg = _('Currently its not possible to make payments. Please try later.') + messages.add_message(self.request, messages.ERROR, msg, extra_tags='failed_payment') + return HttpResponseRedirect(reverse('datacenterlight:payment')) context = { 'site_url': reverse('datacenterlight:index'), 'cc_last4': card_details.get('response_object').get('last4'), diff --git a/hosting/templates/hosting/payment.html b/hosting/templates/hosting/payment.html index d03713c1..5ef7f1ce 100644 --- a/hosting/templates/hosting/payment.html +++ b/hosting/templates/hosting/payment.html @@ -49,6 +49,15 @@ +
+ {% for message in messages %} + {% if 'failed_payment' in message.tags %} + + {% endif %} + {% endfor %} +