Stripe: Fix CardError handling when subscribing

master
Alice 8 years ago
parent fd2a1b5c64
commit 381eab7943

@ -170,6 +170,10 @@ class StripeBackend(BackendBase):
) )
except self.stripe.error.InvalidRequestError: except self.stripe.error.InvalidRequestError:
return return
except self.stripe.CardError as e:
subscr.status = 'error'
subscr.backend_data['stripe_error'] = e.json_body['error']['message']
return
try: try:
if subscr.status == 'new': if subscr.status == 'new':

@ -126,6 +126,12 @@ def callback_stripe_subscr(request, id):
p = Subscription.objects.get(id=id) p = Subscription.objects.get(id=id)
BACKENDS['stripe'].callback_subscr(p, request) 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')) return redirect(reverse('account:index'))

Loading…
Cancel
Save