Initialize Stripe object only if a publishable_key has been defined

This commit is contained in:
Rob Harrington
2017-08-30 16:06:50 +10:00
parent 65ab83a9a5
commit 69385370ee
6 changed files with 17 additions and 7 deletions

View File

@@ -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)

View File

@@ -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}"}

View File

@@ -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" }

View File

@@ -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").

View File

@@ -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))

View File

@@ -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