paycertify 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00533fef5f2778118013c557dc86f0764ad29768
4
- data.tar.gz: c1c9d1c5ee320e189028550718c0f052cf16743f
3
+ metadata.gz: 73394e0bc6f1d06f09f82d27c78190e885e02942
4
+ data.tar.gz: 1059912be2fe0e25f280d539c2e28a3a72781c2b
5
5
  SHA512:
6
- metadata.gz: da6e402aa6da16be2c04f2b6742ab8f43f701a8b88dc874ccd2ca3059f8cfb977c0d4b12843db04406e181cddbaeba1322c6e51ebcc68aa749d60a2cd3afb307
7
- data.tar.gz: cf0e3fc1fd392c526bc7cd5e5363cfeb88a818809af080d409f76c0446f0bc3bba7718f2a95f69474e3df39c1a4713cf5d5a4e7ba0523f23dcf8f7f58ae48108
6
+ metadata.gz: a4723260c7476caac031a519c7dcdfd6b89ac6676a9303b820e4c97f51d53e27ce5881af5fcb98b77d8c46813f7af7408d698cea578620a042924def88db5630
7
+ data.tar.gz: 45dde778b7a4bd12f436932a878b14ae1ea077d83636ff58aead9ab984b5b736334dab3e11b4536c63cc9bdc44ab0b9df9820aeb19498d7134799c78c5f12831
@@ -1,3 +1,4 @@
1
+ require_relative './three_ds/callback'
1
2
  require_relative './three_ds/client'
2
3
  require_relative './three_ds/form'
3
4
  require_relative './three_ds/payment_authentication'
@@ -12,15 +13,15 @@ module PayCertify
12
13
 
13
14
  attr_accessor :type, :client, :settings, :authentication
14
15
  attr_accessor :card_number, :expiration_month, :expiration_year, :amount, :transaction_id, :message_id, :return_url
16
+ attr_accessor :mode
15
17
 
16
- delegate :api_key, to: :class
17
- delegate :api_secret, to: :class
18
+ delegate :api_key, :api_secret, :mode, to: :class
18
19
 
19
20
  def initialize(options)
20
21
  raise NoCredentialsError, 'No api_key provided.' unless api_key.present?
21
22
  raise NoCredentialsError, 'No api_secret provided.' unless api_secret.present?
22
23
 
23
- self.type = options[:type].to_sym.in?([:default, :frictionless]) ? options[:type].to_sym : :default
24
+ self.type = options[:type].to_sym.in?([:strict, :frictionless]) ? options[:type].to_sym : :strict
24
25
 
25
26
  self.card_number = options[:card_number]
26
27
  self.expiration_month = options[:expiration_month]
@@ -30,7 +31,7 @@ module PayCertify
30
31
  self.message_id = options[:message_id]
31
32
  self.return_url = options[:return_url]
32
33
 
33
- self.client = PayCertify::ThreeDS::Client.new(api_key: api_key, api_secret: api_secret)
34
+ self.client = PayCertify::ThreeDS::Client.new(api_key: api_key, api_secret: api_secret, mode: mode)
34
35
  end
35
36
 
36
37
  def settings
@@ -62,7 +63,7 @@ module PayCertify
62
63
  end
63
64
 
64
65
  class << self
65
- cattr_accessor :api_key, :api_secret
66
+ cattr_accessor :api_key, :api_secret, :mode
66
67
 
67
68
  def configure(&block)
68
69
  yield self if block_given?
@@ -72,7 +73,7 @@ module PayCertify
72
73
  raise NoCredentialsError, 'No api_key provided.' unless api_key.present?
73
74
  raise NoCredentialsError, 'No api_secret provided.' unless api_secret.present?
74
75
 
75
- client = PayCertify::ThreeDS::Client.new(api_key: api_key, api_secret: api_secret)
76
+ client = PayCertify::ThreeDS::Client.new(api_key: api_key, api_secret: api_secret, mode: mode)
76
77
  PayCertify::ThreeDS::PaymentAuthentication.new(client, settings).authenticate!(callback_params)
77
78
  end
78
79
  end
