diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 1b5f54a84c..37df04b685 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -21,7 +21,9 @@ module EnterprisesHelper def available_payment_methods return [] unless current_distributor.present? payment_methods = current_distributor.payment_methods.available(:front_end).all - payment_methods.reject!{ |p| p.type.ends_with? "StripeConnect" } unless Spree::Config.stripe_connect_enabled + + stripe_enabled = Spree::Config.stripe_connect_enabled && Stripe.publishable_key + payment_methods.reject!{ |p| p.type.ends_with? "StripeConnect" } unless stripe_enabled applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterPaymentMethods", current_customer.andand.tag_list) applicator.filter!(payment_methods) diff --git a/app/views/checkout/_payment.html.haml b/app/views/checkout/_payment.html.haml index 3ac4b8cdf9..ab3ad309be 100644 --- a/app/views/checkout/_payment.html.haml +++ b/app/views/checkout/_payment.html.haml @@ -1,6 +1,8 @@ %fieldset#payment - :javascript - angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) + - if Stripe.publishable_key + :javascript + 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 aae16de24f..23de4fd744 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -3,8 +3,9 @@ = inject_shops = inject_saved_credit_cards - :javascript - angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) + - if Stripe.publishable_key + :javascript + angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) .row.pad-top .small-12.columns.pad-top @@ -21,7 +22,7 @@ .row.tabset-ctrl#account-tabs{ style: 'margin-bottom: 100px', navigate: 'true', selected: 'orders', prefix: 'account' } .small.12.medium-3.columns.tab{ name: "orders" } %a{ href: 'javascript:void(0)' }=t('.tabs.orders') - - if Spree::Config.stripe_connect_enabled + - if Spree::Config.stripe_connect_enabled && Stripe.publishable_key .small.12.medium-3.columns.tab{ name: "cards" } %a{ href: 'javascript:void(0)' }=t('.tabs.cards') .small.12.medium-3.columns.tab{ name: "transactions" } diff --git a/spec/features/consumer/account/cards_spec.rb b/spec/features/consumer/account/cards_spec.rb index 590c67d42b..2482d2b956 100644 --- a/spec/features/consumer/account/cards_spec.rb +++ b/spec/features/consumer/account/cards_spec.rb @@ -10,6 +10,7 @@ feature "Credit Cards", js: true do quick_login_as user allow(Stripe).to receive(:api_key) { "sk_test_xxxx" } + allow(Stripe).to receive(:publishable_key) { "some_token" } Spree::Config.set(stripe_connect_enabled: true) stub_request(:get, "https://api.stripe.com/v1/customers/cus_AZNMJ"). diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index a5da47e8ef..debcfabf15 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -158,6 +158,7 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do before do allow(Stripe).to receive(:api_key) { "sk_test_12345" } + allow(Stripe).to receive(:publishable_key) { "some_key" } Spree::Config.set(stripe_connect_enabled: true) stub_request(:post, "https://sk_test_12345:@api.stripe.com/v1/charges") .to_return(body: JSON.generate(response_mock)) diff --git a/spec/helpers/enterprises_helper_spec.rb b/spec/helpers/enterprises_helper_spec.rb index 2aa9131942..ac2307f94f 100644 --- a/spec/helpers/enterprises_helper_spec.rb +++ b/spec/helpers/enterprises_helper_spec.rb @@ -233,7 +233,10 @@ describe EnterprisesHelper do end context "and Stripe Connect is enabled" do - before { Spree::Config.set(stripe_connect_enabled: true) } + before do + Spree::Config.set(stripe_connect_enabled: true) + allow(Stripe).to receive(:publishable_key) { "some_key" } + end it "includes the Stripe payment method" do expect(helper.available_payment_methods.map(&:id)).to include pm3.id