class Airtel::Pesa::RefundPayment
Constants
- PRODUCTION_URL
- STAGING_URL
Attributes
airtel_money_id[R]
transaction_country_code[R]
transaction_currency_code[R]
Public Class Methods
call(airtel_money_id:, transaction_country_code:, transaction_currency_code:)
click to toggle source
# File lib/airtel/pesa/refund_payment.rb, line 17 def self.call(airtel_money_id:, transaction_country_code:, transaction_currency_code:) new(airtel_money_id, transaction_country_code, transaction_currency_code).call end
new(airtel_money_id, transaction_country_code, transaction_currency_code)
click to toggle source
# File lib/airtel/pesa/refund_payment.rb, line 21 def initialize(airtel_money_id, transaction_country_code, transaction_currency_code) @airtel_money_id = airtel_money_id @transaction_country_code = transaction_country_code @transaction_currency_code = transaction_currency_code end
Public Instance Methods
call()
click to toggle source
# File lib/airtel/pesa/refund_payment.rb, line 27 def call url = URI("#{env_url}/standard/v1/payments/refund") 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["X-Country"] = transaction_country_code request["X-Currency"] = transaction_currency_code request.body = JSON.dump(body) response = http.request(request) parsed_response = JSON.parse(response.read_body) result = Airtel::Pesa.to_recursive_ostruct(parsed_response) OpenStruct.new(result: result, error: nil) rescue JSON::ParserError => error OpenStruct.new(result: nil, error: error) end
Private Instance Methods
body()
click to toggle source
# File lib/airtel/pesa/refund_payment.rb, line 60 def body { "transaction": { "airtel_money_id": airtel_money_id } } end
env_url()
click to toggle source
# File lib/airtel/pesa/refund_payment.rb, line 51 def env_url return STAGING_URL Airtel::Pesa.configuration.env == 'staging' return PRODUCTION_URL Airtel::Pesa.configuration.env == 'production' end
token()
click to toggle source
# File lib/airtel/pesa/refund_payment.rb, line 56 def token Airtel::Pesa::Authorization.call.result.access_token end