Added stripe make_charge error handler

This commit is contained in:
Siarhei Puhach 2017-08-07 13:36:21 +03:00
parent 4fea099b5d
commit 4cd3d6a4aa

View file

@ -467,15 +467,12 @@ class OrderConfirmationView(DetailView):
stripe_utils = StripeUtils() stripe_utils = StripeUtils()
charge_response = stripe_utils.make_charge(amount=final_price, charge_response = stripe_utils.make_charge(amount=final_price,
customer=customer.stripe_id) customer=customer.stripe_id)
charge = charge_response.get('response_object')
# Check if the payment was approved # Check if the payment was approved
if not charge: if not charge_response.get('response_object') and not charge_response.get('paid'):
context = {} msg = charge_response.get('error')
context.update({ messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error')
'paymentError': charge_response.get('error') return HttpResponseRedirect(reverse('datacenterlight:payment'))
})
return render(request, self.payment_template_name, context)
charge = charge_response.get('response_object') charge = charge_response.get('response_object')