Class: Fintoc::V2::Account
- Inherits:
-
Object
- Object
- Fintoc::V2::Account
- Defined in:
- lib/fintoc/v2/resources/account.rb
Instance Attribute Summary collapse
-
#available_balance ⇒ Object
readonly
Returns the value of attribute available_balance.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_root ⇒ Object
readonly
Returns the value of attribute is_root.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#root_account_number ⇒ Object
readonly
Returns the value of attribute root_account_number.
-
#root_account_number_id ⇒ Object
readonly
Returns the value of attribute root_account_number_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #account_statements ⇒ Object
- #active? ⇒ Boolean
- #blocked? ⇒ Boolean
- #closed? ⇒ Boolean
-
#initialize(id:, object:, mode:, description:, available_balance:, currency:, is_root:, root_account_number_id:, root_account_number:, status:, entity:, client: nil) ⇒ Account
constructor
A new instance of Account.
- #movements ⇒ Object
- #refresh ⇒ Object
- #simulate_receive_transfer(amount:, idempotency_key: nil) ⇒ Object
- #test_mode? ⇒ Boolean
- #to_s ⇒ Object
- #update(description: nil, idempotency_key: nil) ⇒ Object
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_id @root_account_number = root_account_number @status = status @entity = entity @client = client end |
Instance Attribute Details
#available_balance ⇒ Object (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 |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
8 9 10 |
# File 'lib/fintoc/v2/resources/account.rb', line 8 def currency @currency end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/fintoc/v2/resources/account.rb', line 8 def description @description end |
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
8 9 10 |
# File 'lib/fintoc/v2/resources/account.rb', line 8 def entity @entity end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/fintoc/v2/resources/account.rb', line 8 def id @id end |
#is_root ⇒ Object (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 |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
8 9 10 |
# File 'lib/fintoc/v2/resources/account.rb', line 8 def mode @mode end |
#object ⇒ Object (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_number ⇒ Object (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 @root_account_number end |
#root_account_number_id ⇒ Object (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 @root_account_number_id end |
#status ⇒ Object (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_statements ⇒ Object
86 87 88 |
# File 'lib/fintoc/v2/resources/account.rb', line 86 def account_statements @account_statements ||= Managers::AccountStatementsManager.new(@client, @id) end |
#active? ⇒ Boolean
57 58 59 |
# File 'lib/fintoc/v2/resources/account.rb', line 57 def active? @status == 'active' end |
#blocked? ⇒ Boolean
61 62 63 |
# File 'lib/fintoc/v2/resources/account.rb', line 61 def blocked? @status == 'blocked' end |
#closed? ⇒ Boolean
65 66 67 |
# File 'lib/fintoc/v2/resources/account.rb', line 65 def closed? @status == 'closed' end |
#movements ⇒ Object
90 91 92 |
# File 'lib/fintoc/v2/resources/account.rb', line 90 def movements @movements ||= Managers::MovementsManager.new(@client, @id) end |
#refresh ⇒ Object
44 45 46 47 |
# File 'lib/fintoc/v2/resources/account.rb', line 44 def refresh fresh_account = @client.accounts.get(@id) refresh_from_account(fresh_account) 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
69 70 71 |
# File 'lib/fintoc/v2/resources/account.rb', line 69 def test_mode? @mode == 'test' end |
#to_s ⇒ Object
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 updated_account = @client.accounts.update(@id, idempotency_key:, **params) refresh_from_account(updated_account) end |