From 381eab79432d8820075d112f0b9b6b1b91621347 Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 16 Jan 2017 00:59:52 +0000 Subject: [PATCH] Stripe: Fix CardError handling when subscribing --- payments/backends/stripe.py | 4 ++++ payments/views.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/payments/backends/stripe.py b/payments/backends/stripe.py index ecadd74..597704a 100644 --- a/payments/backends/stripe.py +++ b/payments/backends/stripe.py @@ -170,6 +170,10 @@ class StripeBackend(BackendBase): ) except self.stripe.error.InvalidRequestError: return + except self.stripe.CardError as e: + subscr.status = 'error' + subscr.backend_data['stripe_error'] = e.json_body['error']['message'] + return try: if subscr.status == 'new': diff --git a/payments/views.py b/payments/views.py index 5ca5dd5..2cebd74 100644 --- a/payments/views.py +++ b/payments/views.py @@ -126,6 +126,12 @@ def callback_stripe_subscr(request, id): p = Subscription.objects.get(id=id) BACKENDS['stripe'].callback_subscr(p, request) + if p.status == 'error' or p.status == 'cancelled': + messages.add_message(request, messages.ERROR, + _("Error subscribing. It usually means you don't" + " have enough money available.")) + else: + messages.add_message(request, messages.INFO, _("Subscribed!")) return redirect(reverse('account:index'))