Liz
Liz

Reputation: 1437

Rails: Stripe on Heroku Stuck on Test Mode

I have Stripe set up on my app so that it works perfectly on localhost and Heroku in test mode. I have since switched to live mode on Stripe, as well as updating my stripe_api_key and stripe_publishable_key using these steps from the Stripe documentation:

heroku config:set PUBLISHABLE_KEY=pk_live_... SECRET_KEY=sk_live_...

I also did this with stripe_api_key and stripe_publishable_key, as I have seen that in other documentation and wanted to cover my bases.

I have the following in my application.example.yml:

stripe_api_key:
stripe_publishable_key:

production:
  stripe_api_key:
  stripe_publishable_key:

SENDGRID_USERNAME:
SENDGRID_PASSWORD:

AWS_ACCESS_KEY_ID:
AWS_REGION:
AWS_SECRET_ACCESS_KEY:
S3_BUCKET_NAME:

And the application.yml has the corresponding information. My stripe.rb looks like this:

Rails.configuration.stripe = {
  :publishable_key => Rails.application.secrets.publishable_key,
  :secret_key      => Rails.application.secrets.secret_key
}

Stripe.api_key = Rails.configuration.stripe[:secret_key]

Can anyone see why Stripe is still running on Test mode on the production server on Heroku?

Upvotes: 1

Views: 638

Answers (2)

Liz
Liz

Reputation: 1437

I ended up getting rid of Figaro/application.yml altogether and restructuring my secrets.yml file to have the following structure for staging/production:

# Do not keep production secrets in the repository,
# instead read values from the environment.
staging:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
  sendgrid_username: <%= ENV["SENDGRID_USERNAME"] %>
  sendgrid_password: <%= ENV["SENDGRID_PASSWORD"] %>

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  stripe_api_key: <%= ENV["STRIPE_API_KEY"] %>
  stripe_publishable_key: <%= ENV["STRIPE_PUBLISHABLE_KEY"] %>
  sendgrid_username: <%= ENV["SENDGRID_USERNAME"] %>
  sendgrid_password: <%= ENV["SENDGRID_PASSWORD"] %>

After this everything worked properly.

Upvotes: 1

m3characters
m3characters

Reputation: 2290

When you do this:

heroku config:set PUBLISHABLE_KEY=pk_live_... SECRET_KEY=sk_live_...

You're setting two ENV vars on your heroku environment, which will be accessible in rails as ENV['PUBLISHABLE_KEY'] and ENV['SECRET_KEY'].

You can also see what ENV variables you have set, access them, remove them, or change their values, by visiting your heroku dashboard, your app, and then Settings and clicking Reveal Config Vars.

You only need to define them in stripe.rb

Rails.configuration.stripe = {
  :publishable_key => ENV['PUBLISHABLE_KEY'],
  :secret_key      => ENV['SECRET_KEY']
}

or if you want to use your secrets, changing this on your secrets.yml

production:
  stripe_api_key: <%= ENV['PUBLISHABLE_KEY'] %>
  stripe_publishable_key: <%= ENV['SECRET_KEY'] %>

And leaving your stripe.rb as was before.

I would still change your ENV variable names to be more specific, like STRIPE_PUBLISHABLE_KEY & STRIPE_SECRET_KEY.

Upvotes: 0

Related Questions