ruby on rails - When stripe verification fails why am I not being shown a flash? -


for example, if purposely make card decline, shown error page. so: enter image description here instead of error page want notified flash instead. have below code, why not alerted using flash?

class chargescontroller < applicationcontroller     def new       end       def create     # amount in cents     @amount = 100      # credit card details submitted form     customer = stripe::customer.create(         :email => params[:email],         :source  => params[:stripetoken]     )      # create charge on stripe's servers - charge user's card     begin       stripe::charge.create(           :amount => @amount,           :currency => 'usd',           :customer => customer.id,           :description => 'example charge custom form'       )        current_user.subscribed = true       current_user.stripe_id = customer.id       current_user.expiry_date = date.today + 30.days       current_user.save         flash[:success] = "thank subscribing. account has been unlocked."       redirect_to root_path        rescue stripe::carderror => e       flash[:error] = e.message       redirect_to root_path     end   end  end 

can please try one, see result.

don't put flash or redirection. use raise or else see code caught.

begin   # use stripe's library make requests... rescue stripe::carderror => e   # since it's decline, stripe::carderror caught  rescue stripe::ratelimiterror => e   # many requests made api rescue stripe::invalidrequesterror => e   # invalid parameters supplied stripe's api rescue stripe::authenticationerror => e   # authentication stripe's api failed   # (maybe changed api keys recently) rescue stripe::apiconnectionerror => e   # network communication stripe failed rescue stripe::stripeerror => e   # display generic error user, , maybe send   # email rescue => e   # else happened, unrelated stripe end 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -