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 +4 -4
- data/History.txt +4 -0
- data/VERSION +1 -1
- data/lib/stripe/stripe_client.rb +25 -18
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/stripe_client_test.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc6007a4a7e4fe882d757b6d98c32a8c4ebe5cd0
|
4
|
+
data.tar.gz: 11fd5cc602368b14af8e2026d7e4443b1ea5e8be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0499ecd568b1dc51b3dba91ca087640d68201858de6d836cd0fbaf4ef8762e7264144ac45cd4e4e5c1c4795aa58bbc81f3b4b9d125006540549e08fe7c16fafb'
|
7
|
+
data.tar.gz: 59c86405800248611f69e91a55bbf32d3885beb90ee06cd36e89bad93ee84bf0927624f292b694e99c94e286164136aff9da6eb64a33a5f9bfd47fca417444ec
|
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.0
|
data/lib/stripe/stripe_client.rb
CHANGED
@@ -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,
|
60
|
-
return false if
|
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(
|
78
|
+
def self.sleep_time(num_retries)
|
79
79
|
# Apply exponential backoff with initial_network_retry_delay on the
|
80
|
-
# number of
|
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 ** (
|
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"]
|
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
|
-
|
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,
|
217
|
-
|
218
|
-
sleep self.class.sleep_time(
|
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,
|
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,
|
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
|
398
|
-
message += " Request was retried #{
|
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(
|
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"]
|
data/lib/stripe/version.rb
CHANGED
@@ -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,
|