RailsApps / rails-stripe-membership-saas

An example Rails 4.2 app with Stripe and the Payola gem for a membership or subscription site.
http://railsapps.github.io/rails-stripe-membership-saas
1.14k stars 232 forks source link

Stripe::AuthenticationError #152

Open lgs opened 9 years ago

lgs commented 9 years ago

After building with

rails new rails-stripe-membership-saas -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

I get the following error:

lsoave@basenode:~/test/rails-stripe-membership-saas$  rake db:seed
CREATED ADMIN USER: user@example.com
rake aborted!

Stripe::AuthenticationError: You did not provide an API key, though you did set your Authorization header to "Bearer". Using Bearer auth, your Authorization header should look something like 'Authorization: Bearer YOUR_SECRET_KEY'. See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.

even if Linux env and rails config/secrets.yml seem fine:

lsoave@basenode:~/test/rails-stripe-membership-saas$ echo $STRIPE_API_KEY
sk_test_34875ygojg45oj4g5o1j34g34ljr5
lsoave@basenode:~/test/rails-stripe-membership-saas$ echo $STRIPE_PUBLISHABLE_KEY
pk_test_l3k4j5;1k3jhnr514kjn5nrlk4nlknrtnnn
lsoave@basenode:~/test/rails-stripe-membership-saas$ grep -i STRIPE config/secrets.yml 
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %> 
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %> 
DanielKehoe commented 9 years ago

That's odd. Thanks for providing the diagnostic detail. It looks like it should be fine. Try hardcoding the keys into the config/secrets.yml file (temporarily, don't check in to Git).

I've just attempted generating the app Using Rails Composer and running rake db:reset and it works here with my ENV settings. So I suspect you have a local configuration issue.

lgs commented 9 years ago

@DanielKehoe you were right, hardcoding Stripe keys into the config/secrets.yml make it working, then I guess is something "local env" related, may be something to do with my ssl localhost configuration and the fact that I go with https://localhost:3000/ ? ... need more investigation.

archonic commented 9 years ago

I also had to hardcode keys in to secrets.yml. It looks like ENV isn't working for a lot of people.

kathyonu commented 9 years ago

@lgs @archonic @DanielKehoe @tmock12 The single finest answer to these questions rests here Rails Environmental Variables authored by Taylor Mock and Daniel Kehoe, last updated 20121215. Also, I will share what I have done so far to make environmental variables easy peasy. My opinion is after working all methods described in the articles is : the config/local_env.yml is the tool of choice especially if you are dealing with lots of apps, lots of repositories. It takes a minute maybe two to set up the local_env.yml file, making certain you .gitignore it because this local_env.yml file holds the crown jewels of all passwords, secret keys, etc., and make the addition of a code block in your config/application.rb file, and bham! problem solved forever on that app. And, these tests on the two tests making sure the Stripe keys are in place will pass every time. Next app, set it up the way you need and want with its own local_env.yml file in each app complete unto itself. Please note, the reference article gives a thumbs up to Figaro gem. I abandoned that gem quite a while ago, due to exact changes I cannot recall where Figaro was unuseful in terms of setting env variables on Heroku. I set the Heroku variables directly with $ heroku config add commands, one time, it is done, so no need for Figaro. I would be happy indeed to write these codes into the rails-stripe-membership-saas app, so that everyone can enjoy trouble free environment variables in development and test.

kathyonu commented 9 years ago

@lgs @archonic @DanielKehoe @tmock12 The two tests I mentioned are located here : https://github.com/kathyonu/rails-stripe-membership-saas/blob/testsformaster/spec/stripe/stripe_config_spec.rb

Please do note this is the testsformaster branch of my fork of the app. This branch contains a boatload of /spec tests you may find useful. They are all part of the open pull request on this branch. More tests are coming because my personal goal is 100% tests coverage of our production app, and i have found it is pretty easy to adapt those tests to the rails-stripe-membership-saas app and contribute them to RailsApps.

lgs commented 9 years ago

@kathyonu very useful, many thanks! @DanielKehoe +1 to commit that pull request #150 (even if I'd preferred pure minitest)

kathyonu commented 9 years ago

@lgs many welcomes @DanielKehoe i do believe this is my first +1, and have no clue what the full import of that is, butt-ha, i sure Love the idea of bringing these tests-works to fruition in the master so folks can learn to test their way out of problems and into new capabilities.