Class: SpreeCmCommissioner::PaymentMethods::Find

Inherits:
Object
  • Object
show all
Defined in:
app/finders/spree_cm_commissioner/payment_methods/find.rb

Overview

Order & user independent lookup of the payment methods a vendor accepts.

Mirrors the scope selection of Vpago::OrderDecorator#available_payment_methods, minus everything that depends on the current user, so the result stays cacheable on vendor id (+ payout):

- available_for_order?  (only Spree::PaymentMethod::StoreCredit varies, on user balance)
- available_on_frontend_for_early_adopter  (user attribute)
- preferred_payment_method_id  (user, affects sort only)

payout covers support_payout?, since callers already know whether their order requires it (Order#required_payway_payout?, serialized onto the cart/order response) without needing to look at line items/shipments here.

Callers needing the full per-order truth must keep using Spree::Api::V2::*::CartPaymentMethodGroupsController.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor:, store: nil, type: nil, payout: false) ⇒ Find

Returns a new instance of Find.



22
23
24
25
26
27
# File 'app/finders/spree_cm_commissioner/payment_methods/find.rb', line 22

def initialize(vendor:, store: nil, type: nil, payout: false)
  @vendor = vendor
  @store = store
  @type = type
  @payout = payout
end

Instance Attribute Details

#payoutObject (readonly)

Returns the value of attribute payout.



20
21
22
# File 'app/finders/spree_cm_commissioner/payment_methods/find.rb', line 20

def payout
  @payout
end

#storeObject (readonly)

Returns the value of attribute store.



20
21
22
# File 'app/finders/spree_cm_commissioner/payment_methods/find.rb', line 20

def store
  @store
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'app/finders/spree_cm_commissioner/payment_methods/find.rb', line 20

def type
  @type
end

#vendorObject (readonly)

Returns the value of attribute vendor.



20
21
22
# File 'app/finders/spree_cm_commissioner/payment_methods/find.rb', line 20

def vendor
  @vendor
end

Instance Method Details

#executeObject



29
30
31
32
# File 'app/finders/spree_cm_commissioner/payment_methods/find.rb', line 29

def execute
  result = type.present? ? mini_app_scope : scope.reject(&:mini_app?)
  payout ? result.select(&:support_payout?) : result
end