Stripe “Invalid API Key Provided”

大城市里の小女人 提交于 2020-01-24 05:30:11

问题


I have followed Stripe's Rails tutorial (https://stripe.com/docs/checkout/guides/rails) exactly (copy and pasted code), but when I run rails

PUBLISHABLE_KEY=pk_foo SECRET_KEY=sk_bar rails s 

and go to localhost:3000/charges/new and fill out the fields with the test card data (card number "4242 4242 4242 4242"), but I get an

Invalid API Key provided: ***********_***

Any ideas why this is happening?


回答1:


You need to plug in your publishable key and secret key; pk_foo and sk_bar are placeholders. (Unlike the API docs, the Checkout tutorial doesn't use information from your account.)

You can get them from the API Keys tab of Your Account.

i.e. for a secret key of Sk123456 and a publishable key of pk_987654, you'd issue:

PUBLISHABLE_KEY=pk_987654 SECRET_KEY=Sk123456 rails s

If that still doesn't work there are a couple things to check:

  • Are both keys from the same environment (test or live)? Occasionally people mix the two together.
  • If you load a Rails console instead of a Rails server, can you access those environment variables with ENV['PUBLISHABLE_KEY'] and ENV['SECRET_KEY']?
  • If you're using multiple APIs, it's possible you have some kind of collision occurring; you might try adjusting the command-line and the code to STRIPE_PUBLISHABLE_KEY and STRIPE_SECRET_KEY.


来源:https://stackoverflow.com/questions/19216508/stripe-invalid-api-key-provided

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!