Class: Fintoc::V2::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/fintoc/v2/resources/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, object:, mode:, description:, available_balance:, currency:, is_root:, root_account_number_id:, root_account_number:, status:, entity:, client: nil) ⇒ Account

Returns a new instance of Account.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fintoc/v2/resources/account.rb', line 11

def initialize(
  id:,
  object:,
  mode:,
  description:,
  available_balance:,
  currency:,
  is_root:,
  root_account_number_id:,
  root_account_number:,
  status:,
  entity:,
  client: nil,
  **
)
  @id = id
  @object = object
  @mode = mode
  @description = description
  @available_balance = available_balance
  @currency = currency
  @is_root = is_root
  @root_account_number_id = 
  @root_account_number = 
  @status = status
  @entity = entity
  @client = client
end

Instance Attribute Details

#available_balanceObject (readonly)

Returns the value of attribute available_balance.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def available_balance
  @available_balance
end

#currencyObject (readonly)

Returns the value of attribute currency.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def currency
  @currency
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def description
  @description
end

#entityObject (readonly)

Returns the value of attribute entity.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def entity
  @entity
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def id
  @id
end

#is_rootObject (readonly)

Returns the value of attribute is_root.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def is_root
  @is_root
end

#modeObject (readonly)

Returns the value of attribute mode.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def mode
  @mode
end

#objectObject (readonly)

Returns the value of attribute object.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def object
  @object
end

#root_account_numberObject (readonly)

Returns the value of attribute root_account_number.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def 
  @root_account_number
end

#root_account_number_idObject (readonly)

Returns the value of attribute root_account_number_id.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def 
  @root_account_number_id
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/fintoc/v2/resources/account.rb', line 8

def status
  @status
end

Instance Method Details

#account_statementsObject



86
87
88
# File 'lib/fintoc/v2/resources/account.rb', line 86

def 
  @account_statements ||= Managers::AccountStatementsManager.new(@client, @id)
end

#active?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/fintoc/v2/resources/account.rb', line 57

def active?
  @status == 'active'
end

#blocked?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/fintoc/v2/resources/account.rb', line 61

def blocked?
  @status == 'blocked'
end

#closed?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/fintoc/v2/resources/account.rb', line 65

def closed?
  @status == 'closed'
end

#movementsObject



90
91
92
# File 'lib/fintoc/v2/resources/account.rb', line 90

def movements
  @movements ||= Managers::MovementsManager.new(@client, @id)
end

#refreshObject



44
45
46
47
# File 'lib/fintoc/v2/resources/account.rb', line 44

def refresh
   = @client.accounts.get(@id)
  ()
end

#simulate_receive_transfer(amount:, idempotency_key: nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fintoc/v2/resources/account.rb', line 73

def simulate_receive_transfer(amount:, idempotency_key: nil)
  unless test_mode?
    raise Fintoc::Errors::InvalidRequestError, 'Simulation is only available in test mode'
  end

  @client.simulate.receive_transfer(
    account_number_id: @root_account_number_id,
    amount:,
    currency: @currency,
    idempotency_key:
  )
end

#test_mode?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fintoc/v2/resources/account.rb', line 69

def test_mode?
  @mode == 'test'
end

#to_sObject



40
41
42
# File 'lib/fintoc/v2/resources/account.rb', line 40

def to_s
  "💰 #{@description} (#{@id}) - #{Money.from_cents(@available_balance, @currency).format}"
end

#update(description: nil, idempotency_key: nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/fintoc/v2/resources/account.rb', line 49

def update(description: nil, idempotency_key: nil)
  params = {}
  params[:description] = description if description

   = @client.accounts.update(@id, idempotency_key:, **params)
  ()
end