kount_complete 3.0.0 → 3.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0594c812d04334112250610f423e7f3f1bcd57a08395df9ba2ce74a92c72a81
4
- data.tar.gz: 829832f26be3fe70c4620920983abd2ee7f5b1f7ca3ef83cbc5df7fb01dcdbc7
3
+ metadata.gz: ae5af998247f6cde23bf2838bd2340e0635047fc2e6358e81fd7af146e050db6
4
+ data.tar.gz: dda20932fedac07e0b88d215c1855f59f3aebbf8a34cdfcda07e858b6b719695
5
5
  SHA512:
6
- metadata.gz: b1c97349871d6aabef60e0598c8dad20d3a0888341302fbeb853457717eeed9b5ba8ee6143ccc3dc75f4b00cb8bccf8b8c88302a3c666487fe21f516738d1413
7
- data.tar.gz: 938011bc69fa002935991fb6127f17e997fa7561040038474cbd6118afa6f296ad176c5f576b75a2e8d7d9b86c6feac56b12f3631ece08239d91dfff434fae82
6
+ metadata.gz: 11ffa0c88b04dffa110784502e57c9cd3f56c227aceb580db1aa950df73908d77ee387c8a1724aad1d23a2b7b513fd600132b4e99c37e7d75a689c6462b449a4
7
+ data.tar.gz: ff578ed7f88cf99b9dc7d60be129a14298890acf05e8fdecc9edcd5706902cf2b4497990391573927ee7ee9b91deb511bc62a1a4fab23e88c273a2ab6d506f2a
data/lib/kount/client.rb CHANGED
@@ -36,12 +36,7 @@ module Kount
36
36
  PAYMENTS_FRAUD_AUTH_ENDPOINT_PROD = 'https://login.kount.com/oauth2/ausdppksgrbyM0abp357/v1/token'
37
37
 
38
38
  # Default endpoint for Payments Fraud by Kount 360 test. Used by the TEST_DEFAULT_OPTIONS
39
- PAYMENTS_FRAUD_AUTH_ENDPOINT_TEST = 'https://login.kount.com/oauth2/ausdppkujzCPQuIrY357/v1/token'
40
-
41
- # Migration mode enabled
42
- @migration_mode_enabled = false
43
- @access_token = ''
44
- @token_expires_at = DateTime.now
39
+ PAYMENTS_FRAUD_AUTH_ENDPOINT_TEST = 'https://login.kount.com/oauth2/ausdppksgrbyM0abp357/v1/token'
45
40
 
46
41
  # Default params for production
47
42
  PROD_DEFAULT_OPTIONS = {
@@ -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
- if @migration_mode_enabled
90
- @options[:version] = DEFAULT_VERSION # this is needed for the intg to work correctly
91
- end
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 @token_expires_at.nil? || DateTime.now >= @token_expires_at
116
+ if token_expires_at.nil? || Time.now >= token_expires_at
103
117
  refresh_pf_auth_token
104
- if @access_token.nil? || @access_token == ''
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': "Bearer #{@access_token}" })
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
@@ -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(@options[:pf_auth_endpoint], payload, headers)
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
- @access_token = data['access_token']
229
- @token_expires_at = DateTime.now.to_time + (expires_in - 60) # less 60 seconds for latency
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
@@ -8,7 +8,7 @@ module Kount
8
8
  # SDK release version
9
9
  # Set the sdk release version which will be used for git tagging in github
10
10
  # This will be set by the build process
11
- SDK_VERSION = '3.0.0'
11
+ SDK_VERSION = '3.0.1'
12
12
 
13
13
  end
14
14
  end
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.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kount
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-24 00:00:00.000000000 Z
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: http://rubygems.org/gems/kount_complete
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.6.5
47
+ rubygems_version: 3.7.2
48
48
  specification_version: 4
49
49
  summary: Kount Complete Services Wrapper
50
50
  test_files: []