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
- #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.
- #refresh ⇒ Object
- #simulate_receive_transfer(amount:) ⇒ Object
- #test_mode? ⇒ Boolean
- #to_s ⇒ Object
- #update(description: 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.
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_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.
6 7 8 |
# File 'lib/fintoc/v2/resources/account.rb', line 6 def available_balance @available_balance end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
6 7 8 |
# File 'lib/fintoc/v2/resources/account.rb', line 6 def currency @currency end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/fintoc/v2/resources/account.rb', line 6 def description @description end |
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
6 7 8 |
# File 'lib/fintoc/v2/resources/account.rb', line 6 def entity @entity end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/fintoc/v2/resources/account.rb', line 6 def id @id end |
#is_root ⇒ Object (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 |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
6 7 8 |
# File 'lib/fintoc/v2/resources/account.rb', line 6 def mode @mode end |
#object ⇒ Object (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_number ⇒ Object (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 @root_account_number end |
#root_account_number_id ⇒ Object (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 @root_account_number_id end |
#status ⇒ Object (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
55 56 57 |
# File 'lib/fintoc/v2/resources/account.rb', line 55 def active? @status == 'active' end |
#blocked? ⇒ Boolean
59 60 61 |
# File 'lib/fintoc/v2/resources/account.rb', line 59 def blocked? @status == 'blocked' end |
#closed? ⇒ Boolean
63 64 65 |
# File 'lib/fintoc/v2/resources/account.rb', line 63 def closed? @status == 'closed' end |
#refresh ⇒ Object
42 43 44 45 |
# File 'lib/fintoc/v2/resources/account.rb', line 42 def refresh fresh_account = @client.accounts.get(@id) refresh_from_account(fresh_account) 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
67 68 69 |
# File 'lib/fintoc/v2/resources/account.rb', line 67 def test_mode? @mode == 'test' end |
#to_s ⇒ Object
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 updated_account = @client.accounts.update(@id, **params) refresh_from_account(updated_account) end |