Class: PayCertify::ThreeDS::Client
- Inherits:
-
Object
- Object
- PayCertify::ThreeDS::Client
- Defined in:
- lib/paycertify/three_ds/client.rb
Constant Summary collapse
- API_ENDPOINT =
'https://mpi.3dsintegrator.com'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #base_url ⇒ Object
- #error? ⇒ Boolean
-
#initialize(api_key:, api_secret:, mode:) ⇒ Client
constructor
A new instance of Client.
- #live? ⇒ Boolean
- #path_for(path) ⇒ Object
- #path_prefix ⇒ Object
- #post(path:, data:) ⇒ Object
- #success? ⇒ Boolean
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_key ⇒ Object
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_secret ⇒ Object
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 |
#mode ⇒ Object
Returns the value of attribute mode.
9 10 11 |
# File 'lib/paycertify/three_ds/client.rb', line 9 def mode @mode end |
#response ⇒ Object
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_url ⇒ Object
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_prefix ⇒ Object
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 |