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.



9
10
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
# File 'lib/fintoc/v2/resources/account.rb', line 9

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.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def available_balance
  @available_balance
end

#currencyObject (readonly)

Returns the value of attribute currency.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def currency
  @currency
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def description
  @description
end

#entityObject (readonly)

Returns the value of attribute entity.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def entity
  @entity
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def id
  @id
end

#is_rootObject (readonly)

Returns the value of attribute is_root.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def is_root
  @is_root
end

#modeObject (readonly)

Returns the value of attribute mode.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def mode
  @mode
end

#objectObject (readonly)

Returns the value of attribute object.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def object
  @object
end

#root_account_numberObject (readonly)

Returns the value of attribute root_account_number.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def 
  @root_account_number
end

#root_account_number_idObject (readonly)

Returns the value of attribute root_account_number_id.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def 
  @root_account_number_id
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/fintoc/v2/resources/account.rb', line 6

def status
  @status
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/fintoc/v2/resources/account.rb', line 55

def active?
  @status == 'active'
end

#blocked?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/fintoc/v2/resources/account.rb', line 59

def blocked?
  @status == 'blocked'
end

#closed?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/fintoc/v2/resources/account.rb', line 63

def closed?
  @status == 'closed'
end

#refreshObject



42
43
44
45
# File 'lib/fintoc/v2/resources/account.rb', line 42

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

#simulate_receive_transfer(amount:) ⇒ Object



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

def simulate_receive_transfer(amount:)
  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
  )
end

#test_mode?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/fintoc/v2/resources/account.rb', line 67

def test_mode?
  @mode == 'test'
end

#to_sObject



38
39
40
# File 'lib/fintoc/v2/resources/account.rb', line 38

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

#update(description: nil) ⇒ Object



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

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

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