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


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/kaui/payment_method.rb', line 19

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

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

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


33
34
35
36
# File 'app/models/kaui/payment_method.rb', line 33

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

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


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

def self.find_safely_by_id(id, options = {})
  Kaui::PaymentMethod.find_by_id(id, true, options)
rescue => e
  # Maybe the plugin is not registered or the plugin threw an exception
  Rails.logger.warn(e)
  Kaui::PaymentMethod.find_by_id(id, false, options) rescue nil # deleted pm?
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


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/kaui/payment_method.rb', line 38

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