Class: SpreeCmCommissioner::PaymentMethods::GroupByBank
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::PaymentMethods::GroupByBank
- Defined in:
- app/finders/spree_cm_commissioner/payment_methods/group_by_bank.rb
Instance Method Summary collapse
- #execute(payment_methods:, preferred_payment_method_id:) ⇒ Object
- #sort_payments(payment_methods:, preferred_payment_method_id:) ⇒ Object
Instance Method Details
#execute(payment_methods:, preferred_payment_method_id:) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/finders/spree_cm_commissioner/payment_methods/group_by_bank.rb', line 4 def execute(payment_methods:, preferred_payment_method_id:) sorted_payment_methods = sort_payments( payment_methods: payment_methods, preferred_payment_method_id: preferred_payment_method_id ) sorted_payment_methods.group_by(&:type).map do |type, methods| ::SpreeCmCommissioner::PaymentMethodGroup.new( name: type.underscore, payment_methods: methods ) end end |
#sort_payments(payment_methods:, preferred_payment_method_id:) ⇒ Object
18 19 20 21 22 |
# File 'app/finders/spree_cm_commissioner/payment_methods/group_by_bank.rb', line 18 def sort_payments(payment_methods:, preferred_payment_method_id:) payment_methods.sort_by do |method| [preferred_payment_method_id == method.id ? 0 : 1, method.position] end end |