Class: MpesaStk::Push

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, phone_number, transaction_type, till_number = nil, business_short_code = nil, callback_url = nil, business_passkey = nil, key = nil, secret = nil) ⇒ Push

Returns a new instance of Push.



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

def initialize(amount, phone_number, transaction_type, till_number = nil, business_short_code = nil, callback_url = nil, business_passkey = nil, key = nil, secret = nil)
  @token = MpesaStk::AccessToken.call(key, secret)
  @transaction_type = transaction_type
  @till_number = till_number
  @business_short_code = business_short_code
  @callback_url = callback_url
  @business_passkey = business_passkey
  @amount = amount
  @phone_number = phone_number
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def amount
  @amount
end

#business_passkeyObject (readonly)

Returns the value of attribute business_passkey.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def business_passkey
  @business_passkey
end

#business_short_codeObject (readonly)

Returns the value of attribute business_short_code.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def business_short_code
  @business_short_code
end

#callback_urlObject (readonly)

Returns the value of attribute callback_url.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def callback_url
  @callback_url
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def phone_number
  @phone_number
end

#till_numberObject (readonly)

Returns the value of attribute till_number.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def till_number
  @till_number
end

#tokenObject (readonly)

Returns the value of attribute token.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def token
  @token
end

#transaction_typeObject (readonly)

Returns the value of attribute transaction_type.



15
16
17
# File 'lib/mpesa_stk/push.rb', line 15

def transaction_type
  @transaction_type
end

Class Method Details

.buy_goods(amount, phone_number, hash = {}) ⇒ Object



10
11
12
# File 'lib/mpesa_stk/push.rb', line 10

def buy_goods(amount, phone_number, hash = {})
  new(amount, phone_number, "CustomerBuyGoodsOnline", hash["till_number"], hash["business_short_code"], hash["callback_url"], hash["business_passkey"], hash["key"], hash["secret"]).push_payment
end

.pay_bill(amount, phone_number, hash = {}) ⇒ Object



6
7
8
# File 'lib/mpesa_stk/push.rb', line 6

def pay_bill(amount, phone_number, hash = {})
  new(amount, phone_number, "CustomerPayBillOnline", nil, hash["business_short_code"], hash["callback_url"], hash["business_passkey"], hash["key"], hash["secret"]).push_payment
end

Instance Method Details

#push_paymentObject



28
29
30
31
# File 'lib/mpesa_stk/push.rb', line 28

def push_payment
  response = HTTParty.post(url, headers: headers, body: body)
  JSON.parse(response.body)
end