Stripe Rails:无效整数:1.06 [英] Stripe Rails: Invalid integer: 1.06
本文介绍了Stripe Rails:无效整数:1.06的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法理解这个.
我的表单传递了 106
的参数,即 £1.06
.
My form passes a params of 106
which is £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
.
Where does the integer comes from? I have converted that to float
.
推荐答案
根据 Stripe API 参考数量参数应该是整数,它被认为是美分.所以你应该直接传递 params[:amount]
作为数量.
According to Stripe API Reference amount parameter should be integer and it is perceived as cents. So you should pass params[:amount]
directly as 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
这篇关于Stripe Rails:无效整数:1.06的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文