stripe 3.1.0 → 3.2.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
  SHA1:
3
- metadata.gz: 4e0d93e7805ba65b7f5dcfe753298a8be427fc1d
4
- data.tar.gz: 3a59dcb60834e656c55f37368c8f957bb9d23486
3
+ metadata.gz: cc6007a4a7e4fe882d757b6d98c32a8c4ebe5cd0
4
+ data.tar.gz: 11fd5cc602368b14af8e2026d7e4443b1ea5e8be
5
5
  SHA512:
6
- metadata.gz: 5a769766ed97097ae745300710ad092bc6646ec85d98f70686ffe71758159667e67f7758c6550a00ac74269978562a2dcf44162bc681960fb59c67ffbc04a525
7
- data.tar.gz: 2c6782650e0069887f14fa28be69e135f2e4ccaeec68ce69422972cde7e8fc28e2310de86c903c88ade3017998cb9a11a68c5ffc921bf6098deb7877de5bd85e
6
+ metadata.gz: '0499ecd568b1dc51b3dba91ca087640d68201858de6d836cd0fbaf4ef8762e7264144ac45cd4e4e5c1c4795aa58bbc81f3b4b9d125006540549e08fe7c16fafb'
7
+ data.tar.gz: 59c86405800248611f69e91a55bbf32d3885beb90ee06cd36e89bad93ee84bf0927624f292b694e99c94e286164136aff9da6eb64a33a5f9bfd47fca417444ec
@@ -1,3 +1,7 @@
1
+ === 3.2.0 2017-08-03
2
+
3
+ * Add logging for request retry account and `Stripe-Account` header
4
+
1
5
  === 3.1.0 2017-08-03
2
6
 
3
7
  * Implement request logging with `Stripe.log_level` and `STRIPE_LOG`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.2.0
@@ -56,8 +56,8 @@ module Stripe
56
56
  # Checks if an error is a problem that we should retry on. This includes both
57
57
  # socket errors that may represent an intermittent problem and some special
58
58
  # HTTP statuses.
59
- def self.should_retry?(e, retry_count)
60
- return false if retry_count >= Stripe.max_network_retries
59
+ def self.should_retry?(e, num_retries)
60
+ return false if num_retries >= Stripe.max_network_retries
61
61
 
62
62
  # Retry on timeout-related problems (either on open or read).
63
63
  return true if e.is_a?(Faraday::TimeoutError)
@@ -75,11 +75,11 @@ module Stripe
75
75
  false
76
76
  end
77
77
 
78
- def self.sleep_time(retry_count)
78
+ def self.sleep_time(num_retries)
79
79
  # Apply exponential backoff with initial_network_retry_delay on the
80
- # number of attempts so far as inputs. Do not allow the number to exceed
80
+ # number of num_retries so far as inputs. Do not allow the number to exceed
81
81
  # max_network_retry_delay.
82
- sleep_seconds = [Stripe.initial_network_retry_delay * (2 ** (retry_count - 1)), Stripe.max_network_retry_delay].min
82
+ sleep_seconds = [Stripe.initial_network_retry_delay * (2 ** (num_retries - 1)), Stripe.max_network_retry_delay].min
83
83
 
84
84
  # Apply some jitter by randomizing the value in the range of (sleep_seconds
85
85
  # / 2) to (sleep_seconds).
@@ -139,8 +139,9 @@ module Stripe
139
139
  # stores information on the request we're about to make so that we don't
140
140
  # have to pass as many parameters around for logging.
