Class: Mpesa::Client
- Inherits:
-
Object
- Object
- Mpesa::Client
- Defined in:
- lib/mpesa/client.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#pass_key ⇒ Object
readonly
Returns the value of attribute pass_key.
-
#raise_errors ⇒ Object
readonly
Returns the value of attribute raise_errors.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#shortcode ⇒ Object
readonly
Returns the value of attribute shortcode.
Instance Method Summary collapse
- #auth ⇒ Object
- #balance(**args) ⇒ Object
- #connection(basic_auth: false) ⇒ Object
-
#initialize(key:, secret:, shortcode: nil, pass_key: nil, env: 'production', adapter: Faraday.default_adapter, raise_errors: true) ⇒ Client
constructor
A new instance of Client.
- #payout(**args) ⇒ Object
- #register(**args) ⇒ Object
- #reversal(**args) ⇒ Object
- #status(**args) ⇒ Object
- #stk(**args) ⇒ Object
- #subdomain ⇒ Object
Constructor Details
#initialize(key:, secret:, shortcode: nil, pass_key: nil, env: 'production', adapter: Faraday.default_adapter, raise_errors: true) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 |
# File 'lib/mpesa/client.rb', line 9 def initialize(key:, secret:, shortcode: nil, pass_key: nil, env: 'production', adapter: Faraday.default_adapter, raise_errors: true) @key = key @secret = secret @env = env @adapter = adapter @pass_key = pass_key @shortcode = shortcode @raise_errors = raise_errors end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/mpesa/client.rb', line 7 def adapter @adapter end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/mpesa/client.rb', line 7 def env @env end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/mpesa/client.rb', line 7 def key @key end |
#pass_key ⇒ Object (readonly)
Returns the value of attribute pass_key.
7 8 9 |
# File 'lib/mpesa/client.rb', line 7 def pass_key @pass_key end |
#raise_errors ⇒ Object (readonly)
Returns the value of attribute raise_errors.
7 8 9 |
# File 'lib/mpesa/client.rb', line 7 def raise_errors @raise_errors end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
7 8 9 |
# File 'lib/mpesa/client.rb', line 7 def secret @secret end |
#shortcode ⇒ Object (readonly)
Returns the value of attribute shortcode.
7 8 9 |
# File 'lib/mpesa/client.rb', line 7 def shortcode @shortcode end |
Instance Method Details
#balance(**args) ⇒ Object
39 40 41 |
# File 'lib/mpesa/client.rb', line 39 def balance(**args) Balance.new(self, args).call end |
#connection(basic_auth: false) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mpesa/client.rb', line 47 def connection(basic_auth: false) @connection ||= Faraday.new do |conn| conn.url_prefix = "https://#{subdomain}.safaricom.co.ke" conn.request :json conn.response :json, content_type: 'application/json' conn.adapter adapter conn.request :authorization, :basic, key, secret if basic_auth conn.request :authorization, 'Bearer', auth.access_token unless basic_auth end end |
#payout(**args) ⇒ Object
31 32 33 |
# File 'lib/mpesa/client.rb', line 31 def payout(**args) Payout.new(self, args).call end |
#register(**args) ⇒ Object
23 24 25 |
# File 'lib/mpesa/client.rb', line 23 def register(**args) Register.new(self, args).call end |
#reversal(**args) ⇒ Object
43 44 45 |
# File 'lib/mpesa/client.rb', line 43 def reversal(**args) Reversal.new(self, args).call end |
#status(**args) ⇒ Object
35 36 37 |
# File 'lib/mpesa/client.rb', line 35 def status(**args) Status.new(self, args).call end |
#stk(**args) ⇒ Object
27 28 29 |
# File 'lib/mpesa/client.rb', line 27 def stk(**args) Stk.new(self, args).call end |
#subdomain ⇒ Object
58 59 60 |
# File 'lib/mpesa/client.rb', line 58 def subdomain env == 'production' ? 'api' : 'sandbox' end |