Class: Airwallex::Balance
- Inherits:
-
APIResource
- Object
- APIResource
- Airwallex::Balance
- Extended by:
- APIOperations::List
- Defined in:
- lib/airwallex/resources/balance.rb
Overview
Balance resource for account balance queries
Query account balances across all currencies or for specific currencies. Shows available, pending, and reserved amounts.
Instance Attribute Summary
Attributes inherited from APIResource
Class Method Summary collapse
- .resource_path ⇒ Object
-
.retrieve(currency) ⇒ Airwallex::Balance
Retrieve balance for a specific currency.
Instance Method Summary collapse
-
#total_amount ⇒ Float
Calculate total balance.
Methods included from APIOperations::List
Methods inherited from APIResource
#changed_attributes, #dirty?, #initialize, #inspect, #method_missing, #refresh, #refresh_from, resource_name, #respond_to_missing?, #to_hash, #to_json, #to_s
Constructor Details
This class inherits a constructor from Airwallex::APIResource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Airwallex::APIResource
Class Method Details
.resource_path ⇒ Object
24 25 26 |
# File 'lib/airwallex/resources/balance.rb', line 24 def self.resource_path "/api/v1/balances/current" end |
.retrieve(currency) ⇒ Airwallex::Balance
Retrieve balance for a specific currency
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/airwallex/resources/balance.rb', line 32 def self.retrieve(currency) response = Airwallex.client.get(resource_path, currency: currency) # Balance API returns array directly at top level balances_array = response.is_a?(Array) ? response : response[:data] || response["data"] || [] balances = ListObject.new( data: balances_array, has_more: false, resource_class: self ) # Filter to find the requested currency balance = balances.find { |b| b.currency&.upcase == currency.upcase } raise NotFoundError, "Balance not found for currency: #{currency}" unless balance balance end |
Instance Method Details
#total_amount ⇒ Float
Calculate total balance
52 53 54 55 56 57 |
# File 'lib/airwallex/resources/balance.rb', line 52 def total_amount available = respond_to?(:available_amount) ? available_amount.to_f : 0.0 pending = respond_to?(:pending_amount) ? pending_amount.to_f : 0.0 reserved = respond_to?(:reserved_amount) ? reserved_amount.to_f : 0.0 (available + pending + reserved).round(2) end |