stevec
stevec

Reputation: 52238

Where to set stripe API key in rails application?

I currently have this in every controller action that needs it (quite a few):

Stripe.api_key = Rails.application.credentials[Rails.env.to_sym][:stripe][:secret_stripe_test_key]

Where is the best place to put this code? The options that come to mind are:

What I currently have isn't DRY, so I figured there's got to be a better way.

Upvotes: 1

Views: 1471

Answers (2)

Stephane Paquet
Stephane Paquet

Reputation: 2344

I prefer the approach mentioned here Stripe on Ruby on Rails - Creating config/initializers/stripe.rb You can then have the values in environment variables. This is safer when in production

Upvotes: 1

Kamal Panhwar
Kamal Panhwar

Reputation: 2399

You can create an intializer file inside folder config/initializers/stripe.rb and put this key there

Stripe.api_key = Rails.application.credentials.stripe_secret_key

Upvotes: 4

Related Questions