class Epayments::API

Attributes

partner_id[RW]
partner_secret[RW]

Public Class Methods

new(partner_id, partner_secret) click to toggle source
# File lib/epayments/api.rb, line 12
def initialize(partner_id, partner_secret)
  @partner_id = partner_id
  @partner_secret = partner_secret
  @access_token = nil
  @token_expires_at = nil
end

Public Instance Methods

currency_exchange(params) click to toggle source
# File lib/epayments/api.rb, line 49
def currency_exchange(params)
  check_token

  Request.perform(:post, URI.parse(Urls::CURRENCY_EXCHANGE_URL), headers_for_other, params.to_json)
end
ewallet() click to toggle source
# File lib/epayments/api.rb, line 43
def ewallet
  check_token

  Request.perform(:get, URI.parse(Urls::EWALLET_URL), headers_for_other, '')
end
payment(params) click to toggle source

requisites is the array of requisites hashes

# File lib/epayments/api.rb, line 24
def payment(params)
  check_token

  Request.perform(:post, URI.parse(Urls::PAYMENTS_URL), headers_for_other, params.to_json)
end
payment_info(payment_id) click to toggle source
# File lib/epayments/api.rb, line 30
def payment_info(payment_id)
  check_token

  Request.perform(:get, URI.parse(Urls::PAYMENTS_URL + "/#{payment_id}"), headers_for_other, '')
end
preflight(params) click to toggle source

test payment with no actual processing, to view errors if they exists

# File lib/epayments/api.rb, line 37
def preflight(params)
  check_token

  Request.perform(:post, URI.parse(Urls::PREFLIGHT_URL), headers_for_other, params.to_json)
end
token(params) click to toggle source
# File lib/epayments/api.rb, line 19
def token(params)
  Request.perform(:post, URI.parse(Urls::TOKEN_URL), headers_for_token, params.to_s)
end

Private Instance Methods

check_token() click to toggle source
# File lib/epayments/api.rb, line 65
def check_token
  return if @access_token.present? && @token_expires_at > Time.now

  response = token("grant_type=partner&partner_id=#{@partner_id}"\
                   "&partner_secret=#{CGI.escape(@partner_secret)}")

  @access_token = response['access_token']
  @token_expires_at = Time.now + response['expires_in'].to_i
end
headers_for_other() click to toggle source
# File lib/epayments/api.rb, line 61
def headers_for_other
  { 'Content-type' => 'application/json', 'Authorization' => "Bearer #{@access_token}" }
end
headers_for_token() click to toggle source
# File lib/epayments/api.rb, line 57
def headers_for_token
  { 'Content-type' => 'application/x-www-form-urlencoded' }
end