mangopay 3.24.0 → 3.25.0

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
  SHA256:
3
- metadata.gz: 7321bd891306f53afcbd49ecb871a872f7899d2ee039688392b076ee64c45142
4
- data.tar.gz: c93e03ce101e31b67def7784e6a1d9490ca4cf5d4254f312f6cda02d32f528ec
3
+ metadata.gz: dfbda16f8ea316a00735545fa9c670f5ecbbe7dadc389ebecc37909a24c29be6
4
+ data.tar.gz: 774766d50d6351820e1b33dd6cc43beaba2b137756318ed4a22c0b079cd4fdac
5
5
  SHA512:
6
- metadata.gz: 889df791bf8d890fedbaca69373b91f7f14bb332b9bd2bda09524bfe8d5438c04c0189aea216627c097ccfb1453c1b8f5f4fcb53f6c90d328c04b143e47b75bb
7
- data.tar.gz: 91c75bf32947a0eb9023d309164a5e416fb80744ca9516da1843b51dff4fdf01b7136c3c3489a3d50aecfa868c735c7f65330eebfe8f1e9ee37cbbaf79ad98de
6
+ metadata.gz: e003221ba09f9358431c661d5bc85be4b6c0893ef7369b8e770a2d98a5a5a30ec73994037509519dcda0ee859af674610481c3dee5ec01109d97abc1000364cd
7
+ data.tar.gz: 3c42d1785055f226161c6aa728db75e40016fb9f08cf947b63f25862268c52b124ad076920cdc6faddfbf679c26ef80a67e7c70fc1f575780804c09b0cfcb611
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [3.25.0] - 2024-04-16
2
+ ### Added
3
+
4
+ - Add trace header logging : Introduced the `log_trace_headers` boolean configuration key. Set it to true to enable logging of `x_mangopay_trace-id` and `IdempotencyKey` in the log of the http requests.
5
+
6
+ ## [3.24.1] - 2024-04-10
7
+ ### Fixed
8
+
9
+ - #249 Improve error handling when logging is enabled
10
+ - #226 MultiJson::ParseError is thrown on HTTP error 5XX
11
+
1
12
  ## [3.24.0] - 2024-04-02
2
13
  ### Added
3
14
 
@@ -1,3 +1,3 @@
1
1
  module MangoPay
2
- VERSION = '3.24.0'
2
+ VERSION = '3.25.0'
3
3
  end
data/lib/mangopay.rb CHANGED
@@ -5,6 +5,7 @@ require 'multi_json'
5
5
  require 'benchmark'
6
6
  require 'logger'
7
7
  require 'time'
8
+ require 'securerandom'
8
9
 
9
10
  # helpers
10
11
  require 'mangopay/version'
@@ -55,7 +56,7 @@ module MangoPay
55
56
  class Configuration
56
57
  attr_accessor :preproduction, :root_url,
57
58
  :client_id, :client_apiKey,
58
- :temp_dir, :log_file, :http_timeout,
59
+ :temp_dir, :log_file, :log_trace_headers, :http_timeout,
59
60
  :http_max_retries, :http_open_timeout,
60
61
  :logger, :use_ssl, :uk_header_flag
61
62
 
@@ -65,6 +66,7 @@ module MangoPay
65
66
  config.client_id = @client_id
66
67
  config.client_apiKey = @client_apiKey
67
68
  config.log_file = @log_file
69
+ config.log_trace_headers = @log_trace_headers
68
70
  config.http_timeout = @http_timeout
69
71
  config.http_max_retries = @http_max_retries
70
72
  config.http_open_timeout = @http_open_timeout
@@ -101,6 +103,10 @@ module MangoPay
101
103
 
102
104
  true
103
105
  end
106
+
107
+ def log_trace_headers
108
+ @log_trace_headers || false
109
+ end
104
110
 
105
111
  def uk_header_flag
106
112
  @uk_header_flag || false
@@ -214,7 +220,13 @@ module MangoPay
214
220
  raise MangoPay::ResponseError.new(uri, '408', {'Message' => 'Request Timeout'}) if res.nil?
215
221
 
216
222
  # decode json data
217
- data = res.body.to_s.empty? ? {} : JSON.load(res.body.to_s)
223
+ begin
224
+ data = res.body.to_s.empty? ? {} : JSON.load(res.body.to_s)
225
+ rescue MultiJson::ParseError
226
+ details = {}
227
+ details['Message'] = res.body
228
+ raise MangoPay::ResponseError.new(uri, res.code, details)
229
+ end
218
230
 
