Added stripe failed payment error handler

This commit is contained in:
Siarhei Puhach 2017-08-03 12:47:34 +03:00
parent b28cbdc940
commit 34acf2310b
2 changed files with 13 additions and 0 deletions

View file

@ -426,6 +426,10 @@ class OrderConfirmationView(DetailView):
customer = StripeCustomer.objects.filter(id=stripe_customer_id).first() customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
stripe_utils = StripeUtils() stripe_utils = StripeUtils()
card_details = stripe_utils.get_card_details(customer.stripe_id, request.session.get('token')) 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 = { context = {
'site_url': reverse('datacenterlight:index'), 'site_url': reverse('datacenterlight:index'),
'cc_last4': card_details.get('response_object').get('last4'), 'cc_last4': card_details.get('response_object').get('last4'),

View file

@ -49,6 +49,15 @@
</div> </div>
</div> </div>
</div> </div>
<div class="help-block with-errors">
{% for message in messages %}
{% if 'failed_payment' in message.tags %}
<ul class="list-unstyled"><li>
<p class="alert alert-danger">{{ message|safe }}</p>
</li></ul>
{% endif %}
{% endfor %}
</div>
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 dcl-billing-sec"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 dcl-billing-sec">
<div class="col-xs-12 col-sm-5 col-md-6 billing dcl-billing"> <div class="col-xs-12 col-sm-5 col-md-6 billing dcl-billing">