Class: MpesaStk::StkPushQuery

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

Overview

Query the status of an STK Push checkout request.

Constant Summary

Constants inherited from Client

Client::AUTH_KEYS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

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

Constructor Details

#initialize(checkout_request_id, **options) ⇒ StkPushQuery

Returns a new instance of StkPushQuery.



16
17
18
19
# File 'lib/mpesa_stk/stk_push_query.rb', line 16

def initialize(checkout_request_id, **options)
  super(**options)
  @checkout_request_id = checkout_request_id
end

Instance Attribute Details

#checkout_request_idObject (readonly)

Returns the value of attribute checkout_request_id.



14
15
16
# File 'lib/mpesa_stk/stk_push_query.rb', line 14

def checkout_request_id
  @checkout_request_id
end

Class Method Details

.call(checkout_request_id, **options) ⇒ Object



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

def call(checkout_request_id, **options)
  new(checkout_request_id, **options).query_status
end

Instance Method Details

#query_statusObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mpesa_stk/stk_push_query.rb', line 21

def query_status
  short_code = option('business_short_code')
  passkey = option('business_passkey')
  timestamp = stk_timestamp

  post(
    'stk_push_query_url',
    {
      BusinessShortCode: short_code,
      Password: stk_password(short_code, passkey, timestamp),
      Timestamp: timestamp.to_s,
      CheckoutRequestID: checkout_request_id
    },
    error_message: 'Failed to query STK push status'
  )
end