Class: MpesaStk::Reversal

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

Overview

Reverse a completed M-Pesa transaction.

Constant Summary

Constants inherited from Client

Client::AUTH_KEYS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

extract_auth_options, #json_headers, #option, #optional_option, #post, #random_reference, #stk_password, #stk_timestamp, #token

Constructor Details

#initialize(transaction_id, amount, **options) ⇒ Reversal

Returns a new instance of Reversal.



16
17
18
19
20
# File 'lib/mpesa_stk/reversal.rb', line 16

def initialize(transaction_id, amount, **options)
  super(**options)
  @transaction_id = transaction_id
  @amount = amount
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



14
15
16
# File 'lib/mpesa_stk/reversal.rb', line 14

def amount
  @amount
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



14
15
16
# File 'lib/mpesa_stk/reversal.rb', line 14

def transaction_id
  @transaction_id
end

Class Method Details

.call(transaction_id, amount, **options) ⇒ Object



9
10
11
# File 'lib/mpesa_stk/reversal.rb', line 9

def call(transaction_id, amount, **options)
  new(transaction_id, amount, **options).reverse_transaction
end

Instance Method Details

#reverse_transactionObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mpesa_stk/reversal.rb', line 22

def reverse_transaction
  post(
    'reversal_url',
    {
      Initiator: option('initiator'),
      SecurityCredential: option('security_credential'),
      CommandID: 'TransactionReversal',
      TransactionID: transaction_id,
      Amount: amount.to_s,
      ReceiverParty: option('business_short_code', :receiver_party),
      RecieverIdentifierType: @options.fetch(:receiver_identifier_type, '4'),
      ResultURL: option('result_url'),
      QueueTimeOutURL: option('queue_timeout_url')
    },
    error_message: 'Failed to reverse transaction'
  )
end