Class: MpesaStk::B2C
Overview
Business-to-customer payments (salary, promotions, etc.).
Constant Summary
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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(amount, phone_number, **options) ⇒ B2C
constructor
A new instance of B2C.
- #send_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, **options) ⇒ B2C
Returns a new instance of B2C.
16 17 18 19 20 |
# File 'lib/mpesa_stk/b2c.rb', line 16 def initialize(amount, phone_number, **) super(**) @amount = amount @phone_number = phone_number end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
14 15 16 |
# File 'lib/mpesa_stk/b2c.rb', line 14 def amount @amount end |
#phone_number ⇒ Object (readonly)
Returns the value of attribute phone_number.
14 15 16 |
# File 'lib/mpesa_stk/b2c.rb', line 14 def phone_number @phone_number end |
Class Method Details
.call(amount, phone_number, **options) ⇒ Object
9 10 11 |
# File 'lib/mpesa_stk/b2c.rb', line 9 def call(amount, phone_number, **) new(amount, phone_number, **).send_payment end |
Instance Method Details
#send_payment ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mpesa_stk/b2c.rb', line 22 def send_payment body = { InitiatorName: option('initiator_name'), SecurityCredential: option('security_credential'), CommandID: @options.fetch(:command_id, 'BusinessPayment'), Amount: amount.to_s, PartyA: option('business_short_code', :party_a), PartyB: phone_number, Remarks: @options.fetch(:remarks, 'Payment'), QueueTimeOutURL: option('queue_timeout_url'), ResultURL: option('result_url') } body[:Occasion] = @options[:occasion] if @options[:occasion] post('b2c_url', body, error_message: 'Failed to send B2C payment') end |