From c35c003e5a37d6601e91fa7b806d904d59c1f3ba Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 17 Nov 2022 11:59:54 +0100 Subject: [PATCH 1/3] load exclusively the payment methods that are available on the distributor --- app/services/order_available_payment_methods.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/services/order_available_payment_methods.rb b/app/services/order_available_payment_methods.rb index 0e89825723..e7f9d1a3ff 100644 --- a/app/services/order_available_payment_methods.rb +++ b/app/services/order_available_payment_methods.rb @@ -30,8 +30,13 @@ class OrderAvailablePaymentMethods distributor.payment_methods else distributor.payment_methods.where( - id: order_cycle.distributor_payment_methods.select(:payment_method_id) + id: available_distributor_payment_methods_ids ) end.available.select(&:configured?) end + + def available_distributor_payment_methods_ids + order_cycle.distributor_payment_methods.where(distributor_id: distributor.id) + .select(:payment_method_id) + end end From e20e519201f8b8fdc2f902d068ecf493b1bbc856 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Fri, 25 Nov 2022 10:01:51 +0100 Subject: [PATCH 2/3] test when two distributors support the same PMs, and only one PM is checked for a distributor in the OC --- .../order_available_payment_methods_spec.rb | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/services/order_available_payment_methods_spec.rb b/spec/services/order_available_payment_methods_spec.rb index a8e4fedb45..8f3983b826 100644 --- a/spec/services/order_available_payment_methods_spec.rb +++ b/spec/services/order_available_payment_methods_spec.rb @@ -214,4 +214,28 @@ describe OrderAvailablePaymentMethods do end end end + + context "when two distributors implement the same payment methods" do + context "only one distributor supports the two payment methods in the order cycle" do + let(:oc){ create(:order_cycle) } + let(:payment_method){ create(:payment_method) } + let(:payment_method2){ create(:payment_method) } + let(:d1){ oc.distributors.first } + let(:d2){ oc.distributors.second } + before { + d1.payment_methods << payment_method + d1.payment_methods << payment_method2 + d2.payment_methods << payment_method + d2.payment_methods << payment_method2 + oc.selected_distributor_payment_methods << d1.distributor_payment_methods.first + oc.selected_distributor_payment_methods << d1.distributor_payment_methods.second + oc.selected_distributor_payment_methods << d2.distributor_payment_methods.first + } + it do + order = build(:order, distributor: d2, order_cycle: oc) + order_available_payment_methods = OrderAvailablePaymentMethods.new(order).to_a + expect(order_available_payment_methods).to eq([d2.payment_methods.first]) + end + end + end end From 9fbdb311b0c864701cb3bce39e6e13cd292d853c Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Sat, 10 Dec 2022 11:51:35 +0100 Subject: [PATCH 3/3] Update app/services/order_available_payment_methods.rb Co-authored-by: jibees --- app/services/order_available_payment_methods.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/services/order_available_payment_methods.rb b/app/services/order_available_payment_methods.rb index e7f9d1a3ff..c3f71cc1da 100644 --- a/app/services/order_available_payment_methods.rb +++ b/app/services/order_available_payment_methods.rb @@ -36,7 +36,8 @@ class OrderAvailablePaymentMethods end def available_distributor_payment_methods_ids - order_cycle.distributor_payment_methods.where(distributor_id: distributor.id) + order_cycle.distributor_payment_methods + .where(distributor_id: distributor.id) .select(:payment_method_id) end end