From 4cd3d6a4aada182b3d88ec7a6f6e2743278a7754 Mon Sep 17 00:00:00 2001 From: Siarhei Puhach Date: Mon, 7 Aug 2017 13:36:21 +0300 Subject: [PATCH] Added stripe make_charge error handler --- datacenterlight/views.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index dcf64814..d82522e9 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -467,15 +467,12 @@ class OrderConfirmationView(DetailView): 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 = {} - context.update({ - 'paymentError': charge_response.get('error') - }) - return render(request, self.payment_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('datacenterlight:payment')) charge = charge_response.get('response_object')