Invalid API Key provided error using dotenv env for stripe

僤鯓⒐⒋嵵緔 提交于 2019-12-25 01:53:20

问题


I have my env file with the correct test codes. I then added the following to my stripe.rb:

Rails.configuration.stripe = {
  :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
  :secret_key      => ENV['STRIPE_SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]

In my env file:

export STRIPE_PUBLISHABLE_KEY=pk_test_x
export STRIPE_SECRET_KEY=sk_test_x

I tried with and without export and with and without quotations.

Then in the beginning of my stripe.js file

var stripe = Stripe("<%= ENV['STRIPE_PUBLISHABLE_KEY']%>");

I believe this is the issue because when I manually enter the stripe key in this stripe.js file, it works.

Is assets/javascript not reached by the env file, or what is happening that made the stripe key not going through?

Using js.erb works locally, but not in production on heroku. I tried:

gem 'dotenv-rails', groups: [:development, :test, :production]

and

Rails.application.config.assets.precompile << '*.js.erb'

Both do not work in production on heroku. The ENV isn't working and making it through to production.

来源:https://stackoverflow.com/questions/55370201/invalid-api-key-provided-error-using-dotenv-env-for-stripe

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