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_all_safely_by_account_id(account_id, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/kaui/payment_method.rb', line 25

def self.(, options = {})
  pms = Kaui::PaymentMethod.(, false, options)

  pms.each_with_index do |pm, i|
    pms[i] = Kaui::PaymentMethod.find_by_id(pm.payment_method_id, true, options)
  rescue StandardError => e
    # Maybe the plugin is not registered or the plugin threw an exception
    Rails.logger.warn(e)
  end
  pms
end

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



37
38
39
40
# File 'app/models/kaui/payment_method.rb', line 37

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

.find_safely_by_id(id, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/kaui/payment_method.rb', line 13

def self.find_safely_by_id(id, options = {})
  Kaui::PaymentMethod.find_by_id(id, true, options)
rescue StandardError => e
  # Maybe the plugin is not registered or the plugin threw an exception
  Rails.logger.warn(e)
  begin
    Kaui::PaymentMethod.find_by_id(id, false, options)
  rescue StandardError
    nil
  end
end

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



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

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/kaui/payment_method.rb', line 42

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] ||= begin
      Kaui::PaymentMethod.find_by_id(payment.payment_method_id, true, options)
    rescue StandardError
      nil
    end

    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