Stripe Error

I'm getting this error: Stripe::InvalidRequestError in OrdersController#create You must supply either a card or a customer id begin charge = Stripe::Charge.create( :amount => (@order.amount * 100).floor, :currency => "usd", :card => token with charge = Stripe::Charge.create( highlighted I've checked and I think I set up everything like the tutorial. Interestingly, if I hit back after I get the error and re-submit the form, it works fine. This happens every time; one error, hit back, works fine. I've looked all over but haven't found a solution. Would really appreciate some guidance.

Posted almost 5 years ago by Markus Lopez
Posted almost 5 years ago by Alex Yang

The issue most likely doesn't have to do with the code that you've shown - it has to do with the token that you're generating. You're seeing the error because your 'token' variable isn't being set correctly. You'll be able to see that by typing 'puts "Token is #{token}' in your controller file, reproducing the error in your browser, and checking your Rails server. Your token is nil, so you should see "Token is" in your command line.

0
Posted almost 5 years ago by Markus Lopez

Thanks for the response. Sorry, but I need some further guidance on the token part. I've placed: puts 'Token is #{token}' at the top of my controller, but I don't see anything different in my browser or command line. The command line just says again "Stripe::InvalidRequestError (You must supply either a card or a customer id): app/controllers/orders_controller.rb:66:in `create' " with the error page in the browser looking the same

0
Posted almost 5 years ago by Alex Yang

Put it in your 'create' action instead, preferably right before 'begin'.

0
Posted almost 5 years ago by Markus Lopez

I did that. It is showing up in the command line just as: Token is #{token}. Sorry if I'm misunderstanding something. Also, after googling for over an hour, I think this error is related to JS. I really don't know what is causing it, but that seems to be a common theme with this error. I would appreciate any further guidance!

0
Posted almost 5 years ago by Alex Yang

Yeah, it's probably a JavaScript/CoffeeScript issue. I forgot to close the double-quotes above...it should be this:

puts "Token is #{token}"

0
Posted almost 5 years ago by Markus Lopez

Ok, trying what you just said gives me "Token is" and then a blank spot. So you were right about the token not being filled out. I'm wondering what's causing it not to be filled out. It's always just the first attempt, then when I hit back and try again it works. Could it be something with turbolinks? Any idea of anything else that could be messing with the JS/Coffeescript? My JS file is identical to the one in the tutorial. Thanks.

0
Posted almost 5 years ago by Alex Yang

Take another look at the 'Verify Credit Cards' and 'Charge Credit Cards' videos in the Etsydemo course and make sure you're setting up your CoffeeScript code as shown. You should also check that your tabbing/spacing is right. CoffeeScript is sensitive to indentation, so that could also be the problem.

0
Posted almost 5 years ago by Markus Lopez

I've removed turbolinks from my gem file and my application.js file. It's working fine now. So it seems like turbolinks was the issue. Not sure exactly why...but for now I will go without turbolinks

0