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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73394e0bc6f1d06f09f82d27c78190e885e02942
|
4
|
+
data.tar.gz: 1059912be2fe0e25f280d539c2e28a3a72781c2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4723260c7476caac031a519c7dcdfd6b89ac6676a9303b820e4c97f51d53e27ce5881af5fcb98b77d8c46813f7af7408d698cea578620a042924def88db5630
|
7
|
+
data.tar.gz: 45dde778b7a4bd12f436932a878b14ae1ea077d83636ff58aead9ab984b5b736334dab3e11b4536c63cc9bdc44ab0b9df9820aeb19498d7134799c78c5f12831
|
data/lib/paycertify/three_ds.rb
CHANGED
@@ -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?([:
|
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
|
-
|
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:
|
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}#{
|
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
|
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
|
-
|
56
|
-
|
57
|
-
<input type="hidden" name="
|
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('
|
64
|
-
var
|
65
|
-
var
|
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
|
-
|
92
|
-
|
93
|
-
if (
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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 = '/
|
6
|
-
PAREQ_PATH = '/
|
7
|
-
PARES_PATH = '/
|
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
|
+
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
|