Prevent Stripe-based payment methods that are not linked to a StripeAccount from displaying in the checkout

This commit is contained in:
Rob Harrington
2017-09-22 16:24:15 +10:00
parent 7ba99c0fe0
commit 90007d7114
3 changed files with 17 additions and 7 deletions

View File

@@ -159,6 +159,8 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
gateway_customer_profile_id: "i_am_saved")
end
let!(:stripe_account) { create(:stripe_account, enterprise_id: distributor.id, stripe_user_id: 'some_id') }
let(:response_mock) { { id: "ch_1234", object: "charge", amount: 2000} }
before do

View File

@@ -222,30 +222,32 @@ describe EnterprisesHelper do
context "when StripeConnect payment methods are present" do
let!(:pm3) { create(:stripe_payment_method, distributors: [distributor], preferred_enterprise_id: distributor.id) }
let!(:pm4) { create(:stripe_payment_method, distributors: [distributor], preferred_enterprise_id: distributor.id) }
let!(:pm4) { create(:stripe_payment_method, distributors: [distributor], preferred_enterprise_id: some_other_distributor.id) }
let(:available_payment_methods) { helper.available_payment_methods }
before do
allow(helper).to receive(:current_distributor) { distributor }
pm4.update_attribute(:preferred_enterprise_id, nil)
end
context "and Stripe Connect is disabled" do
before { Spree::Config.set(stripe_connect_enabled: false) }
it "ignores Stripe payment methods" do
expect(helper.available_payment_methods.map(&:id)).to_not include pm3.id, pm4.id
expect(available_payment_methods).to_not include pm3, pm4
end
end
context "and Stripe Connect is enabled" do
let!(:stripe_account) { create(:stripe_account, enterprise_id: distributor.id) }
before do
Spree::Config.set(stripe_connect_enabled: true)
allow(Stripe).to receive(:publishable_key) { "some_key" }
end
it "includes Stripe payment methods with a preferred_enterprise_id" do
expect(helper.available_payment_methods.map(&:id)).to include pm3.id
expect(helper.available_payment_methods.map(&:id)).to_not include pm4.id
it "includes Stripe payment methods with a valid stripe accounts" do
expect(available_payment_methods).to include pm3
expect(available_payment_methods).to_not include pm4
end
end
end