I'm trying to create a one time, single charge in Stripe with Rails. I am getting the following error:
Stripe::InvalidRequestError (No such token: tok_18nnwSJ6tVEvTdcVs3dNIhGs)
However, as can clearly be seen in the photo, the token is in the parameters. That token is from Stripe.js.
Here is my code in my controller:
Stripe.api_key = "xxxxxxxxxxx"
customer = Stripe::Customer.create(source: params[:stripeToken])
charge = Stripe::Charge.create({
:amount => 10000,
:currency => "usd",
:customer => customer.id,
:description => "Example charge"
})
I have also tried:
Stripe.api_key = "xxxxxxxxxxx"
charge = Stripe::Charge.create({
:amount => 10000,
:currency => "usd",
:source => params[:stripeToken],
:description => "Example charge"
})
And that does not work either. All of this is simple, boilerplate code straight from the Stripe site, any idea what I could be doing wrong? I'm not having any trouble with the Stripe embedded form.
I had been facing same issue for my test environment and the mistake i had been doing, i was adding the token received by Strip like this one tok_18nnwSJ6tVEvTdcVs3dNIhGs , for the test environment we have to use 'tok_visa' in source.
Here is the list of test sources provided by Stripe. https://stripe.com/docs/testing#cards
It created customer for me, let me know if it helped anyone else as well.
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