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()
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')