Class: PayCertify::Gateway::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/paycertify/gateway/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, mode:) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# 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

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/paycertify/gateway/client.rb', line 7

def api_key
  @api_key
end

#modeObject

Returns the value of attribute mode.



7
8
9
# File 'lib/paycertify/gateway/client.rb', line 7

def mode
  @mode
end

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/paycertify/gateway/client.rb', line 7

def response
  @response
end

Instance Method Details

#api_endpointObject



18
19
20
# File 'lib/paycertify/gateway/client.rb', line 18

def api_endpoint
  @api_endpoint ||= 'https://'+ (live?? 'gateway' : 'demo') +'.paycertify.net'
end

#error?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/paycertify/gateway/client.rb', line 43

def error?
  !success?
end

#get(path:, data: {}) ⇒ Object



22
23
24
25
26
# 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?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/paycertify/gateway/client.rb', line 14

def live?
  mode.to_sym == :live
end

#post(path:, data:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# 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?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/paycertify/gateway/client.rb', line 39

def success?
  response.status < 400
end