141
141
  context = RequestLogContext.new(
142
+ account: headers["Stripe-Account"],
142
143
  api_key: api_key,
143
- api_version: headers["Stripe-Version"] || Stripe.api_version,
144
+ api_version: headers["Stripe-Version"],
144
145
  idempotency_key: headers["Idempotency-Key"],
145
146
  method: method,
146
147
  path: path,
@@ -189,10 +190,10 @@ module Stripe
189
190
  end
190
191
 
191
192
  def execute_request_with_rescues(api_base, context, &block)
192
- retry_count = 0
193
+ num_retries = 0
193
194
  begin
194
195
  request_start = Time.now
195
- log_request(context)
196
+ log_request(context, num_retries)
196
197
  resp = block.call
197
198
  context = context.dup_from_response(resp)
198
199
  log_response(context, request_start, resp.status, resp.body)
@@ -213,9 +214,9 @@ module Stripe
213
214
  log_response_error(error_context, request_start, e)
214
215
  end
215
216
 
216
- if self.class.should_retry?(e, retry_count)
217
- retry_count = retry_count + 1
218
- sleep self.class.sleep_time(retry_count)
217
+ if self.class.should_retry?(e, num_retries)
218
+ num_retries += 1
219
+ sleep self.class.sleep_time(num_retries)
219
220
  retry
220
221
  end
221
222
 
@@ -224,7 +225,7 @@ module Stripe
224
225
  if e.response
225
226
  handle_error_response(e.response, error_context)
226
227
  else
227
- handle_network_error(e, error_context, retry_count, api_base)
228
+ handle_network_error(e, error_context, num_retries, api_base)
228
229
  end
229
230
 
230
231
  # Only handle errors when we know we can do so, and re-raise otherwise.
@@ -362,7 +363,7 @@ module Stripe
362
363
  end
363
364
  end
364
365
 
365
- def handle_network_error(e, context, retry_count, api_base=nil)
366
+ def handle_network_error(e, context, num_retries, api_base=nil)
366
367
  Util.log_info('Stripe OAuth error',
367
368
  error_message: e.message,
368
369
  idempotency_key: context.idempotency_key,
@@ -394,8 +395,8 @@ module Stripe
394
395
 
395
396
  end
396
397
 
397
- if retry_count > 0
398
- message += " Request was retried #{retry_count} times."
398
+ if num_retries > 0
399
+ message += " Request was retried #{num_retries} times."
399
400
  end
400
401
 
401
402
  raise APIConnectionError.new(message + "\n\n(Network error: #{e.message})")
@@ -437,11 +438,13 @@ module Stripe
437
438
  headers
438
439
  end
439
440
 
440
- def log_request(context)
441
+ def log_request(context, num_retries)
441
442
  Util.log_info("Request to Stripe API",
443
+ account: context.account,
442
444
  api_version: context.api_version,
443
445
  idempotency_key: context.idempotency_key,
444
446
  method: context.method,
447
+ num_retries: num_retries,
445
448
  path: context.path
446
449
  )
447
450
  Util.log_debug("Request details",
@@ -453,6 +456,7 @@ module Stripe
453
456
 
454
457
  def log_response(context, request_start, status, body)
455
458
  Util.log_info("Response from Stripe API",
459
+ account: context.account,
456
460
  api_version: context.api_version,
457
461
  elapsed: Time.now - request_start,
458
462
  idempotency_key: context.idempotency_key,
@@ -491,6 +495,7 @@ module Stripe
491
495
  # that we can log certain information. It's useful because it means that we
492
496
  # don't have to pass around as many parameters.
493
497
  class RequestLogContext
498
+ attr_accessor :account
494
499
  attr_accessor :api_key
495
500
  attr_accessor :api_version
496
501
  attr_accessor :idempotency_key
@@ -499,8 +504,9 @@ module Stripe
499
504
  attr_accessor :payload
500
505
  attr_accessor :request_id
501
506
 
502
- def initialize(api_key: nil, api_version: nil, idempotency_key: nil,
503
- method: nil, path: nil, payload: nil)
507
+ def initialize(account: nil, api_key: nil, api_version: nil,
508
+ idempotency_key: nil, method: nil, path: nil, payload: nil)
509
+ self.account = account
504
510
  self.api_key = api_key
505
511
  self.api_version = api_version
506
512
  self.idempotency_key = idempotency_key
@@ -528,6 +534,7 @@ module Stripe
528
534
  end
529
535
 
530
536
  context = self.dup
537
+ context.account = headers["Stripe-Account"]
531
538
  context.api_version = headers["Stripe-Version"]
532
539
  context.idempotency_key = headers["Idempotency-Key"]
533
540
  context.request_id = headers["Request-Id"]
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '3.1.0'
2
+ VERSION = '3.2.0'
3
3
  end
@@ -160,9 +160,11 @@ module Stripe
160
160
  body = JSON.generate({ object: "account" })
161
161
 
162
162
  Util.expects(:log_info).with("Request to Stripe API",
163
+ account: "acct_123",
163
164
  api_version: '2010-11-12',
164
165
  idempotency_key: "abc",
165
166
  method: :post,
167
+ num_retries: 0,
166
168
  path: "/v1/account"
167
169
  )
168
170
  Util.expects(:log_debug).with("Request details",
@@ -171,6 +173,7 @@ module Stripe
171
173
  )
172
174
 
173
175
  Util.expects(:log_info).with("Response from Stripe API",
176
+ account: "acct_123",
174
177
  api_version: '2010-11-12',
175
178
  elapsed: 0.0,
176
179
  idempotency_key: "abc",
@@ -196,6 +199,7 @@ module Stripe
196
199
  headers: {
197
200
  "Idempotency-Key" => "abc",
198
201
  "Request-Id" => "req_123",
202
+ "Stripe-Account" => "acct_123",
199
203
  "Stripe-Version" => "2010-11-12"
200
204
  }
201
205
  )
@@ -204,6 +208,7 @@ module Stripe
204
208
  client.execute_request(:post, '/v1/account',
205
209
  headers: {
206
210
  "Idempotency-Key" => "abc",
211
+ "Stripe-Account" => "acct_123",
207
212
  "Stripe-Version" => "2010-11-12"
208
213
  }
209
214
  )
@@ -211,12 +216,15 @@ module Stripe
211
216
 
212
217
  should "produce logging on API error" do
213
218
  Util.expects(:log_info).with("Request to Stripe API",
219
+ account: nil,
214
220
  api_version: nil,
215
221
  idempotency_key: nil,
216
222
  method: :post,
223
+ num_retries: 0,
217
224
  path: "/v1/account"
218
225
  )
219
226
  Util.expects(:log_info).with("Response from Stripe API",
227
+ account: nil,
220
228
  api_version: nil,
221
229
  elapsed: 0.0,
222
230
  idempotency_key: nil,
@@ -256,12 +264,15 @@ module Stripe
256
264
 
257
265
  should "produce logging on OAuth error" do
258
266
  Util.expects(:log_info).with("Request to Stripe API",
267
+ account: nil,
259
268
  api_version: nil,
260
269
  idempotency_key: nil,
261
270
  method: :post,
271
+ num_retries: 0,
262
272
  path: "/oauth/token"
263
273
  )
264
274
  Util.expects(:log_info).with("Response from Stripe API",
275
+ account: nil,
265
276
  api_version: nil,
266
277
  elapsed: 0.0,
267
278
  idempotency_key: nil,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe