Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails/Stripe: No such token

I'm trying to create a one time, single charge in Stripe with Rails. I am getting the following error:

enter image description here

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.

like image 712
jjjjjjjj Avatar asked Aug 29 '16 11:08

jjjjjjjj


1 Answers

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.

like image 154
Hamza Khan Avatar answered Oct 16 '22 03:10

Hamza Khan