Class: MpesaStk::Push
- Inherits:
-
Object
- Object
- MpesaStk::Push
- Defined in:
- lib/mpesa_stk/push.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#business_passkey ⇒ Object
readonly
Returns the value of attribute business_passkey.
-
#business_short_code ⇒ Object
readonly
Returns the value of attribute business_short_code.
-
#callback_url ⇒ Object
readonly
Returns the value of attribute callback_url.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#till_number ⇒ Object
readonly
Returns the value of attribute till_number.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#transaction_type ⇒ Object
readonly
Returns the value of attribute transaction_type.
Class Method Summary collapse
- .buy_goods(amount, phone_number, hash = {}) ⇒ Object
- .pay_bill(amount, phone_number, hash = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(amount, phone_number, transaction_type, till_number = nil, business_short_code = nil, callback_url = nil, business_passkey = nil, key = nil, secret = nil) ⇒ Push
constructor
A new instance of Push.
- #push_payment ⇒ Object
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
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
15 16 17 |
# File 'lib/mpesa_stk/push.rb', line 15 def amount @amount end |
#business_passkey ⇒ Object (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_code ⇒ Object (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_url ⇒ Object (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_number ⇒ Object (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_number ⇒ Object (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 |
#token ⇒ Object (readonly)
Returns the value of attribute token.
15 16 17 |
# File 'lib/mpesa_stk/push.rb', line 15 def token @token end |
#transaction_type ⇒ Object (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_payment ⇒ Object
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 |