Class: MpesaStk::Push
Overview
STK Push (Lipa na M-Pesa): PayBill and Buy Goods.
MpesaStk::Push.call(amount, phone) # PayBill, ENV only
MpesaStk::Push.call(amount, phone, type: :buy_goods) # Buy Goods
MpesaStk::Push.call(amount, phone, key: '...', ...) # per-request overrides
Constant Summary collapse
- TRANSACTION_TYPES =
{ pay_bill: 'CustomerPayBillOnline', buy_goods: 'CustomerBuyGoodsOnline' }.freeze
Constants inherited from Client
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#phone_number ⇒ Object
readonly
Returns the value of attribute phone_number.
-
#transaction_type ⇒ Object
readonly
Returns the value of attribute transaction_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(amount, phone_number, type: :pay_bill, **options) ⇒ Push
constructor
A new instance of Push.
- #push_payment ⇒ Object
Methods inherited from Client
extract_auth_options, #json_headers, #option, #optional_option, #post, #random_reference, #stk_password, #stk_timestamp, #token
Constructor Details
#initialize(amount, phone_number, type: :pay_bill, **options) ⇒ Push
Returns a new instance of Push.
25 26 27 28 29 30 31 32 33 |
# File 'lib/mpesa_stk/push.rb', line 25 def initialize(amount, phone_number, type: :pay_bill, **) @transaction_type = TRANSACTION_TYPES.fetch(type) do raise ArgumentError, "Unknown STK type: #{type}. Use :pay_bill or :buy_goods" end super(**) @amount = amount @phone_number = phone_number end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
23 24 25 |
# File 'lib/mpesa_stk/push.rb', line 23 def amount @amount end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
23 24 25 |
# File 'lib/mpesa_stk/push.rb', line 23 def phone_number @phone_number end |
#transaction_type ⇒ Object (readonly)
Returns the value of attribute transaction_type.
23 24 25 |
# File 'lib/mpesa_stk/push.rb', line 23 def transaction_type @transaction_type end |
Class Method Details
.call(amount, phone_number, type: :pay_bill, **options) ⇒ Object
18 19 20 |
# File 'lib/mpesa_stk/push.rb', line 18 def call(amount, phone_number, type: :pay_bill, **) new(amount, phone_number, type: type, **).push_payment end |
Instance Method Details
#push_payment ⇒ Object
35 36 37 |
# File 'lib/mpesa_stk/push.rb', line 35 def push_payment post('process_request_url', stk_push_payload, error_message: 'Failed to push payment') end |