@@ -0,0 +1,29 @@
1
+ require 'faraday'
2
+
3
+ module PayCertify
4
+ class ThreeDS
5
+ class Callback < HashWithIndifferentAccess
6
+
7
+ attr_accessor :params, :session
8
+
9
+ def initialize(params={}, session={})
10
+ self.params = params.to_h
11
+ self.session = session.to_h
12
+
13
+ super(self.params.merge(self.session))
14
+ end
15
+
16
+ def authentication?
17
+ !execute_transaction? && self['PaRes'].present?
18
+ end
19
+
20
+ def execute_transaction?
21
+ self['_frictionless_3ds_callback'].present?
22
+ end
23
+
24
+ def authenticate!
25
+ PayCertify::ThreeDS.authenticate!(settings: session, callback_params: params)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -4,20 +4,37 @@ module PayCertify
4
4
  class ThreeDS
5
5
  class Client
6
6
 
7
- BASE_URL = 'https://mpi.3dsintegrator.com'
7
+ API_ENDPOINT = 'https://mpi.3dsintegrator.com'
8
8
 
9
- attr_accessor :api_key, :api_secret, :response
9
+ attr_accessor :api_key, :api_secret, :mode, :response
10
10
 
11
- def initialize(api_key:, api_secret:)
11
+ def initialize(api_key:, api_secret:, mode:)
12
12
  self.api_key = api_key
13
13
  self.api_secret = api_secret
14
+ self.mode = mode.to_s.to_sym
15
+ end
16
+
17
+ def live?
18
+ mode.to_sym == :live
19
+ end
20
+
21
+ def path_prefix
22
+ @path_prefix ||= live?? 'index.php' : 'index_demo.php'
23
+ end
24
+
25
+ def base_url
26
+ @base_url ||= [API_ENDPOINT, path_prefix].join('/')
27
+ end
28
+
29
+ def path_for(path)
30
+ base_url + path
14
31
  end
15
32
 
16
33
  def post(path:, data:)
17
34
  sorted_data = JSON.generate(data.sort.to_h)
18
35
 
19
36
  response = connection.post do |request|
20
- request.url path
37
+ request.url path_for(path)
21
38
  request.headers['Content-Type'] = 'application/json'
22
39
  request.headers['x-mpi-api-key'] = api_key
23
40
  request.headers['x-mpi-signature'] = signature(path, sorted_data)
@@ -37,7 +54,7 @@ module PayCertify
37
54
 
38
55
  private
39
56
  def connection
40
- @connection ||= Faraday.new(url: BASE_URL, ssl: {verify: false}) do |faraday|
57
+ @connection ||= Faraday.new(url: API_ENDPOINT, ssl: {verify: false}) do |faraday|
41
58
  faraday.request :url_encoded
42
59
  faraday.response :logger
43
60
  faraday.adapter Faraday.default_adapter
@@ -45,7 +62,7 @@ module PayCertify
45
62
  end
46
63
 
47
64
  def signature(path, data)
48
- Digest::SHA256.hexdigest "#{api_key}#{BASE_URL}#{path}#{data}#{api_secret}"
65
+ Digest::SHA256.hexdigest "#{api_key}#{path_for(path)}#{data}#{api_secret}"
49
66
  end
50
67
 
51
68
  def respond_with(response)
@@ -35,7 +35,7 @@ module PayCertify
35
35
  raise UndefinedTypeError, 'Type is not supported: '+ type
36
36
  end
37
37
 
38
- def default
38
+ def strict
39
39
  <<-HTML.squish
40
40
  #{form}
41
41
 
@@ -48,61 +48,68 @@ module PayCertify
48
48
  end
49
49
 
50
50
  def frictionless
51
- <<-HTML.squish
51
+ html = <<-HTML.squish
52
52
  <style> #frame { display: none; } </style>
53
53
  <iframe id="frame" src="about:blank"></iframe>
54
+ <form id="callback-form" method="POST" action="#{term_url}">
55
+ <input type="hidden" name="_frictionless_3ds_callback" value="1"/>
56
+ HTML
54
57
 
55
- <form id="verification-form" action="#{term_url}" method="post">
56
- <input type="hidden" id="pares" name="pares"/>
57
- <input type="hidden" name="___verify_pares" value="1"/>
58
+ settings.each do |key, value|
59
+ html << <<-HTML.squish
60
+ <input type="hidden" name="#{key}" value="#{value}"/>
61
+ HTML
62
+ end
63
+
64
+ html << <<-HTML.squish
58
65
  </form>
