Class: Mobile::Pesa::Reversal
- Inherits:
-
Object
- Object
- Mobile::Pesa::Reversal
- Defined in:
- lib/mobile/pesa/reversal.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#occasion ⇒ Object
readonly
Returns the value of attribute occasion.
-
#remarks ⇒ Object
readonly
Returns the value of attribute remarks.
-
#short_code ⇒ Object
readonly
Returns the value of attribute short_code.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(amount, transaction_id, short_code, remarks, occasion) ⇒ Reversal
constructor
A new instance of Reversal.
Constructor Details
#initialize(amount, transaction_id, short_code, remarks, occasion) ⇒ Reversal
Returns a new instance of Reversal.
19 20 21 22 23 24 25 |
# File 'lib/mobile/pesa/reversal.rb', line 19 def initialize(amount, transaction_id, short_code, remarks, occasion) @amount = amount @transaction_id = transaction_id @short_code = short_code @remarks = remarks @occasion = occasion end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
13 14 15 |
# File 'lib/mobile/pesa/reversal.rb', line 13 def amount @amount end |
#occasion ⇒ Object (readonly)
Returns the value of attribute occasion.
13 14 15 |
# File 'lib/mobile/pesa/reversal.rb', line 13 def occasion @occasion end |
#remarks ⇒ Object (readonly)
Returns the value of attribute remarks.
13 14 15 |
# File 'lib/mobile/pesa/reversal.rb', line 13 def remarks @remarks end |
#short_code ⇒ Object (readonly)
Returns the value of attribute short_code.
13 14 15 |
# File 'lib/mobile/pesa/reversal.rb', line 13 def short_code @short_code end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
13 14 15 |
# File 'lib/mobile/pesa/reversal.rb', line 13 def transaction_id @transaction_id end |
Class Method Details
.call(amount:, transaction_id:, short_code:, remarks:, occasion:) ⇒ Object
15 16 17 |
# File 'lib/mobile/pesa/reversal.rb', line 15 def self.call(amount:, transaction_id:, short_code:, remarks:, occasion:) new(amount, transaction_id, short_code, remarks, occasion).call end |
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mobile/pesa/reversal.rb', line 27 def call url = URI("https://sandbox.safaricom.co.ke/mpesa/reversal/v1/request") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["Authorization"] = "Bearer #{token}" request.body = JSON.dump(body) response = http.request(request) parsed_body = JSON.parse(response.read_body) if parsed_body.key?("errorCode") error = OpenStruct.new( error_code: parsed_body["errorCode"], error_message: parsed_body["errorMessage"], request_id: parsed_body["requestId"] ) OpenStruct.new(result: nil, error: error) else result = OpenStruct.new( originator_converstion_id: parsed_body["OriginatorConverstionID"], response_code: parsed_body["ResponseCode"], response_description: parsed_body["ResponseDescription"] ) OpenStruct.new(result: result, error: nil) end rescue JSON::ParserError => error OpenStruct.new(result: nil, error: error) end |