Class: Airtel::Pesa::Example
- Inherits:
-
Object
- Object
- Airtel::Pesa::Example
- Defined in:
- lib/airtel/pesa/example.rb
Constant Summary collapse
- STAGING_URL =
"https://openapiuat.airtel.africa".freeze
- PRODUCTION_URL =
"https://openapi.airtel.africa".freeze
Instance Attribute Summary collapse
-
#param1 ⇒ Object
readonly
Returns the value of attribute param1.
-
#param4 ⇒ Object
readonly
Returns the value of attribute param4.
-
#param5 ⇒ Object
readonly
Returns the value of attribute param5.
-
#param6 ⇒ Object
readonly
Returns the value of attribute param6.
-
#transaction_country_code ⇒ Object
readonly
Returns the value of attribute transaction_country_code.
-
#transaction_currency_code ⇒ Object
readonly
Returns the value of attribute transaction_currency_code.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(param1, transaction_country_code, transaction_currency_code, param4, param5, param6) ⇒ Example
constructor
A new instance of Example.
Constructor Details
#initialize(param1, transaction_country_code, transaction_currency_code, param4, param5, param6) ⇒ Example
Returns a new instance of Example.
21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#param1 ⇒ Object (readonly)
Returns the value of attribute param1.
15 16 17 |
# File 'lib/airtel/pesa/example.rb', line 15 def param1 @param1 end |
#param4 ⇒ Object (readonly)
Returns the value of attribute param4.
15 16 17 |
# File 'lib/airtel/pesa/example.rb', line 15 def param4 @param4 end |
#param5 ⇒ Object (readonly)
Returns the value of attribute param5.
15 16 17 |
# File 'lib/airtel/pesa/example.rb', line 15 def param5 @param5 end |
#param6 ⇒ Object (readonly)
Returns the value of attribute param6.
15 16 17 |
# File 'lib/airtel/pesa/example.rb', line 15 def param6 @param6 end |
#transaction_country_code ⇒ Object (readonly)
Returns the value of attribute transaction_country_code.
15 16 17 |
# File 'lib/airtel/pesa/example.rb', line 15 def transaction_country_code @transaction_country_code end |
#transaction_currency_code ⇒ Object (readonly)
Returns the value of attribute transaction_currency_code.
15 16 17 |
# File 'lib/airtel/pesa/example.rb', line 15 def transaction_currency_code @transaction_currency_code end |
Class Method Details
.call(param1:, transaction_country_code:, transaction_currency_code:, param4:, param5:, param6:) ⇒ Object
17 18 19 |
# 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 |
Instance Method Details
#call ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 |