From dfb18af971269bb9a836b9a404e58990ade6dbb2 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 5 Feb 2024 15:48:29 +0000 Subject: [PATCH] Improves Stripe api.key declaration --- config/initializers/stripe.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb index 56cf923fd6..37871eb00a 100644 --- a/config/initializers/stripe.rb +++ b/config/initializers/stripe.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add some additional properties, to allow us to access these # properties from the object, rather than calling from ENV directly. # This is mostly useful for stubbing when testing, but also feels @@ -11,9 +13,13 @@ module Stripe end Rails.application.reloader.to_prepare do - Stripe.api_key = ENV['STRIPE_INSTANCE_SECRET_KEY'] - Stripe.api_key = ENV['STRIPE_SECRET_TEST_API_KEY'] if Rails.env.test? || ENV["CI"] - Stripe.publishable_key = ENV['STRIPE_INSTANCE_PUBLISHABLE_KEY'] - Stripe.client_id = ENV['STRIPE_CLIENT_ID'] - Stripe.endpoint_secret = ENV['STRIPE_ENDPOINT_SECRET'] -end \ No newline at end of file + Stripe.api_key = if Rails.env.test? || ENV["CI"] + ENV.fetch('STRIPE_SECRET_TEST_API_KEY', nil) + else + ENV.fetch('STRIPE_INSTANCE_SECRET_KEY', nil) + end + + Stripe.publishable_key = ENV.fetch('STRIPE_INSTANCE_PUBLISHABLE_KEY', nil) + Stripe.client_id = ENV.fetch('STRIPE_CLIENT_ID', nil) + Stripe.endpoint_secret = ENV.fetch('STRIPE_ENDPOINT_SECRET', nil) +end