Stripe: Invalid Request Error

Hi Alex, I am using your EtsyDemo tutorial and am having trouble on implementing the stripe functionality within my web app. I have gone thru the accept payments videos and am getting the error: Stripe::InvalidRequestError in OrdersController#create. Must provide source or customer. Do you know how to solve this? Is it something with the API keys from STRIPE? Thank you! Grace

Posted 8 months ago by Grace Saint
Posted 8 months ago by Alex Yang

The issue is either that:

1) the Stripe token that should be generated from your CoffeeScript file isn't being passed into your controller file. Try adding a 'puts params[:stripeToken]' line at the top of your controller action. If you see this value printed in your Rails server, then you should be fine.

2) You're missing some other piece of information when you're actually making your Stripe call.

Most likely, the issue has to do with #1. Try it out, and let me know if you need more help.

1
Posted 8 months ago by Grace Saint

Thank you for your quick response! I put that line of code in the create action, right before begin and the value wasn't printed in my rails server. So since that aspect isn't working, what else should I try?

1
Posted 8 months ago by Grace Saint

Do you think it could have something to do with my figaro keys in the application.yml file?

1
Posted 8 months ago by Alex Yang

It's possible. Are you finding that the code works in one environment (e.g. development / localhost), but not in another (e.g. production / Heroku)?

1
Posted 8 months ago by Grace Saint

I am developing my application in Cloud9 and running a preview live view of it, which is where I am testing my code. I'm not using Heroku, but am committing my code to GitHub.

1
Posted 8 months ago by Alex Yang

I see. Just as confirmation, that means if you look in your Rails server, you should not see a stripeToken as one of the passed parameters? That means the issue is further upstream, probably in your CoffeeScript code. Did you check that the code is able to generate a token from Stripe? The best way to test this is by using the alert method from the Verify Credit Card Data video.

1
Posted 8 months ago by Grace Saint

I don't see striped token in my passed parameters in my rails server, but maybe I'm not looking correctly. Here is what I have in my terminal: Started POST "/orders" for 163.120.56.210 at 2018-04-30 16:01:58 +0000
Cannot render console from 163.120.56.210! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by OrdersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"A7QBH94iF32OpeGrpeuVdXdjjZ7b/NKFcJ4Hr0VFeqUvOB1zDHCVxGJhWNKDqWuT0+/o+GLUTtezcdseQGr4/Q==", "order"=>{"user_id"=>"1", "status"=>"Submitted", "street"=>"123 Fake Street", "city"=>"Los Angeles", "state"=>"CA"}, "commit"=>"Complete Order"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Completed 500 Internal Server Error in 347ms (ActiveRecord: 4.5ms)



Stripe::InvalidRequestError (Must provide source or customer.):

app/controllers/orders_controller.rb:40:in `create'

1
Posted 8 months ago by Alex Yang

You're right. There's no stripeToken (you would see it here as an additional parameter), which means that the issue is definitely in your CoffeeScript code. Use the alert method I suggested - this will work in any testing environment as it makes sure that your CoffeeScript code works on both successful credit card inputs and incorrect ones.

1
Posted 8 months ago by Grace Saint

Okay great, thank you!

1