Class: Mpesa::Reversal

Inherits:
Resource show all
Defined in:
lib/mpesa/resources/reversal.rb

Constant Summary collapse

PATH =
'mpesa/reversal/v1/request'

Instance Attribute Summary

Attributes inherited from Resource

#args, #client

Instance Method Summary collapse

Methods inherited from Resource

#format_phone, #get_request, #handle_response, #initialize, #post_request

Constructor Details

This class inherits a constructor from Mpesa::Resource

Instance Method Details

#bodyObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mpesa/resources/reversal.rb', line 11

def body
  {
    "Initiator": args[:initiator_username],
    "SecurityCredential": credentials,
    "CommandID": 'TransactionReversal',
    "TransactionID": args[:transaction_id],
    "Amount": args[:amount],
    "ReceiverParty": args[:receiver],
    "RecieverIdentifierType": args[:receiver_type],
    "Remarks": args[:remarks] || 'check status',
    "QueueTimeOutURL": args[:timeout_url],
    "ResultURL": args[:result_url],
    "Occasion": args[:occasion] || 'check status'
  }
end

#callObject



7
8
9
# File 'lib/mpesa/resources/reversal.rb', line 7

def call
  Object.new post_request(url: PATH, body: body).body
end

#credentialsObject



27
28
29
# File 'lib/mpesa/resources/reversal.rb', line 27

def credentials
  SecurityCred.new(args[:initiator_password], client.env).password_credential
end