Ruby on rails Rails:无法向用户显示条带::InvalidRequestError

Ruby on rails Rails:无法向用户显示条带::InvalidRequestError,ruby-on-rails,ruby,ruby-on-rails-4,stripe-payments,Ruby On Rails,Ruby,Ruby On Rails 4,Stripe Payments,我使用stripe作为支付网关(嵌入式表单)。它运行良好 但是,我不能在我的网站上显示卡片错误。 动作控制器的错误页面中显示的错误 我的控制器 def process begin customer = Stripe::Customer.create( :email => params[:stripeEmail], :source => params[:stripeToken] ) charge = Stripe::Charge.create(

我使用stripe作为支付网关(嵌入式表单)。它运行良好

但是,我不能在我的网站上显示卡片错误。 动作控制器的错误页面中显示的错误

我的控制器

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
def过程
开始
customer=Stripe::customer.create(
:email=>params[:stripeEmail],
:source=>params[:stripeToken]
)
charge=Stripe::charge.create(
:customer=>customer.id,
:amount=>totalprice,#金额应以美分为单位
:description=>orderid,
:货币=>“澳元”
)
救援条带::CardError=>e

flash[:error]=e.message在您的代码中,您正在从
条带::卡片错误
中解救,但最初您得到了一个
条带::InvalidRequestError
。所以,这就是为什么你的代码不能从错误中拯救出来

当您的请求包含无效参数时,会出现无效请求错误。看

您必须确保发送的参数正确。或者,您可以根据需要从
Stripe::InvalidRequestError
中拯救:

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