条纹“提供的 API 密钥无效" [英] Stripe "Invalid API Key Provided"

查看:44
本文介绍了条纹“提供的 API 密钥无效"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了 Stripe 的 Rails 教程 (https://stripe.com/docs/checkout/guides/rails) 完全正确(复制和粘贴代码),但是当我运行 rails

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 

然后转到 localhost:3000/charges/new 并使用测试卡数据(卡号4242 4242 4242 4242")填写字段,但我得到一个

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: ***********_***

知道为什么会这样吗?

推荐答案

您需要插入您的可发布密钥和秘密密钥;pk_foosk_bar 是占位符.(与 API 文档不同,Checkout 教程不使用您帐户中的信息.)

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.)

您可以从您帐户的API 密钥标签中获取它们.

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

即对于 Sk123456 的密钥和 pk_987654 的可发布密钥,您将发出:

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:

  • 两个密钥是否来自同一环境(测试或实时)?有时人们会将两者混合在一起.
  • 如果您加载 Rails 控制台而不是 Rails 服务器,您是否可以使用 ENV['PUBLISHABLE_KEY']ENV['SECRET_KEY'] 访问这些环境变量?
  • 如果您使用多个 API,则可能会发生某种冲突;您可以尝试将命令行和代码调整为 STRIPE_PUBLISHABLE_KEY 和 STRIPE_SECRET_KEY.
  • 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.

这篇关于条纹“提供的 API 密钥无效"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