问题
I can't get my head around this one.
My form passes a params of 106
which is £1.06
.
Charging the card:
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
How to prevent:
Invalid integer: 1.06
Where does the integer comes from? I have converted that to float
.
回答1:
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
来源:https://stackoverflow.com/questions/36837952/stripe-rails-invalid-integer-1-06