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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With