首页 > 解决方案 > 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 个空格^

这是配置变量 在此处输入图像描述

请帮我弄清楚,我确实花了一天时间试图解决这个问题

标签: ruby-on-railsrubyherokustripe-payments

解决方案


推荐阅读