Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe API key missing Rails

We're facing a problem with Stripe API keys. What I've done so far is:

  • set environment/*.rb to utilise appropriate Stripe keys using constants
  • created a config/initializers/stripe.rb with the line Stripe.api_key = STRIPE_SECRET
  • using the rails console, both STRIPE_PUBLIC and STRIPE_SECRET constants are set and visible. STRIPE_PUBLIC => "pk_test_xxxxxxxxx"

However, once these things are in place, making a call to Stripe's API using the browser results in:

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 [email protected] if you have any questions.

Using the web-console gem, we can tell that STRIPE_SECRET and STRIPE_PUBLIC are nil in the website. But every time we run rails console we get our keys from our constants.

like image 509
fbelanger Avatar asked Mar 30 '26 16:03

fbelanger


1 Answers

I fixed my issue. The terminal running rails server had been opened since before the environment variables had been set.

Therefore, running source ~/.bashrc (for me) or using a new terminal worked for me.

Thank you, sincerely, to everyone who tried to help!

like image 59
fbelanger Avatar answered Apr 02 '26 07:04

fbelanger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!