Class: MpesaStk::AccountBalance

Inherits:
Client
  • Object
show all
Defined in:
lib/mpesa_stk/account_balance.rb

Overview

Query account balance for a PayBill or Till number.

Constant Summary

Constants inherited from Client

Client::AUTH_KEYS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

extract_auth_options, #initialize, #json_headers, #option, #optional_option, #post, #random_reference, #stk_password, #stk_timestamp, #token

Constructor Details

This class inherits a constructor from MpesaStk::Client

Class Method Details

.call(**options) ⇒ Object



9
10
11
# File 'lib/mpesa_stk/account_balance.rb', line 9

def call(**options)
  new(**options).query_balance
end

Instance Method Details

#query_balanceObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mpesa_stk/account_balance.rb', line 14

def query_balance
  post(
    'account_balance_url',
    {
      Initiator: option('initiator'),
      SecurityCredential: option('security_credential'),
      CommandID: 'AccountBalance',
      PartyA: option('business_short_code', :party_a),
      IdentifierType: @options.fetch(:identifier_type, '4'),
      ResultURL: option('result_url'),
      QueueTimeOutURL: option('queue_timeout_url')
    },
    error_message: 'Failed to query account balance'
  )
end