I am working on a subscription based website with content behind a paywall wired up with Stripe. If the charge is declined or blocked, the account creation should cease and go back to the account create screen, with the error message.
Here's my exception code:
class RegistrationsController < Devise::RegistrationsController
rescue_from Stripe::CardError, with: :stripe_card_error
def stripe_card_error(e)
flash[:error] = "#{e.error.message}"
redirect_to request.referrer || "registrations#new" and return
end
def new
#
end
def create
#
end
//etc. etc.
It works fine for general card declines, however, when I run the test card numbers provided by Stripe that specifically say it will return fraudulent, the rescue does not trigger and the user account is created.
I got into my stripe dashboard and I can see the customer, subscription, etc. but the payment is blocked.
I would have thought the Stripe::CardError would catch this, but apparently not.
If a payment is blocked due to potential fraud, I don't want the user account to be created.
I want to treat it as a general card decline with appropriate error messages.
Is there another error I can rescue from or another way to do this? I can't find anything in Stripe's API about the best way to handle this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…