ruby-on-rails - Ruby on Rails - Stripe - Heroku - 没有提供 Stripe api_key
问题描述
Pay::Stripe::Error (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.)
很确定我已经将这个 api 密钥添加到每个可能的地方,可能我是盲人什么的。Stripe 在开发过程中没有任何错误,但在生产过程中不断出现同样的错误。
配置/初始化程序/stripe.rb
if Rails.env.test? || Rails.env.development?
Stripe.api_key = Rails.application.credentials.dig(:stripe, :private_key)
end
if Rails.env.production?
Rails.configuration.stripe = {
:publishable_key => ENV['PUBLISHABLE_KEY'],
:secret_key => ENV['PRIVATE_KEY']
}
Stripe.api_key = Rails.application.secrets.private_key
end
配置/secrets.yml
production:
secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
private_key: <%= ENV['PRIVATE_KEY'] %>
public_key: <%= ENV['PUBLISHABLE_KEY'] %>
导轨凭据:
stripe:
public_key: pk_test_xxx
private_key: sk_test_xxx
在 rails 凭据中使用 2 个空格^
请帮我弄清楚,我确实花了一天时间试图解决这个问题
解决方案
推荐阅读
- python - 如何使用openCV检测脸颊?
- google-apps-script - 如何总结每列中的值并通过谷歌表中的值总和对每列名称进行排名
- azure - 带有实体框架的 Service Fabric 应用程序?
- c# - 在 Unity C# 脚本中向 localhost 发出 GET 请求
- python - 简化许多 if 语句
- postgresql - 在其中一列的值重复 1-300 次以上的情况下,存储数据的最佳方法是什么?
- c# - 以编程方式更改按钮背景不起作用
- wpf - 在 wpf 组件中使用哪种布局来设计 UI?
- reactjs - 如何动态确定反应组件的 propTypes?
- elixir - 您可以将自定义路由助手功能添加到 Phoenix Router.Helpers 吗?