Class: Kaui::PaymentMethod

Inherits:
KillBillClient::Model::PaymentMethod
  • Object
show all
Defined in:
app/models/kaui/payment_method.rb

Class Method Summary collapse

Class Method Details

.find_non_external_by_account_id(account_id, with_plugin_info = false, options = {}) ⇒ Object



11
12
13
14
# File 'app/models/kaui/payment_method.rb', line 11

def self.(, with_plugin_info = false, options = {})
  payment_methods = (, with_plugin_info, options)
  payment_methods.reject { |x| x.plugin_name == '__EXTERNAL_PAYMENT__' }
end

.list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'app/models/kaui/payment_method.rb', line 3

def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
  if search_key.present?
    find_in_batches_by_search_key(search_key, offset, limit, options)
  else
    find_in_batches(offset, limit, options)
  end
end

.payment_methods_for_payments(payments = [], options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/kaui/payment_method.rb', line 16

def self.payment_methods_for_payments(payments = [], options = {})
  payment_method_per_payment = {}
  payment_methods_cache      = {}
  deleted_payment_methods    = Set.new

  payments.each do |payment|
    next if deleted_payment_methods.include?(payment.payment_method_id)

    # The payment method may have been deleted
    payment_methods_cache[payment.payment_method_id] ||= Kaui::PaymentMethod.find_by_id(payment.payment_method_id, true, options) rescue nil

    if payment_methods_cache[payment.payment_method_id].nil?
      deleted_payment_methods.add(payment.payment_method_id)
    else
      payment_method_per_payment[payment.payment_id] = payment_methods_cache[payment.payment_method_id]
    end
  end

  payment_method_per_payment
end