class PayCertify::Gateway::Client

Attributes

api_key[RW]
mode[RW]
response[RW]

Public Class Methods

new(api_key:, mode:) click to toggle source
# File lib/paycertify/gateway/client.rb, line 9
def initialize(api_key:, mode:)
  self.api_key = api_key
  self.mode = mode.to_s.to_sym
end

Public Instance Methods

api_endpoint() click to toggle source
# File lib/paycertify/gateway/client.rb, line 18
def api_endpoint
  @api_endpoint ||= 'https://'+ (live?? 'gateway' : 'demo') +'.paycertify.net'
end
error?() click to toggle source
# File lib/paycertify/gateway/client.rb, line 43
def error?
  !success?
end
get(path:, data: {}) click to toggle source
# File lib/paycertify/gateway/client.rb, line 22
def get(path:, data: {})
  data.merge!(token_payload)
  response = connection.get(path, data)
  respond_with response
end
live?() click to toggle source
# File lib/paycertify/gateway/client.rb, line 14
def live?
  mode.to_sym == :live
end
post(path:, data:) click to toggle source
# File lib/paycertify/gateway/client.rb, line 28
def post(path:, data:)
  body = data.merge(token_payload)

  response = connection.post do |request|
    request.url path
    request.body = body
  end

  respond_with response
end
success?() click to toggle source
# File lib/paycertify/gateway/client.rb, line 39
def success?
  response.status < 400
end

Private Instance Methods

connection() click to toggle source
# File lib/paycertify/gateway/client.rb, line 48
def connection
  @connection ||= Faraday.new(url: api_endpoint, ssl: {verify: false}) do |faraday|
    faraday.request :url_encoded
    faraday.response :logger
    faraday.adapter  Faraday.default_adapter
  end
end
respond_with(response) click to toggle source
# File lib/paycertify/gateway/client.rb, line 60
def respond_with(response)
  self.response = PayCertify::Gateway::Response.new(response)
end
token_payload() click to toggle source
# File lib/paycertify/gateway/client.rb, line 56
def token_payload
  { 'ApiToken' => api_key }
end