Rails: Cannot display Stripe::InvalidRequestError to user
我正在使用数据条作为支付网关(嵌入式表单)。它工作正常。
但是,我无法在我的网站上显示卡错误。
错误显示在动作控制器的错误页面上!
我的控制器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | def process begin customer = Stripe::Customer.create( :email => params[:stripeEmail], :source => params[:stripeToken] ) charge = Stripe::Charge.create( :customer => customer.id, :amount => totalprice, #Amount should be in cents :description => orderid, :currency => 'aud' ) rescue Stripe::CardError => e flash[:error]= e.message <-------------not working?! redirect_to root_url end showconfirmation end |
我想在我的网站上将条带错误显示为Flash消息。如何解决?
谢谢。
在您的代码中,您正在从
无效请求错误发生在您的请求具有无效参数时。请参阅Stripe API错误参考。
您必须确保发送正确的参数。或者,您可以根据需要从
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | begin customer = Stripe::Customer.create( :email => params[:stripeEmail], :source => params[:stripeToken] ) charge = Stripe::Charge.create( :customer => customer.id, :amount => totalprice, #Amount should be in cents :description => orderid, :currency => 'aud' ) rescue Stripe::CardError, Stripe::InvalidRequestError => e flash[:error]= e.message redirect_to root_url end |