stripe 5.31.0 → 5.35.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 +18 -0
- data/VERSION +1 -1
- data/lib/stripe/api_operations/request.rb +35 -2
- data/lib/stripe/api_resource.rb +8 -0
- data/lib/stripe/connection_manager.rb +17 -2
- data/lib/stripe/object_types.rb +3 -0
- data/lib/stripe/resources.rb +3 -0
- data/lib/stripe/resources/identity/verification_report.rb +12 -0
- data/lib/stripe/resources/identity/verification_session.rb +35 -0
- data/lib/stripe/resources/tax_code.rb +10 -0
- data/lib/stripe/stripe_client.rb +120 -57
- data/lib/stripe/stripe_response.rb +80 -52
- data/lib/stripe/util.rb +3 -1
- data/lib/stripe/version.rb +1 -1
- data/stripe.gemspec +9 -2
- metadata +9 -198
- data/.editorconfig +0 -10
- data/.gitattributes +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -5
- data/.github/workflows/ci.yml +0 -34
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -81
- data/.rubocop_todo.yml +0 -33
- data/.travis.yml +0 -38
- data/.vscode/extensions.json +0 -7
- data/.vscode/settings.json +0 -8
- data/test/openapi/README.md +0 -9
- data/test/stripe/account_link_test.rb +0 -18
- data/test/stripe/account_test.rb +0 -412
- data/test/stripe/alipay_account_test.rb +0 -37
- data/test/stripe/api_operations_test.rb +0 -80
- data/test/stripe/api_resource_test.rb +0 -646
- data/test/stripe/apple_pay_domain_test.rb +0 -46
- data/test/stripe/application_fee_refund_test.rb +0 -37
- data/test/stripe/application_fee_test.rb +0 -58
- data/test/stripe/balance_test.rb +0 -13
- data/test/stripe/balance_transaction_test.rb +0 -20
- data/test/stripe/bank_account_test.rb +0 -36
- data/test/stripe/billing_portal/configuration_test.rb +0 -37
- data/test/stripe/billing_portal/session_test.rb +0 -18
- data/test/stripe/capability_test.rb +0 -45
- data/test/stripe/charge_test.rb +0 -64
- data/test/stripe/checkout/session_test.rb +0 -53
- data/test/stripe/connection_manager_test.rb +0 -210
- data/test/stripe/country_spec_test.rb +0 -20
- data/test/stripe/coupon_test.rb +0 -61
- data/test/stripe/credit_note_test.rb +0 -90
- data/test/stripe/customer_balance_transaction_test.rb +0 -37
- data/test/stripe/customer_card_test.rb +0 -48
- data/test/stripe/customer_test.rb +0 -226
- data/test/stripe/dispute_test.rb +0 -51
- data/test/stripe/ephemeral_key_test.rb +0 -93
- data/test/stripe/errors_test.rb +0 -53
- data/test/stripe/exchange_rate_test.rb +0 -20
- data/test/stripe/file_link_test.rb +0 -41
- data/test/stripe/file_test.rb +0 -87
- data/test/stripe/instrumentation_test.rb +0 -74
- data/test/stripe/invoice_item_test.rb +0 -66
- data/test/stripe/invoice_line_item_test.rb +0 -8
- data/test/stripe/invoice_test.rb +0 -229
- data/test/stripe/issuing/authorization_test.rb +0 -72
- data/test/stripe/issuing/card_test.rb +0 -74
- data/test/stripe/issuing/cardholder_test.rb +0 -53
- data/test/stripe/issuing/dispute_test.rb +0 -54
- data/test/stripe/issuing/transaction_test.rb +0 -48
- data/test/stripe/list_object_test.rb +0 -202
- data/test/stripe/login_link_test.rb +0 -37
- data/test/stripe/mandate_test.rb +0 -14
- data/test/stripe/multipart_encoder_test.rb +0 -130
- data/test/stripe/oauth_test.rb +0 -149
- data/test/stripe/order_return_test.rb +0 -21
- data/test/stripe/order_test.rb +0 -82
- data/test/stripe/payment_intent_test.rb +0 -107
- data/test/stripe/payment_method_test.rb +0 -84
- data/test/stripe/payout_test.rb +0 -72
- data/test/stripe/person_test.rb +0 -46
- data/test/stripe/plan_test.rb +0 -98
- data/test/stripe/price_test.rb +0 -48
- data/test/stripe/product_test.rb +0 -58
- data/test/stripe/promotion_code_test.rb +0 -42
- data/test/stripe/radar/early_fraud_warning_test.rb +0 -22
- data/test/stripe/radar/value_list_item_test.rb +0 -48
- data/test/stripe/radar/value_list_test.rb +0 -61
- data/test/stripe/recipient_test.rb +0 -62
- data/test/stripe/refund_test.rb +0 -39
- data/test/stripe/reporting/report_run_test.rb +0 -33
- data/test/stripe/reporting/report_type_test.rb +0 -22
- data/test/stripe/reversal_test.rb +0 -43
- data/test/stripe/review_test.rb +0 -27
- data/test/stripe/setup_attempt_test.rb +0 -16
- data/test/stripe/setup_intent_test.rb +0 -84
- data/test/stripe/sigma/scheduled_query_run_test.rb +0 -22
- data/test/stripe/sku_test.rb +0 -60
- data/test/stripe/source_test.rb +0 -119
- data/test/stripe/stripe_client_test.rb +0 -1456
- data/test/stripe/stripe_configuration_test.rb +0 -159
- data/test/stripe/stripe_object_test.rb +0 -510
- data/test/stripe/stripe_response_test.rb +0 -95
- data/test/stripe/subscription_item_test.rb +0 -84
- data/test/stripe/subscription_schedule_test.rb +0 -82
- data/test/stripe/subscription_test.rb +0 -80
- data/test/stripe/tax_id_test.rb +0 -31
- data/test/stripe/tax_rate_test.rb +0 -43
- data/test/stripe/terminal/connection_token_test.rb +0 -16
- data/test/stripe/terminal/location_test.rb +0 -68
- data/test/stripe/terminal/reader_test.rb +0 -62
- data/test/stripe/three_d_secure_test.rb +0 -23
- data/test/stripe/topup_test.rb +0 -62
- data/test/stripe/transfer_test.rb +0 -88
- data/test/stripe/usage_record_summary_test.rb +0 -29
- data/test/stripe/util_test.rb +0 -402
- data/test/stripe/webhook_endpoint_test.rb +0 -59
- data/test/stripe/webhook_test.rb +0 -135
- data/test/stripe_mock.rb +0 -78
- data/test/stripe_test.rb +0 -137
- data/test/test_data.rb +0 -61
- data/test/test_helper.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f51ef2fd825e626807098544261c034bf55a84cf59852a7ac1c88a213add62ca
|
4
|
+
data.tar.gz: 6df0829f6b372f47393a5a22cc8aba022c40620188c0e8c3619d41965d84837b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0c7c97de7a70c94ebd08659f6a0630f3508347772d2ed7a799778f2c08db2e6a1540a9b77b377f31edeadc6d5a874da4e084994c8ce23e4690512db083c987
|
7
|
+
data.tar.gz: 180af07a05467d75b0a88907bf59a0f837981ab4cd6ca16673ec4f17bedcff33e7efcf80ff482cd14517b9a2efa25095ce018011fc82b70d62a20bddc1cd2525
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 5.35.0 - 2021-06-30
|
4
|
+
* [#985](https://github.com/stripe/stripe-ruby/pull/985) Update normalize_opts to use dup instead of clone.
|
5
|
+
* [#982](https://github.com/stripe/stripe-ruby/pull/982) Deprecate travis
|
6
|
+
* [#983](https://github.com/stripe/stripe-ruby/pull/983) Add support for making a request and receiving the response as a stream.
|
7
|
+
|
8
|
+
## 5.34.0 - 2021-06-04
|
9
|
+
* [#981](https://github.com/stripe/stripe-ruby/pull/981) API Updates
|
10
|
+
* Add support for `TaxCode` API.
|
11
|
+
|
12
|
+
## 5.33.0 - 2021-05-19
|
13
|
+
* [#979](https://github.com/stripe/stripe-ruby/pull/979) Add support for the Identify VerificationSession and VerificationReport APIs
|
14
|
+
|
15
|
+
## 5.32.1 - 2021-04-05
|
16
|
+
* Correct use of regexp `match` in gemspec for old versions of Ruby
|
17
|
+
|
18
|
+
## 5.32.0 - 2021-04-05
|
19
|
+
* [#973](https://github.com/stripe/stripe-ruby/pull/973) Reduce packed gem size
|
20
|
+
|
3
21
|
## 5.31.0 - 2021-04-02
|
4
22
|
* [#968](https://github.com/stripe/stripe-ruby/pull/968) Allow StripeClient to be configured per instance
|
5
23
|
* [#971](https://github.com/stripe/stripe-ruby/pull/971) On config change, only clear connection managers for changed config
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.35.0
|
@@ -6,6 +6,28 @@ module Stripe
|
|
6
6
|
module ClassMethods
|
7
7
|
def execute_resource_request(method, url,
|
8
8
|
params = {}, opts = {})
|
9
|
+
execute_resource_request_internal(
|
10
|
+
:execute_request, method, url, params, opts
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute_resource_request_stream(method, url,
|
15
|
+
params = {}, opts = {},
|
16
|
+
&read_body_chunk_block)
|
17
|
+
execute_resource_request_internal(
|
18
|
+
:execute_request_stream,
|
19
|
+
method,
|
20
|
+
url,
|
21
|
+
params,
|
22
|
+
opts,
|
23
|
+
&read_body_chunk_block
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
private def execute_resource_request_internal(client_request_method_sym,
|
28
|
+
method, url,
|
29
|
+
params, opts,
|
30
|
+
&read_body_chunk_block)
|
9
31
|
params ||= {}
|
10
32
|
|
11
33
|
error_on_invalid_params(params)
|
@@ -22,10 +44,12 @@ module Stripe
|
|
22
44
|
client = headers.delete(:client)
|
23
45
|
# Assume all remaining opts must be headers
|
24
46
|
|
25
|
-
resp, opts[:api_key] = client.
|
47
|
+
resp, opts[:api_key] = client.send(
|
48
|
+
client_request_method_sym,
|
26
49
|
method, url,
|
27
50
|
api_base: api_base, api_key: api_key,
|
28
|
-
headers: headers, params: params
|
51
|
+
headers: headers, params: params,
|
52
|
+
&read_body_chunk_block
|
29
53
|
)
|
30
54
|
|
31
55
|
# Hash#select returns an array before 1.9
|
@@ -89,6 +113,15 @@ module Stripe
|
|
89
113
|
self.class.execute_resource_request(method, url, params, opts)
|
90
114
|
end
|
91
115
|
|
116
|
+
protected def execute_resource_request_stream(method, url,
|
117
|
+
params = {}, opts = {},
|
118
|
+
&read_body_chunk_block)
|
119
|
+
opts = @opts.merge(Util.normalize_opts(opts))
|
120
|
+
self.class.execute_resource_request_stream(
|
121
|
+
method, url, params, opts, &read_body_chunk_block
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
92
125
|
# See notes on `alias` above.
|
93
126
|
alias request execute_resource_request
|
94
127
|
end
|
data/lib/stripe/api_resource.rb
CHANGED
@@ -115,5 +115,13 @@ module Stripe
|
|
115
115
|
Util.convert_to_stripe_object(resp.data, opts)
|
116
116
|
end
|
117
117
|
end
|
118
|
+
|
119
|
+
protected def request_stream(method:, path:, params:, opts: {},
|
120
|
+
&read_body_chunk_block)
|
121
|
+
resp, = execute_resource_request_stream(
|
122
|
+
method, path, params, opts, &read_body_chunk_block
|
123
|
+
)
|
124
|
+
resp
|
125
|
+
end
|
118
126
|
end
|
119
127
|
end
|
@@ -66,7 +66,8 @@ module Stripe
|
|
66
66
|
|
67
67
|
# Executes an HTTP request to the given URI with the given method. Also
|
68
68
|
# allows a request body, headers, and query string to be specified.
|
69
|
-
def execute_request(method, uri, body: nil, headers: nil, query: nil
|
69
|
+
def execute_request(method, uri, body: nil, headers: nil, query: nil,
|
70
|
+
&block)
|
70
71
|
# Perform some basic argument validation because it's easy to get
|
71
72
|
# confused between strings and hashes for things like body and query
|
72
73
|
# parameters.
|
@@ -92,8 +93,22 @@ module Stripe
|
|
92
93
|
u.path
|
93
94
|
end
|
94
95
|
|
96
|
+
method_name = method.to_s.upcase
|
97
|
+
has_response_body = method_name != "HEAD"
|
98
|
+
request = Net::HTTPGenericRequest.new(
|
99
|
+
method_name,
|
100
|
+
(body ? true : false),
|
101
|
+
has_response_body,
|
102
|
+
path,
|
103
|
+
headers
|
104
|
+
)
|
105
|
+
|
95
106
|
@mutex.synchronize do
|
96
|
-
|
107
|
+
# The block parameter is special here. If a block is provided, the block
|
108
|
+
# is invoked with the Net::HTTPResponse. However, the body will not have
|
109
|
+
# been read yet in the block, and can be streamed by calling
|
110
|
+
# HTTPResponse#read_body.
|
111
|
+
connection.request(request, body, &block)
|
97
112
|
end
|
98
113
|
end
|
99
114
|
|
data/lib/stripe/object_types.rb
CHANGED
@@ -41,6 +41,8 @@ module Stripe
|
|
41
41
|
File::OBJECT_NAME => File,
|
42
42
|
File::OBJECT_NAME_ALT => File,
|
43
43
|
FileLink::OBJECT_NAME => FileLink,
|
44
|
+
Identity::VerificationReport::OBJECT_NAME => Identity::VerificationReport,
|
45
|
+
Identity::VerificationSession::OBJECT_NAME => Identity::VerificationSession,
|
44
46
|
Invoice::OBJECT_NAME => Invoice,
|
45
47
|
InvoiceItem::OBJECT_NAME => InvoiceItem,
|
46
48
|
InvoiceLineItem::OBJECT_NAME => InvoiceLineItem,
|
@@ -82,6 +84,7 @@ module Stripe
|
|
82
84
|
Subscription::OBJECT_NAME => Subscription,
|
83
85
|
SubscriptionItem::OBJECT_NAME => SubscriptionItem,
|
84
86
|
SubscriptionSchedule::OBJECT_NAME => SubscriptionSchedule,
|
87
|
+
TaxCode::OBJECT_NAME => TaxCode,
|
85
88
|
TaxId::OBJECT_NAME => TaxId,
|
86
89
|
TaxRate::OBJECT_NAME => TaxRate,
|
87
90
|
Terminal::ConnectionToken::OBJECT_NAME => Terminal::ConnectionToken,
|
data/lib/stripe/resources.rb
CHANGED
@@ -30,6 +30,8 @@ require "stripe/resources/event"
|
|
30
30
|
require "stripe/resources/exchange_rate"
|
31
31
|
require "stripe/resources/file"
|
32
32
|
require "stripe/resources/file_link"
|
33
|
+
require "stripe/resources/identity/verification_report"
|
34
|
+
require "stripe/resources/identity/verification_session"
|
33
35
|
require "stripe/resources/invoice"
|
34
36
|
require "stripe/resources/invoice_item"
|
35
37
|
require "stripe/resources/invoice_line_item"
|
@@ -71,6 +73,7 @@ require "stripe/resources/source_transaction"
|
|
71
73
|
require "stripe/resources/subscription"
|
72
74
|
require "stripe/resources/subscription_item"
|
73
75
|
require "stripe/resources/subscription_schedule"
|
76
|
+
require "stripe/resources/tax_code"
|
74
77
|
require "stripe/resources/tax_id"
|
75
78
|
require "stripe/resources/tax_rate"
|
76
79
|
require "stripe/resources/terminal/connection_token"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# File generated from our OpenAPI spec
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Stripe
|
5
|
+
module Identity
|
6
|
+
class VerificationSession < APIResource
|
7
|
+
extend Stripe::APIOperations::Create
|
8
|
+
extend Stripe::APIOperations::List
|
9
|
+
include Stripe::APIOperations::Save
|
10
|
+
|
11
|
+
OBJECT_NAME = "identity.verification_session"
|
12
|
+
|
13
|
+
custom_method :cancel, http_verb: :post
|
14
|
+
custom_method :redact, http_verb: :post
|
15
|
+
|
16
|
+
def cancel(params = {}, opts = {})
|
17
|
+
request_stripe_object(
|
18
|
+
method: :post,
|
19
|
+
path: resource_url + "/cancel",
|
20
|
+
params: params,
|
21
|
+
opts: opts
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def redact(params = {}, opts = {})
|
26
|
+
request_stripe_object(
|
27
|
+
method: :post,
|
28
|
+
path: resource_url + "/redact",
|
29
|
+
params: params,
|
30
|
+
opts: opts
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/stripe/stripe_client.rb
CHANGED
@@ -213,62 +213,9 @@ module Stripe
|
|
213
213
|
|
214
214
|
def execute_request(method, path,
|
215
215
|
api_base: nil, api_key: nil, headers: {}, params: {})
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
unless path.is_a?(String)
|
220
|
-
|
221
|
-
api_base ||= config.api_base
|
222
|
-
api_key ||= config.api_key
|
223
|
-
params = Util.objects_to_ids(params)
|
224
|
-
|
225
|
-
check_api_key!(api_key)
|
226
|
-
|
227
|
-
body_params = nil
|
228
|
-
query_params = nil
|
229
|
-
case method
|
230
|
-
when :get, :head, :delete
|
231
|
-
query_params = params
|
232
|
-
else
|
233
|
-
body_params = params
|
234
|
-
end
|
235
|
-
|
236
|
-
query_params, path = merge_query_params(query_params, path)
|
237
|
-
|
238
|
-
headers = request_headers(api_key, method)
|
239
|
-
.update(Util.normalize_headers(headers))
|
240
|
-
url = api_url(path, api_base)
|
241
|
-
|
242
|
-
# Merge given query parameters with any already encoded in the path.
|
243
|
-
query = query_params ? Util.encode_parameters(query_params) : nil
|
244
|
-
|
245
|
-
# Encoding body parameters is a little more complex because we may have
|
246
|
-
# to send a multipart-encoded body. `body_log` is produced separately as
|
247
|
-
# a log-friendly variant of the encoded form. File objects are displayed
|
248
|
-
# as such instead of as their file contents.
|
249
|
-
body, body_log =
|
250
|
-
body_params ? encode_body(body_params, headers) : [nil, nil]
|
251
|
-
|
252
|
-
# stores information on the request we're about to make so that we don't
|
253
|
-
# have to pass as many parameters around for logging.
|
254
|
-
context = RequestLogContext.new
|
255
|
-
context.account = headers["Stripe-Account"]
|
256
|
-
context.api_key = api_key
|
257
|
-
context.api_version = headers["Stripe-Version"]
|
258
|
-
context.body = body_log
|
259
|
-
context.idempotency_key = headers["Idempotency-Key"]
|
260
|
-
context.method = method
|
261
|
-
context.path = path
|
262
|
-
context.query = query
|
263
|
-
|
264
|
-
http_resp = execute_request_with_rescues(method, api_base, context) do
|
265
|
-
self.class
|
266
|
-
.default_connection_manager(config)
|
267
|
-
.execute_request(method, url,
|
268
|
-
body: body,
|
269
|
-
headers: headers,
|
270
|
-
query: query)
|
271
|
-
end
|
216
|
+
http_resp, api_key = execute_request_internal(
|
217
|
+
method, path, api_base, api_key, headers, params
|
218
|
+
)
|
272
219
|
|
273
220
|
begin
|
274
221
|
resp = StripeResponse.from_net_http(http_resp)
|
@@ -284,6 +231,38 @@ module Stripe
|
|
284
231
|
[resp, api_key]
|
285
232
|
end
|
286
233
|
|
234
|
+
# Executes a request and returns the body as a stream instead of converting
|
235
|
+
# it to a StripeObject. This should be used for any request where we expect
|
236
|
+
# an arbitrary binary response.
|
237
|
+
#
|
238
|
+
# A `read_body_chunk` block can be passed, which will be called repeatedly
|
239
|
+
# with the body chunks read from the socket.
|
240
|
+
#
|
241
|
+
# If a block is passed, a StripeHeadersOnlyResponse is returned as the
|
242
|
+
# block is expected to do all the necessary body processing. If no block is
|
243
|
+
# passed, then a StripeStreamResponse is returned containing an IO stream
|
244
|
+
# with the response body.
|
245
|
+
def execute_request_stream(method, path,
|
246
|
+
api_base: nil, api_key: nil,
|
247
|
+
headers: {}, params: {},
|
248
|
+
&read_body_chunk_block)
|
249
|
+
unless block_given?
|
250
|
+
raise ArgumentError,
|
251
|
+
"execute_request_stream requires a read_body_chunk_block"
|
252
|
+
end
|
253
|
+
|
254
|
+
http_resp, api_key = execute_request_internal(
|
255
|
+
method, path, api_base, api_key, headers, params, &read_body_chunk_block
|
256
|
+
)
|
257
|
+
|
258
|
+
# When the read_body_chunk_block is given, we no longer have access to the
|
259
|
+
# response body at this point and so return a response object containing
|
260
|
+
# only the headers. This is because the body was consumed by the block.
|
261
|
+
resp = StripeHeadersOnlyResponse.from_net_http(http_resp)
|
262
|
+
|
263
|
+
[resp, api_key]
|
264
|
+
end
|
265
|
+
|
287
266
|
def store_last_response(object_id, resp)
|
288
267
|
return unless last_response_has_key?(object_id)
|
289
268
|
|
@@ -451,6 +430,83 @@ module Stripe
|
|
451
430
|
pruned_contexts.count
|
452
431
|
end
|
453
432
|
|
433
|
+
private def execute_request_internal(method, path,
|
434
|
+
api_base, api_key, headers, params,
|
435
|
+
&read_body_chunk_block)
|
436
|
+
raise ArgumentError, "method should be a symbol" \
|
437
|
+
unless method.is_a?(Symbol)
|
438
|
+
raise ArgumentError, "path should be a string" \
|
439
|
+
unless path.is_a?(String)
|
440
|
+
|
441
|
+
api_base ||= config.api_base
|
442
|
+
api_key ||= config.api_key
|
443
|
+
params = Util.objects_to_ids(params)
|
444
|
+
|
445
|
+
check_api_key!(api_key)
|
446
|
+
|
447
|
+
body_params = nil
|
448
|
+
query_params = nil
|
449
|
+
case method
|
450
|
+
when :get, :head, :delete
|
451
|
+
query_params = params
|
452
|
+
else
|
453
|
+
body_params = params
|
454
|
+
end
|
455
|
+
|
456
|
+
query_params, path = merge_query_params(query_params, path)
|
457
|
+
|
458
|
+
headers = request_headers(api_key, method)
|
459
|
+
.update(Util.normalize_headers(headers))
|
460
|
+
url = api_url(path, api_base)
|
461
|
+
|
462
|
+
# Merge given query parameters with any already encoded in the path.
|
463
|
+
query = query_params ? Util.encode_parameters(query_params) : nil
|
464
|
+
|
465
|
+
# Encoding body parameters is a little more complex because we may have
|
466
|
+
# to send a multipart-encoded body. `body_log` is produced separately as
|
467
|
+
# a log-friendly variant of the encoded form. File objects are displayed
|
468
|
+
# as such instead of as their file contents.
|
469
|
+
body, body_log =
|
470
|
+
body_params ? encode_body(body_params, headers) : [nil, nil]
|
471
|
+
|
472
|
+
# stores information on the request we're about to make so that we don't
|
473
|
+
# have to pass as many parameters around for logging.
|
474
|
+
context = RequestLogContext.new
|
475
|
+
context.account = headers["Stripe-Account"]
|
476
|
+
context.api_key = api_key
|
477
|
+
context.api_version = headers["Stripe-Version"]
|
478
|
+
context.body = body_log
|
479
|
+
context.idempotency_key = headers["Idempotency-Key"]
|
480
|
+
context.method = method
|
481
|
+
context.path = path
|
482
|
+
context.query = query
|
483
|
+
|
484
|
+
# A block can be passed in to read the content directly from the response.
|
485
|
+
# We want to execute this block only when the response was actually
|
486
|
+
# successful. When it wasn't, we defer to the standard error handling as
|
487
|
+
# we have to read the body and parse the error JSON.
|
488
|
+
response_block =
|
489
|
+
if block_given?
|
490
|
+
lambda do |response|
|
491
|
+
unless should_handle_as_error(response.code.to_i)
|
492
|
+
response.read_body(&read_body_chunk_block)
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
http_resp = execute_request_with_rescues(method, api_base, context) do
|
498
|
+
self.class
|
499
|
+
.default_connection_manager(config)
|
500
|
+
.execute_request(method, url,
|
501
|
+
body: body,
|
502
|
+
headers: headers,
|
503
|
+
query: query,
|
504
|
+
&response_block)
|
505
|
+
end
|
506
|
+
|
507
|
+
[http_resp, api_key]
|
508
|
+
end
|
509
|
+
|
454
510
|
private def api_url(url = "", api_base = nil)
|
455
511
|
(api_base || config.api_base) + url
|
456
512
|
end
|
@@ -490,6 +546,7 @@ module Stripe
|
|
490
546
|
# that's more condusive to logging.
|
491
547
|
flattened_params =
|
492
548
|
flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
|
549
|
+
|
493
550
|
else
|
494
551
|
body = Util.encode_parameters(body_params)
|
495
552
|
end
|
@@ -503,6 +560,10 @@ module Stripe
|
|
503
560
|
[body, body_log]
|
504
561
|
end
|
505
562
|
|
563
|
+
private def should_handle_as_error(http_status)
|
564
|
+
http_status >= 400
|
565
|
+
end
|
566
|
+
|
506
567
|
private def execute_request_with_rescues(method, api_base, context)
|
507
568
|
num_retries = 0
|
508
569
|
|
@@ -520,7 +581,9 @@ module Stripe
|
|
520
581
|
http_status = resp.code.to_i
|
521
582
|
context = context.dup_from_response_headers(resp)
|
522
583
|
|
523
|
-
|
584
|
+
if should_handle_as_error(http_status)
|
585
|
+
handle_error_response(resp, context)
|
586
|
+
end
|
524
587
|
|
525
588
|
log_response(context, request_start, http_status, resp.body)
|
526
589
|
notify_request_end(context, request_duration, http_status,
|