diff --git a/app/views/admin/stripe_connect_settings/edit.html.haml b/app/views/admin/stripe_connect_settings/edit.html.haml index d004d65f0e..43d90b4574 100644 --- a/app/views/admin/stripe_connect_settings/edit.html.haml +++ b/app/views/admin/stripe_connect_settings/edit.html.haml @@ -44,7 +44,7 @@ = @obfuscated_secret_key .publishable_key %strong= t('.instance_publishable_key') + ":" - = ENV["STRIPE_INSTANCE_PUBLISHABLE_KEY"] + = Stripe.publishable_key - if !@stripe_account[:charges_enabled] .alert-box.warning = t(".charges_enabled_warning") diff --git a/app/views/checkout/_payment.html.haml b/app/views/checkout/_payment.html.haml index e7b29c7635..3ac4b8cdf9 100644 --- a/app/views/checkout/_payment.html.haml +++ b/app/views/checkout/_payment.html.haml @@ -1,6 +1,6 @@ %fieldset#payment :javascript - angular.module('Darkswarm').value("stripeObject", Stripe("#{ENV['STRIPE_INSTANCE_PUBLISHABLE_KEY']}")) + angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) %ng-form{"ng-controller" => "PaymentCtrl", name: "payment"} %h5{"ng-class" => "{valid: payment.$valid, dirty: payment.$dirty || submitted}"} diff --git a/app/views/spree/users/show.html.haml b/app/views/spree/users/show.html.haml index 29c213145d..aae16de24f 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -4,7 +4,7 @@ = inject_saved_credit_cards :javascript - angular.module('Darkswarm').value("stripeObject", Stripe("#{ENV['STRIPE_INSTANCE_PUBLISHABLE_KEY']}")) + angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) .row.pad-top .small-12.columns.pad-top diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb index 64bda99d91..c7ec6599d8 100644 --- a/config/initializers/stripe.rb +++ b/config/initializers/stripe.rb @@ -1,2 +1,13 @@ +# Add the :publishable_key property, to allow us to access this +# property from the object, rather than calling from ENV directly. +# This is mostly useful for stubbing when testing, but also feels +# a bit cleaner than accessing keys in different ways. +module Stripe + class << self + attr_accessor :publishable_key + end +end + Stripe.api_key = ENV['STRIPE_INSTANCE_SECRET_KEY'] +Stripe.publishable_key = ENV['STRIPE_INSTANCE_PUBLISHABLE_KEY'] Stripe.client_id = ENV['STRIPE_CLIENT_ID']