Class: PayCertify::ThreeDS::Client

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

Constant Summary collapse

API_ENDPOINT =
'https://mpi.3dsintegrator.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, api_secret:, mode:) ⇒ Client



11
12
13
14
15
# File 'lib/paycertify/three_ds/client.rb', line 11

def initialize(api_key:, api_secret:, mode:)
  self.api_key = api_key
  self.api_secret = api_secret
  self.mode = mode.to_s.to_sym
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



9
10
11
# File 'lib/paycertify/three_ds/client.rb', line 9

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



9
10
11
# File 'lib/paycertify/three_ds/client.rb', line 9

def api_secret
  @api_secret
end

#modeObject

Returns the value of attribute mode.



9
10
11
# File 'lib/paycertify/three_ds/client.rb', line 9

def mode
  @mode
end

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/paycertify/three_ds/client.rb', line 9

def response
  @response
end

Instance Method Details

#base_urlObject



25
26
27
# File 'lib/paycertify/three_ds/client.rb', line 25

def base_url
  @base_url ||= [API_ENDPOINT, path_prefix].join('/')
end

#error?Boolean



51
52
53
# File 'lib/paycertify/three_ds/client.rb', line 51

def error?
  !success?
end

#live?Boolean



17
18
19
# File 'lib/paycertify/three_ds/client.rb', line 17

def live?
  mode.to_sym == :live
end

#path_for(path) ⇒ Object



29
30
31
# File 'lib/paycertify/three_ds/client.rb', line 29

def path_for(path)
  base_url + path
end

#path_prefixObject



21
22
23
# File 'lib/paycertify/three_ds/client.rb', line 21

def path_prefix
  @path_prefix ||= live?? 'index.php' : 'index_demo.php'
end

#post(path:, data:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/paycertify/three_ds/client.rb', line 33

def post(path:, data:)
  sorted_data = JSON.generate(data.sort.to_h)

  response = connection.post do |request|
    request.url path_for(path)
    request.headers['Content-Type'] = 'application/json'
    request.headers['x-mpi-api-key'] = api_key
    request.headers['x-mpi-signature'] = signature(path, sorted_data)
    request.body = sorted_data
  end

  respond_with response
end

#success?Boolean



47
48
49
# File 'lib/paycertify/three_ds/client.rb', line 47

def success?
  response.status < 400
end