stripe 5.2.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/stripe/api_operations/nested_resource.rb +28 -26
- data/lib/stripe/stripe_client.rb +6 -0
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/stripe_client_test.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d03cea94ef3cacc081d711f3f1fe3bb779791c77e35f4c087ee8c69ffecabb93
|
4
|
+
data.tar.gz: a3546067f4fe07f56ab18458691d5261f0a533760da07995dedbd3758259ec18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d821b782237ca17e82a770e6a8ec11d97732290af7f06aaae680d0830cc63b523b7e9d8831d96294f4b80a5facb42993bbddb4a27017542fafd3399b3a513aaf
|
7
|
+
data.tar.gz: 665f013eec87c9c1b9deac66cec3125a3d6e65920c1d2f45bb509c4b5371222817d6bbe53f7f05406d8f477da061c3d1c3a5e5d94b6047d0d56d3736cf3f710a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 5.3.0 - 2019-10-01
|
4
|
+
* [#853](https://github.com/stripe/stripe-ruby/pull/853) Support `Stripe-Should-Retry` header
|
5
|
+
|
3
6
|
## 5.2.0 - 2019-09-19
|
4
7
|
* [#851](https://github.com/stripe/stripe-ruby/pull/851) Introduce system for garbage collecting connection managers
|
5
8
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.3.0
|
@@ -6,7 +6,7 @@ module Stripe
|
|
6
6
|
# that it's possible to do so from a static context (i.e. without a
|
7
7
|
# pre-existing collection of subresources on the parent).
|
8
8
|
#
|
9
|
-
# For
|
9
|
+
# For example, a transfer gains the static methods for reversals so that the
|
10
10
|
# methods `.create_reversal`, `.retrieve_reversal`, `.update_reversal`,
|
11
11
|
# etc. all become available.
|
12
12
|
module NestedResource
|
@@ -14,9 +14,11 @@ module Stripe
|
|
14
14
|
resource_plural: nil)
|
15
15
|
resource_plural ||= "#{resource}s"
|
16
16
|
path ||= resource_plural
|
17
|
+
|
17
18
|
raise ArgumentError, "operations array required" if operations.nil?
|
18
19
|
|
19
20
|
resource_url_method = :"#{resource}s_url"
|
21
|
+
|
20
22
|
define_singleton_method(resource_url_method) do |id, nested_id = nil|
|
21
23
|
url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(path)}"
|
22
24
|
url += "/#{CGI.escape(nested_id)}" unless nested_id.nil?
|
@@ -27,39 +29,39 @@ module Stripe
|
|
27
29
|
case operation
|
28
30
|
when :create
|
29
31
|
define_singleton_method(:"create_#{resource}") \
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
do |id, params = {}, opts = {}|
|
33
|
+
url = send(resource_url_method, id)
|
34
|
+
resp, opts = request(:post, url, params, opts)
|
35
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
36
|
+
end
|
35
37
|
when :retrieve
|
36
38
|
define_singleton_method(:"retrieve_#{resource}") \
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
do |id, nested_id, opts = {}|
|
40
|
+
url = send(resource_url_method, id, nested_id)
|
41
|
+
resp, opts = request(:get, url, {}, opts)
|
42
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
43
|
+
end
|
42
44
|
when :update
|
43
45
|
define_singleton_method(:"update_#{resource}") \
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
do |id, nested_id, params = {}, opts = {}|
|
47
|
+
url = send(resource_url_method, id, nested_id)
|
48
|
+
resp, opts = request(:post, url, params, opts)
|
49
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
50
|
+
end
|
49
51
|
when :delete
|
50
52
|
define_singleton_method(:"delete_#{resource}") \
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
do |id, nested_id, params = {}, opts = {}|
|
54
|
+
url = send(resource_url_method, id, nested_id)
|
55
|
+
resp, opts = request(:delete, url, params, opts)
|
56
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
57
|
+
end
|
56
58
|
when :list
|
57
59
|
define_singleton_method(:"list_#{resource_plural}") \
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
do |id, params = {}, opts = {}|
|
61
|
+
url = send(resource_url_method, id)
|
62
|
+
resp, opts = request(:get, url, params, opts)
|
63
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
64
|
+
end
|
63
65
|
else
|
64
66
|
raise ArgumentError, "Unknown operation: #{operation.inspect}"
|
65
67
|
end
|
data/lib/stripe/stripe_client.rb
CHANGED
@@ -92,6 +92,12 @@ module Stripe
|
|
92
92
|
return true if error.is_a?(SocketError)
|
93
93
|
|
94
94
|
if error.is_a?(Stripe::StripeError)
|
95
|
+
# The API may ask us not to retry (e.g. if doing so would be a no-op),
|
96
|
+
# or advise us to retry (e.g. in cases of lock timeouts). Defer to
|
97
|
+
# those instructions if given.
|
98
|
+
return false if error.http_headers["stripe-should-retry"] == "false"
|
99
|
+
return true if error.http_headers["stripe-should-retry"] == "true"
|
100
|
+
|
95
101
|
# 409 Conflict
|
96
102
|
return true if error.http_status == 409
|
97
103
|
|
data/lib/stripe/version.rb
CHANGED
@@ -171,6 +171,28 @@ module Stripe
|
|
171
171
|
method: :post, num_retries: 0)
|
172
172
|
end
|
173
173
|
|
174
|
+
should "retry when the `Stripe-Should-Retry` header is `true`" do
|
175
|
+
headers = StripeResponse::Headers.new(
|
176
|
+
"Stripe-Should-Retry" => ["true"]
|
177
|
+
)
|
178
|
+
|
179
|
+
# Note we send status 400 here, which would normally not be retried.
|
180
|
+
assert StripeClient.should_retry?(Stripe::StripeError.new(http_headers: headers,
|
181
|
+
http_status: 400),
|
182
|
+
method: :post, num_retries: 0)
|
183
|
+
end
|
184
|
+
|
185
|
+
should "not retry when the `Stripe-Should-Retry` header is `false`" do
|
186
|
+
headers = StripeResponse::Headers.new(
|
187
|
+
"Stripe-Should-Retry" => ["false"]
|
188
|
+
)
|
189
|
+
|
190
|
+
# Note we send status 409 here, which would normally be retried.
|
191
|
+
refute StripeClient.should_retry?(Stripe::StripeError.new(http_headers: headers,
|
192
|
+
http_status: 409),
|
193
|
+
method: :post, num_retries: 0)
|
194
|
+
end
|
195
|
+
|
174
196
|
should "retry on a 409 Conflict" do
|
175
197
|
assert StripeClient.should_retry?(Stripe::StripeError.new(http_status: 409),
|
176
198
|
method: :post, num_retries: 0)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Stripe is the easiest way to accept payments online. See https://stripe.com
|
14
14
|
for details.
|