我无法理解这个问题。
我的表单传递了 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
如何预防:
Invalid integer: 1.06
整数从何而来?我已将其转换为 float
。
最佳答案
根据 Stripe API Reference amount 参数应该是整数,它被认为是美分。因此,您应该将 params[:amount]
直接作为金额传递。
begin
charge = Stripe::Charge.create(
:amount => params[:amount],
:currency => "gbp",
:source => token,
:description => "Example charge"
)
rescue Stripe::CardError => e
# The card has been declined
end
关于ruby-on-rails - Stripe rails : Invalid integer: 1. 06,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36837952/