kount_complete 3.0.0 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kount/client.rb +33 -20
- data/lib/kount/config.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d915e9714d91ba927e636c361ef1a9bf38ec17a2c8a346ce819aaa876ed3bc4c
|
4
|
+
data.tar.gz: def6320eb195553061c158e92964115e625c6a58619dd95d5733b250da716736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91922d4e74721897b3b5d941f56d6b8271b60a9568a4f15a4e5fa3125b5aad9451841dec16a8da92e4c93b4e7b52f8887aead8b4a4fce54d75e84d4e7ac23c38
|
7
|
+
data.tar.gz: 30e75e5341d958c98b73a0bc97951324071dbcd99bafe2fcfa4c9919c36f32c50a3a2ec307e3909690b26cfd71a39c912380a92e7eb5f9bee554574c673190e9
|
data/lib/kount/client.rb
CHANGED
@@ -38,11 +38,6 @@ module Kount
|
|
38
38
|
# Default endpoint for Payments Fraud by Kount 360 test. Used by the TEST_DEFAULT_OPTIONS
|
39
39
|
PAYMENTS_FRAUD_AUTH_ENDPOINT_TEST = 'https://login.kount.com/oauth2/ausdppkujzCPQuIrY357/v1/token'
|
40
40
|
|
41
|
-
# Migration mode enabled
|
42
|
-
@migration_mode_enabled = false
|
43
|
-
@access_token = ''
|
44
|
-
@token_expires_at = DateTime.now
|
45
|
-
|
46
41
|
# Default params for production
|
47
42
|
PROD_DEFAULT_OPTIONS = {
|
48
43
|
endpoint: ENDPOINT_PROD,
|
@@ -70,6 +65,13 @@ module Kount
|
|
70
65
|
# @param params [Hash] Hash with merchant_id, ksalt and key, plus any
|
71
66
|
# other optional params
|
72
67
|
def initialize(params = {})
|
68
|
+
# Migration mode enabled
|
69
|
+
@migration_mode_enabled = false
|
70
|
+
@access_token = ''
|
71
|
+
@token_expires_at = Time.now - 3600 # set to one hour ago to force refresh on first use
|
72
|
+
@access_token_mutex = Mutex.new
|
73
|
+
@token_expires_at_mutex = Mutex.new
|
74
|
+
|
73
75
|
@options = {}
|
74
76
|
migration_mode = params[:migration_mode_enabled]
|
75
77
|
if migration_mode.nil?
|
@@ -85,10 +87,22 @@ module Kount
|
|
85
87
|
end
|
86
88
|
|
87
89
|
@options.merge!(params)
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
+
def access_token
|
93
|
+
@access_token_mutex.synchronize { @access_token }
|
94
|
+
end
|
95
|
+
|
96
|
+
def set_access_token(token)
|
97
|
+
@access_token_mutex.synchronize { @access_token = token }
|
98
|
+
end
|
99
|
+
|
100
|
+
def token_expires_at
|
101
|
+
@token_expires_at_mutex.synchronize { @token_expires_at }
|
102
|
+
end
|
103
|
+
|
104
|
+
def set_token_expires_at(token)
|
105
|
+
@token_expires_at_mutex.synchronize { @token_expires_at = token }
|
92
106
|
end
|
93
107
|
|
94
108
|
# Makes the call to the Kount RIS server
|
@@ -99,13 +113,13 @@ module Kount
|
|
99
113
|
def get_response(request)
|
100
114
|
headers = {}
|
101
115
|
if @migration_mode_enabled
|
102
|
-
if
|
116
|
+
if token_expires_at.nil? || Time.now >= token_expires_at
|
103
117
|
refresh_pf_auth_token
|
104
|
-
if
|
118
|
+
if access_token.nil? || access_token == ''
|
105
119
|
raise RuntimeError, 'Access token could not be retrieved'
|
106
120
|
end
|
107
121
|
headers = pf_http_headers
|
108
|
-
headers.merge!({ 'Authorization'
|
122
|
+
headers.merge!({ 'Authorization' => "Bearer #{access_token}" })
|
109
123
|
end
|
110
124
|
else
|
111
125
|
headers = http_headers
|
@@ -114,7 +128,7 @@ module Kount
|
|
114
128
|
payload = URI.encode_www_form(prepare_request_params(request))
|
115
129
|
response = {}
|
116
130
|
begin
|
117
|
-
resp = http.post(http_path, payload, headers)
|
131
|
+
resp = http.post(http_path.to_s, payload, headers)
|
118
132
|
response = JSON.parse(resp.body)
|
119
133
|
rescue StandardError => e
|
120
134
|
puts e
|
@@ -181,7 +195,7 @@ module Kount
|
|
181
195
|
if endpoint_uri.host.nil? || endpoint_uri.port.nil?
|
182
196
|
raise ArgumentError, 'Invalid endpoint or port'
|
183
197
|
end
|
184
|
-
net_http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
|
198
|
+
net_http = Net::HTTP.new(endpoint_uri.host.to_s, endpoint_uri.port)
|
185
199
|
if endpoint_uri.scheme == 'https'
|
186
200
|
net_http.use_ssl = true
|
187
201
|
net_http.verify_mode = test? ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
|
@@ -207,30 +221,29 @@ module Kount
|
|
207
221
|
'Accept' => 'application/json',
|
208
222
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
209
223
|
'User-Agent' => "SDK-RIS-Ruby/#{Config::SDK_VERSION}",
|
210
|
-
'Authorization' => 'Bearer '
|
211
224
|
}
|
212
225
|
end
|
213
226
|
|
214
227
|
# rubocop:disable Metrics/AbcSize
|
215
228
|
def refresh_pf_auth_token
|
216
|
-
payload = URI.encode_www_form({ grant_type: 'client_credentials', scope: 'k1_integration_api'
|
229
|
+
payload = URI.encode_www_form({ grant_type: 'client_credentials', scope: 'k1_integration_api'})
|
217
230
|
headers = { Authorization: "Basic #{@options[:pf_api_key]}", 'Content-Type': 'application/x-www-form-urlencoded' }
|
218
231
|
uri = URI(@options[:pf_auth_endpoint])
|
219
|
-
client = Net::HTTP.new(uri.host, uri.port)
|
232
|
+
client = Net::HTTP.new(uri.host.to_s, uri.port)
|
220
233
|
client.ignore_eof = true
|
221
234
|
client.use_ssl = true
|
222
|
-
response = client.post(
|
235
|
+
response = client.post(uri.path.to_s, payload, headers)
|
223
236
|
|
224
237
|
return unless response.code == '200'
|
225
238
|
|
226
239
|
data = JSON.parse(response.body)
|
227
240
|
expires_in = data['expires_in'].to_i
|
228
|
-
|
229
|
-
|
241
|
+
set_access_token(data['access_token'])
|
242
|
+
set_token_expires_at(Time.now + (expires_in - 60)) # less 60 seconds for latency
|
230
243
|
end
|
231
244
|
|
232
245
|
def http_path
|
233
|
-
endpoint_uri.path.empty? ? '/' : endpoint_uri.path
|
246
|
+
endpoint_uri.path.to_s.empty? ? '/' : endpoint_uri.path
|
234
247
|
end
|
235
248
|
end
|
236
249
|
end
|
data/lib/kount/config.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kount_complete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kount
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: A wrapper to facilitate making Kount RIS calls
|
13
13
|
email: ruby@kount.com
|
@@ -26,7 +26,7 @@ files:
|
|
26
26
|
- lib/kount/request/update.rb
|
27
27
|
- lib/kount/security_mash.rb
|
28
28
|
- lib/kount/utils/khash.rb
|
29
|
-
homepage:
|
29
|
+
homepage: https://rubygems.org/gems/kount_complete
|
30
30
|
licenses:
|
31
31
|
- MIT
|
32
32
|
metadata: {}
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 3.6.2
|
46
46
|
requirements: []
|
47
|
-
rubygems_version: 3.
|
47
|
+
rubygems_version: 3.7.2
|
48
48
|
specification_version: 4
|
49
49
|
summary: Kount Complete Services Wrapper
|
50
50
|
test_files: []
|