59
66
 
60
67
  <script>
61
68
  (function(){
62
69
  var frame = document.getElementById('frame');
63
- var form = document.getElementById('verification-form');
64
- var submitForm = false;
65
- var saveBeforeUnload = false;
66
-
67
- setInterval(function() {
68
- if (saveBeforeUnload) {
69
- saveBeforeUnload = false;
70
- console.log('SAVE!');
71
- window.onbeforeunload = null;
72
- document.createElement('form').submit.call(form);
73
- }
74
- }, 500);
75
-
76
-
77
-
78
- var exitPoll = function() {
79
- if (submitForm == false) {
80
- saveBeforeUnload = true;
81
- return "Transaction is still processing";
82
- }
83
- };
84
-
85
- window.onbeforeunload = exitPoll;
70
+ var form = document.getElementById('callback-form');
71
+ var interval = 500;
72
+ var timeout = interval * 30;
73
+ var counter = 0;
86
74
 
87
75
  frame.contentDocument.write('#{form}');
88
76
  frame.contentDocument.form3ds.submit();
89
-
90
-
91
- window.onmessage = function(e){
92
- console.log(e);
93
- if (e.data.PaRes != '') {
94
- j = e.data;
95
- var pinput = document.getElementById('pares');
96
- pinput.value = j;
97
- submitForm = true;
98
- document.createElement('form').submit.call(form);
99
- console.log('response received');
100
- clearInterval(tid);
77
+
78
+ setInterval(function() {
79
+ counter = counter + interval;
80
+
81
+ if (counter < timeout) {
82
+ try {
83
+ var frameContent = frame.contentDocument;
84
+ var frameDoc = frameContent.documentElement;
85
+
86
+ var text = frameContent.body.innerHTML || frameDoc.textContent || frameDoc.innerText;
87
+ var json = JSON.parse(text);
88
+
89
+ var input;
90
+
91
+ for(key in json) {
92
+ input = document.createElement('input');
93
+ input.type = 'hidden';
94
+ input.name = key;
95
+ input.value = json[key];
96
+
97
+ form.appendChild(input);
98
+ };
99
+
100
+ form.submit();
101
+ } catch(e) {
102
+ return false;
103
+ };
104
+ } else {
105
+ form.submit();
101
106
  }
102
- };
107
+ }, interval);
103
108
  })();
104
109
  </script>
105
110
  HTML
111
+
112
+ html
106
113
  end
107
114
 
108
115
  private
@@ -2,9 +2,9 @@ module PayCertify
2
2
  class ThreeDS
3
3
  class PaymentAuthentication
4
4
 
5
- ENROLLED_STATUS_PATH = '/index.php/enrolled-status'
6
- PAREQ_PATH = '/index.php/auth-request'
7
- PARES_PATH = '/index.php/auth-response'
5
+ ENROLLED_STATUS_PATH = '/enrolled-status'
6
+ PAREQ_PATH = '/auth-request'
7
+ PARES_PATH = '/auth-response'
8
8
 
9
9
  FIELDS = %w(pan card_exp_month card_exp_year amount transaction_id return_url)
10
10
 
@@ -34,7 +34,8 @@ module PayCertify
34
34
  validate!
35
35
  self.params = params.merge(pares: callback_params['PaRes'])
36
36
 
37
- client.post(path: PARES_PATH, data: params)
37
+ response = client.post(path: PARES_PATH, data: params)
38
+ params.merge(pares: callback_params['PaRes']).merge(response)
38
39
  end
39
40
 
40
41
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paycertify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - PayCertify Engineering Team
@@ -46,6 +46,7 @@ extra_rdoc_files: []
46
46
  files:
47
47
  - lib/paycertify.rb
48
48
  - lib/paycertify/three_ds.rb
49
+ - lib/paycertify/three_ds/callback.rb
49
50
  - lib/paycertify/three_ds/client.rb
50
51
  - lib/paycertify/three_ds/form.rb
51
52
  - lib/paycertify/three_ds/payment_authentication.rb