【发布时间】:2016-04-25 12:12:33
【问题描述】:
我们遇到了 Stripe API 密钥的问题。到目前为止我所做的是:
- 设置 environment/*.rb 以使用常量使用适当的 Stripe 键
- 使用
Stripe.api_key = STRIPE_SECRET行创建了config/initializers/stripe.rb - 使用rails 控制台,
STRIPE_PUBLIC和STRIPE_SECRET常量都被设置并且可见。STRIPE_PUBLIC => "pk_test_xxxxxxxxx"
但是,一旦这些事情都到位,使用浏览器调用 Stripe 的 API 会导致:
Stripe::AuthenticationError in some_controller#some_action
No API key provided. Set your API key using "Stripe.api_key = <API-KEY>". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions.
使用 web-console gem,我们可以看出 STRIPE_SECRET 和 STRIPE_PUBLIC 在网站中是 nil。但是每次我们运行 rails console 时,我们都会从常量中获取密钥。
【问题讨论】:
-
你们在同一个环境中运行吗?也许您已将密钥添加到“environments/development.rb”而不是“environments/production.rb”?
-
environments/production.rb有STRIPE_SECRET = ENV['LIVE_STRIPE_SECRET']和一个 _PUBLIC 版本。environments/development.rb和environements/test.rb都有STRIPE_SECRET = ENV['TEST_STRIPE_SECRET']和 _PUBLIC 版本。
标签: ruby-on-rails ruby api stripe-payments