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
12 13 14 15 16 |
# File 'lib/paycertify/three_ds/client.rb', line 12 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.
10 11 12 |
# File 'lib/paycertify/three_ds/client.rb', line 10 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
10 11 12 |
# File 'lib/paycertify/three_ds/client.rb', line 10 def api_secret @api_secret end |
#mode ⇒ Object
Returns the value of attribute mode.
10 11 12 |
# File 'lib/paycertify/three_ds/client.rb', line 10 def mode @mode end |
#response ⇒ Object
Returns the value of attribute response.
10 11 12 |
# File 'lib/paycertify/three_ds/client.rb', line 10 def response @response end |
Instance Method Details
#base_url ⇒ Object
26 27 28 |
# File 'lib/paycertify/three_ds/client.rb', line 26 def base_url @base_url ||= [API_ENDPOINT, path_prefix].join('/') end |
#error? ⇒ Boolean
52 53 54 |
# File 'lib/paycertify/three_ds/client.rb', line 52 def error? !success? end |
#live? ⇒ Boolean
18 19 20 |
# File 'lib/paycertify/three_ds/client.rb', line 18 def live? mode.to_sym == :live end |
#path_for(path) ⇒ Object
30 31 32 |
# File 'lib/paycertify/three_ds/client.rb', line 30 def path_for(path) base_url + path end |
#path_prefix ⇒ Object
22 23 24 |
# File 'lib/paycertify/three_ds/client.rb', line 22 def path_prefix @path_prefix ||= live?? 'index.php' : 'index_demo.php' end |
#post(path:, data:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/paycertify/three_ds/client.rb', line 34 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
48 49 50 |
# File 'lib/paycertify/three_ds/client.rb', line 48 def success? response.status < 400 end |