class Airtel::Pesa::Example
Constants
- PRODUCTION_URL
- STAGING_URL
Attributes
param1[R]
param4[R]
param5[R]
param6[R]
transaction_country_code[R]
transaction_currency_code[R]
Public Class Methods
call(param1:, transaction_country_code:, transaction_currency_code:, param4:, param5:, param6:)
click to toggle source
# File lib/airtel/pesa/example.rb, line 17 def self.call(param1:, transaction_country_code:, transaction_currency_code:, param4:, param5:, param6:) new(param1, transaction_country_code, transaction_currency_code, param4, param5, param6).call end
new(param1, transaction_country_code, transaction_currency_code, param4, param5, param6)
click to toggle source
# File lib/airtel/pesa/example.rb, line 21 def initialize(param1, transaction_country_code, transaction_currency_code, param4, param5, param6) @param1 = param1 @transaction_country_code = transaction_country_code @transaction_currency_code = transaction_currency_code @param4 = param4 @param5 = param5 @param6 = param6 end
Public Instance Methods
call()
click to toggle source
# File lib/airtel/pesa/example.rb, line 30 def call url = URI("#{env_url}/merchant/v1/payments/") 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/example.rb, line 63 def body {} end
env_url()
click to toggle source
# File lib/airtel/pesa/example.rb, line 54 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/example.rb, line 59 def token Airtel::Pesa::Authorization.call.result.access_token end