条纹 Rails:无效整数:1.06
Stripe Rails: Invalid integer: 1.06
我无法理解这个问题。
我的表单传递了 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]
作为 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
我无法理解这个问题。
我的表单传递了 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]
作为 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