Class: MpesaStk::IMSI

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

Overview

Check customer account type indicator (ATI) via IMSI API.

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(customer_number, version: 'v1', **options) ⇒ Object



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

def call(customer_number, version: 'v1', **options)
  new(**options).check_ati(customer_number, version)
end

Instance Method Details

#check_ati(customer_number, version = 'v1') ⇒ Object

Raises:

  • (StandardError)


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

def check_ati(customer_number, version = 'v1')
  endpoint = version.to_s == 'v2' ? '/imsi/v2/checkATI' : '/imsi/v1/checkATI'
  url = "#{Config.fetch('base_url')}#{endpoint}"
  response = HTTParty.post(
    url,
    headers: json_headers,
    body: { customerNumber: customer_number }.to_json
  )

  raise StandardError, "Failed to check ATI: #{response.code} - #{response.body}" unless response.success?

  JSON.parse(response.body)
end