219
231
  unless res.is_a?(Net::HTTPOK)
220
232
  raise MangoPay::ResponseError.new(uri, res.code, data)
@@ -268,6 +280,9 @@ module MangoPay
268
280
  'Authorization' => "#{auth_token['token_type']} #{auth_token['access_token']}",
269
281
  'Content-Type' => 'application/json'
270
282
  }
283
+ if configuration.log_trace_headers
284
+ headers.update('x_mangopay_trace-id' => SecureRandom.uuid)
285
+ end
271
286
  begin
272
287
  headers.update('x_mangopay_client_user_agent' => JSON.dump(user_agent))
273
288
  rescue => e
@@ -286,7 +301,12 @@ module MangoPay
286
301
  def do_request_with_log(http, req, uri)
287
302
  res, time = nil, nil
288
303
  params = FilterParameters.request(req.body)
289
- line = "[#{Time.now.iso8601}] #{req.method.upcase} \"#{uri.to_s}\" #{params}"
304
+ if configuration.log_trace_headers
305
+ trace_headers = JSON.dump({ 'Idempotency-Key' => req['Idempotency-Key'] , 'x_mangopay_trace-id' => req['x_mangopay_trace-id'] })
306
+ line = "[#{Time.now.iso8601}] #{req.method.upcase} \"#{uri.to_s}\" #{params} #{trace_headers}"
307
+ else
308
+ line = "[#{Time.now.iso8601}] #{req.method.upcase} \"#{uri.to_s}\" #{params}"
309
+ end
290
310
  begin
291
311
  time = Benchmark.realtime {
292
312
  begin
@@ -298,12 +318,17 @@ module MangoPay
298
318
  res
299
319
  ensure
300
320
  line = "#{log_severity(res)} #{line}"
321
+ if time.nil?
322
+ time_log = "[Unknown ms]"
323
+ else
324
+ time_log = "[#{(time * 1000).round(1)}ms]"
325
+ end
301
326
  if res.nil?
302
327
  params = ''
303
- line += "\n [#{(time * 1000).round(1)}ms] 408 Request Timeout #{params}\n"
328
+ line += "\n #{time_log} 408 Request Timeout #{params}\n"
304
329
  else
305
330
  params = FilterParameters.response(res.body)
306
- line += "\n [#{(time * 1000).round(1)}ms] #{res.code} #{params}\n"
331
+ line += "\n #{time_log} #{res.code} #{params}\n"
307
332
  end
308
333
  logger.info { line }
309
334
  end
@@ -6,7 +6,6 @@ describe MangoPay::CardRegistration do
6
6
  it 'creates a new card registration' do
7
7
  created = new_card_registration
8
8
  expect(created['Id']).not_to be_nil
9
- expect(created['Id'].to_i).to be > 0
10
9
  expect(created['AccessKey']).not_to be_nil
11
10
  expect(created['PreregistrationData']).not_to be_nil
12
11
  expect(created['CardRegistrationURL']).not_to be_nil
@@ -51,7 +50,6 @@ describe MangoPay::CardRegistration do
51
50
 
52
51
  # card id filled-in...
53
52
  expect(card_id).not_to be_nil
54
- expect(card_id.to_i).to be > 0
55
53
 
56
54
  # ...and points to existing (newly created) card
57
55
  card = MangoPay::Card.fetch(card_id)
@@ -7,7 +7,6 @@ describe MangoPay::PreAuthorization do
7
7
  cardreg = new_card_registration_completed
8
8
  created = new_card_preauthorization
9
9
  expect(created['Id']).not_to be_nil
10
- expect(created['Id'].to_i).to be > 0
11
10
  expect(created['CardId']).to eq(cardreg['CardId'])
12
11
  expect(created['AuthorId']).to eq(new_natural_user["Id"])
13
12
  expect(created['PayInId']).to be_nil
@@ -144,7 +144,6 @@ describe MangoPay::User do
144
144
  fetched = MangoPay::Card.fetch(card['CardId'])
145
145
 
146
146
  expect(fetched['Id']).not_to be_nil
147
- expect(fetched['Id'].to_i).to be > 0
148
147
  expect(fetched['UserId']).to eq(new_natural_user["Id"])
149
148
  expect(fetched['Currency']).to eq('EUR')
150
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangopay
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.24.0
4
+ version: 3.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoffroy Lorieux
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-04-02 00:00:00.000000000 Z
12
+ date: 2024-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json