问题
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