Class: Kaui::Account

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

Constant Summary collapse

SENSIVITE_DATA_FIELDS =
%w[name email].freeze
REMAPPING_FIELDS =
{
  'is_payment_delegated_to_parent' => 'pay_via_parent',
  'account_balance' => 'balance',
  'bill_cycle_day_local' => 'bcd',
  'account_cba' => 'cba',
  'is_migrated' => 'migrated'
}.freeze
ADVANCED_SEARCH_COLUMNS =
%w[id external_key email name currency parent_account_id pay_via_parent payment_method_id time_zone country postal_code].freeze
ADVANCED_SEARCH_NAME_CHANGES =
[%w[pay_via_parent is_payment_delegated_to_parent]].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bill_cycle_day_localObject

Returns the value of attribute bill_cycle_day_local.



5
6
7
# File 'app/models/kaui/account.rb', line 5

def bill_cycle_day_local
  @bill_cycle_day_local
end

#phoneObject

Returns the value of attribute phone.



5
6
7
# File 'app/models/kaui/account.rb', line 5

def phone
  @phone
end

Class Method Details

.find_by_id_or_key(account_id_or_key, with_balance, with_balance_and_cba, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/kaui/account.rb', line 32

def self.find_by_id_or_key(, with_balance, with_balance_and_cba, options = {})
  if /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/.match?()
    begin
      find_by_id(, with_balance, with_balance_and_cba, options)
    rescue StandardError => e
      begin
        # account_id_or_key looked like an id, but maybe it's an external key (this will happen in tests)?
        find_by_external_key(, with_balance, with_balance_and_cba, options)
      rescue StandardError => _
        # Nope - raise the initial exception
        raise e
      end
    end
  else
    find_by_external_key(, with_balance, with_balance_and_cba, options)
  end
end

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



50
51
52
53
54
55
56
# File 'app/models/kaui/account.rb', line 50

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, true, false, options)
  else
    find_in_batches(offset, limit, true, false, options)
  end
end

Instance Method Details

#balance_to_moneyObject



58
59
60
# File 'app/models/kaui/account.rb', line 58

def balance_to_money
  Kaui::Base.to_money(.abs, currency)
end

#cba_to_moneyObject



62
63
64
# File 'app/models/kaui/account.rb', line 62

def cba_to_money
  Kaui::Base.to_money(.abs, currency)
end

#check_account_details_bill_cycle_day_local?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'app/models/kaui/account.rb', line 26

def 
  return true if bill_cycle_day_local.to_i.between?(1, 31)

  false
end

#check_account_details_phone?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'app/models/kaui/account.rb', line 19

def 
  return false if phone.blank?
  return true if /\A(?:\+?\d{1,3}\s*-?)?\(?(?:\d{3})?\)?[- ]?\d{3}[- ]?\d{4}\z/i.match?(phone)

  false
end

#persisted?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/kaui/account.rb', line 66

def persisted?
  .present?
end