Class: Mpesa::StkQuery

Inherits:
Resource show all
Defined in:
lib/mpesa/resources/stk_query.rb

Constant Summary collapse

PATH =
'mpesa/stkpushquery/v1/query'

Instance Attribute Summary

Attributes inherited from Resource

#args, #client

Instance Method Summary collapse

Methods inherited from Resource

#format_phone, #get_request, #handle_response, #initialize, #post_request

Constructor Details

This class inherits a constructor from Mpesa::Resource

Instance Method Details

#bodyObject



13
14
15
16
17
18
19
20
# File 'lib/mpesa/resources/stk_query.rb', line 13

def body
  {
    'BusinessShortCode': shortcode,
    'Password': password,
    'Timestamp': timestamp,
    'CheckoutRequestID': args[:checkout_request_id]
  }
end

#callObject



9
10
11
# File 'lib/mpesa/resources/stk_query.rb', line 9

def call
  Object.new post_request(url: PATH, body: body).body
end

#passwordObject



22
23
24
# File 'lib/mpesa/resources/stk_query.rb', line 22

def password
  Base64.strict_encode64("#{shortcode}#{args[:pass_key] || client.pass_key}#{timestamp}")
end

#shortcodeObject



30
31
32
# File 'lib/mpesa/resources/stk_query.rb', line 30

def shortcode
  args[:shortcode] || client.shortcode
end

#timestampObject



26
27
28
# File 'lib/mpesa/resources/stk_query.rb', line 26

def timestamp
  Time.now.strftime('%Y%m%d%H%M%S')
end