mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
Prevent Stripe-based payment methods that are not linked to a StripeAccount from displaying in the checkout
This commit is contained in:
@@ -2,7 +2,7 @@ module OpenFoodNetwork
|
||||
class AvailablePaymentMethodFilter
|
||||
def filter!(payment_methods)
|
||||
if stripe_enabled?
|
||||
payment_methods.reject!{ |p| p.type.ends_with?("StripeConnect") && p.preferred_enterprise_id.zero? }
|
||||
payment_methods.reject!{ |p| p.type.ends_with?("StripeConnect") && stripe_configuration_incomplete?(p) }
|
||||
else
|
||||
payment_methods.reject!{ |p| p.type.ends_with?("StripeConnect") }
|
||||
end
|
||||
@@ -13,5 +13,11 @@ module OpenFoodNetwork
|
||||
def stripe_enabled?
|
||||
Spree::Config.stripe_connect_enabled && Stripe.publishable_key
|
||||
end
|
||||
|
||||
def stripe_configuration_incomplete?(payment_method)
|
||||
return true if payment_method.preferred_enterprise_id.zero?
|
||||
|
||||
payment_method.stripe_account_id.blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user