【发布时间】:2016-08-18 16:32:43
【问题描述】:
我无法理解这个。
我的表单传递了106 的参数,即£1.06。
给卡充电:
amount = params[:amount].to_f
begin
charge = Stripe::Charge.create(
:amount => amount / 100,
:currency => "gbp",
:source => token,
:description => "Example charge"
)
rescue Stripe::CardError => e
# The card has been declined
end
如何预防:
无效整数:1.06
整数从何而来?我已将其转换为float。
【问题讨论】:
-
如果没有更多信息,我无法确切地说出发生了什么......但看起来在某个地方,您的代码期望
amount成为Integer(而您正在给它Float)。我的第一个猜测是在Stripe::Charge模型中,您有一个rails 验证,它检查该值是否为整数?或者数据库表列类型可能是integer? -
如果我删除
.to_f,条纹将收取 106 英镑而不是 1.06 英镑。我的 js 没问题,因为它传递的参数是106。稍后我将重新启动此服务器。 -
能否请您发布 params[:amount] 值
标签: ruby-on-rails ruby stripe-payments