stripe 5.28.0 → 8.7.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 +286 -0
- data/Gemfile +5 -3
- data/Makefile +13 -0
- data/OPENAPI_VERSION +1 -0
- data/README.md +43 -5
- data/VERSION +1 -1
- data/lib/data/ca-certificates.crt +1241 -1937
- data/lib/stripe/api_operations/create.rb +6 -2
- data/lib/stripe/api_operations/delete.rb +12 -7
- data/lib/stripe/api_operations/list.rb +6 -9
- data/lib/stripe/api_operations/nested_resource.rb +62 -34
- data/lib/stripe/api_operations/request.rb +45 -2
- data/lib/stripe/api_operations/save.rb +13 -3
- data/lib/stripe/api_operations/search.rb +16 -0
- data/lib/stripe/api_resource.rb +11 -18
- data/lib/stripe/api_resource_test_helpers.rb +49 -0
- data/lib/stripe/api_version.rb +8 -0
- data/lib/stripe/connection_manager.rb +49 -11
- data/lib/stripe/error_object.rb +2 -3
- data/lib/stripe/instrumentation.rb +46 -6
- data/lib/stripe/oauth.rb +4 -3
- data/lib/stripe/object_types.rb +36 -10
- data/lib/stripe/resources/account.rb +39 -17
- data/lib/stripe/resources/account_link.rb +4 -0
- data/lib/stripe/resources/application_fee_refund.rb +7 -1
- data/lib/stripe/resources/apps/secret.rb +40 -0
- data/lib/stripe/resources/balance.rb +11 -0
- data/lib/stripe/resources/balance_transaction.rb +4 -0
- data/lib/stripe/resources/bank_account.rb +7 -0
- data/lib/stripe/resources/billing_portal/configuration.rb +15 -0
- data/lib/stripe/resources/billing_portal/session.rb +14 -0
- data/lib/stripe/resources/capability.rb +5 -1
- data/lib/stripe/resources/card.rb +6 -3
- data/lib/stripe/resources/cash_balance.rb +23 -0
- data/lib/stripe/resources/charge.rb +23 -3
- data/lib/stripe/resources/checkout/session.rb +49 -2
- data/lib/stripe/resources/country_spec.rb +6 -0
- data/lib/stripe/resources/coupon.rb +3 -0
- data/lib/stripe/resources/credit_note.rb +27 -9
- data/lib/stripe/resources/credit_note_line_item.rb +2 -0
- data/lib/stripe/resources/customer.rb +132 -4
- data/lib/stripe/resources/customer_balance_transaction.rb +9 -2
- data/lib/stripe/resources/customer_cash_balance_transaction.rb +14 -0
- data/lib/stripe/resources/discount.rb +5 -0
- data/lib/stripe/resources/dispute.rb +17 -3
- data/lib/stripe/resources/event.rb +29 -0
- data/lib/stripe/resources/exchange_rate.rb +11 -0
- data/lib/stripe/resources/file.rb +9 -1
- data/lib/stripe/resources/file_link.rb +3 -0
- data/lib/stripe/resources/financial_connections/account.rb +67 -0
- data/lib/stripe/resources/financial_connections/account_owner.rb +11 -0
- data/lib/stripe/resources/financial_connections/account_ownership.rb +11 -0
- data/lib/stripe/resources/financial_connections/session.rb +13 -0
- data/lib/stripe/resources/funding_instructions.rb +21 -0
- data/lib/stripe/resources/identity/verification_report.rb +23 -0
- data/lib/stripe/resources/identity/verification_session.rb +61 -0
- data/lib/stripe/resources/invoice.rb +105 -17
- data/lib/stripe/resources/invoice_item.rb +11 -0
- data/lib/stripe/resources/invoice_line_item.rb +1 -0
- data/lib/stripe/resources/issuing/authorization.rb +25 -5
- data/lib/stripe/resources/issuing/card.rb +78 -8
- data/lib/stripe/resources/issuing/cardholder.rb +3 -0
- data/lib/stripe/resources/issuing/dispute.rb +13 -3
- data/lib/stripe/resources/issuing/transaction.rb +5 -0
- data/lib/stripe/resources/line_item.rb +2 -0
- data/lib/stripe/resources/login_link.rb +2 -0
- data/lib/stripe/resources/mandate.rb +1 -0
- data/lib/stripe/resources/payment_intent.rb +103 -6
- data/lib/stripe/resources/payment_link.rb +35 -0
- data/lib/stripe/resources/payment_method.rb +25 -5
- data/lib/stripe/resources/payout.rb +28 -5
- data/lib/stripe/resources/person.rb +7 -0
- data/lib/stripe/resources/plan.rb +8 -0
- data/lib/stripe/resources/price.rb +15 -0
- data/lib/stripe/resources/product.rb +17 -0
- data/lib/stripe/resources/promotion_code.rb +2 -0
- data/lib/stripe/resources/quote.rb +128 -0
- data/lib/stripe/resources/radar/early_fraud_warning.rb +4 -0
- data/lib/stripe/resources/radar/value_list.rb +3 -0
- data/lib/stripe/resources/radar/value_list_item.rb +3 -0
- data/lib/stripe/resources/refund.rb +49 -0
- data/lib/stripe/resources/reporting/report_run.rb +8 -0
- data/lib/stripe/resources/reporting/report_type.rb +8 -1
- data/lib/stripe/resources/reversal.rb +16 -2
- data/lib/stripe/resources/review.rb +14 -3
- data/lib/stripe/resources/setup_attempt.rb +4 -0
- data/lib/stripe/resources/setup_intent.rb +60 -5
- data/lib/stripe/resources/shipping_rate.rb +14 -0
- data/lib/stripe/resources/sigma/scheduled_query_run.rb +4 -0
- data/lib/stripe/resources/source.rb +26 -6
- data/lib/stripe/resources/source_transaction.rb +5 -0
- data/lib/stripe/resources/subscription.rb +57 -3
- data/lib/stripe/resources/subscription_item.rb +2 -7
- data/lib/stripe/resources/subscription_schedule.rb +23 -5
- data/lib/stripe/resources/tax/calculation.rb +33 -0
- data/lib/stripe/resources/tax/calculation_line_item.rb +10 -0
- data/lib/stripe/resources/tax/settings.rb +15 -0
- data/lib/stripe/resources/tax/transaction.rb +49 -0
- data/lib/stripe/resources/tax/transaction_line_item.rb +10 -0
- data/lib/stripe/resources/tax_code.rb +11 -0
- data/lib/stripe/resources/tax_id.rb +5 -0
- data/lib/stripe/resources/tax_rate.rb +3 -0
- data/lib/stripe/resources/terminal/configuration.rb +16 -0
- data/lib/stripe/resources/terminal/connection_token.rb +3 -0
- data/lib/stripe/resources/terminal/location.rb +3 -0
- data/lib/stripe/resources/terminal/reader.rb +119 -0
- data/lib/stripe/resources/test_helpers/test_clock.rb +35 -0
- data/lib/stripe/resources/token.rb +20 -0
- data/lib/stripe/resources/topup.rb +15 -3
- data/lib/stripe/resources/transfer.rb +10 -11
- data/lib/stripe/resources/treasury/credit_reversal.rb +14 -0
- data/lib/stripe/resources/treasury/debit_reversal.rb +14 -0
- data/lib/stripe/resources/treasury/financial_account.rb +52 -0
- data/lib/stripe/resources/treasury/financial_account_features.rb +12 -0
- data/lib/stripe/resources/treasury/inbound_transfer.rb +94 -0
- data/lib/stripe/resources/treasury/outbound_payment.rb +96 -0
- data/lib/stripe/resources/treasury/outbound_transfer.rb +100 -0
- data/lib/stripe/resources/treasury/received_credit.rb +30 -0
- data/lib/stripe/resources/treasury/received_debit.rb +30 -0
- data/lib/stripe/resources/treasury/transaction.rb +13 -0
- data/lib/stripe/resources/treasury/transaction_entry.rb +17 -0
- data/lib/stripe/resources/usage_record.rb +5 -0
- data/lib/stripe/resources/usage_record_summary.rb +1 -0
- data/lib/stripe/resources/webhook_endpoint.rb +7 -0
- data/lib/stripe/resources.rb +34 -10
- data/lib/stripe/search_result_object.rb +86 -0
- data/lib/stripe/stripe_client.rb +267 -121
- data/lib/stripe/stripe_configuration.rb +29 -10
- data/lib/stripe/stripe_object.rb +25 -2
- data/lib/stripe/stripe_response.rb +80 -52
- data/lib/stripe/util.rb +100 -9
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +27 -23
- data/stripe.gemspec +12 -5
- metadata +46 -204
- data/.editorconfig +0 -10
- data/.gitattributes +0 -4
- data/.github/ISSUE_TEMPLATE.md +0 -5
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -80
- data/.rubocop_todo.yml +0 -33
- data/.travis.yml +0 -38
- data/.vscode/extensions.json +0 -7
- data/.vscode/settings.json +0 -8
- data/lib/stripe/resources/bitcoin_receiver.rb +0 -24
- data/lib/stripe/resources/bitcoin_transaction.rb +0 -15
- data/lib/stripe/resources/issuing/card_details.rb +0 -9
- data/lib/stripe/resources/order.rb +0 -33
- data/lib/stripe/resources/order_return.rb +0 -10
- data/lib/stripe/resources/recipient.rb +0 -14
- data/lib/stripe/resources/sku.rb +0 -13
- data/lib/stripe/resources/three_d_secure.rb +0 -14
- 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/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 -167
- 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 -104
- 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 -1291
- data/test/stripe/stripe_configuration_test.rb +0 -131
- data/test/stripe/stripe_object_test.rb +0 -500
- 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 -132
- data/test/test_data.rb +0 -61
- data/test/test_helper.rb +0 -77
@@ -86,13 +86,16 @@ module Stripe
|
|
86
86
|
val = Stripe::LEVEL_DEBUG
|
87
87
|
elsif val == "info"
|
88
88
|
val = Stripe::LEVEL_INFO
|
89
|
+
elsif val == "error"
|
90
|
+
val = Stripe::LEVEL_ERROR
|
89
91
|
end
|
90
92
|
|
91
93
|
levels = [Stripe::LEVEL_INFO, Stripe::LEVEL_DEBUG, Stripe::LEVEL_ERROR]
|
92
94
|
|
93
95
|
if !val.nil? && !levels.include?(val)
|
94
96
|
raise ArgumentError,
|
95
|
-
"log_level should only be set to `nil`, `debug
|
97
|
+
"log_level should only be set to `nil`, `debug`, `info`," \
|
98
|
+
" or `error`"
|
96
99
|
end
|
97
100
|
@log_level = val
|
98
101
|
end
|
@@ -101,14 +104,22 @@ module Stripe
|
|
101
104
|
@max_network_retries = val.to_i
|
102
105
|
end
|
103
106
|
|
107
|
+
def max_network_retry_delay=(val)
|
108
|
+
@max_network_retry_delay = val.to_i
|
109
|
+
end
|
110
|
+
|
111
|
+
def initial_network_retry_delay=(val)
|
112
|
+
@initial_network_retry_delay = val.to_i
|
113
|
+
end
|
114
|
+
|
104
115
|
def open_timeout=(open_timeout)
|
105
116
|
@open_timeout = open_timeout
|
106
|
-
StripeClient.clear_all_connection_managers
|
117
|
+
StripeClient.clear_all_connection_managers(config: self)
|
107
118
|
end
|
108
119
|
|
109
120
|
def read_timeout=(read_timeout)
|
110
121
|
@read_timeout = read_timeout
|
111
|
-
StripeClient.clear_all_connection_managers
|
122
|
+
StripeClient.clear_all_connection_managers(config: self)
|
112
123
|
end
|
113
124
|
|
114
125
|
def write_timeout=(write_timeout)
|
@@ -117,32 +128,32 @@ module Stripe
|
|
117
128
|
end
|
118
129
|
|
119
130
|
@write_timeout = write_timeout
|
120
|
-
StripeClient.clear_all_connection_managers
|
131
|
+
StripeClient.clear_all_connection_managers(config: self)
|
121
132
|
end
|
122
133
|
|
123
134
|
def proxy=(proxy)
|
124
135
|
@proxy = proxy
|
125
|
-
StripeClient.clear_all_connection_managers
|
136
|
+
StripeClient.clear_all_connection_managers(config: self)
|
126
137
|
end
|
127
138
|
|
128
139
|
def verify_ssl_certs=(verify_ssl_certs)
|
129
140
|
@verify_ssl_certs = verify_ssl_certs
|
130
|
-
StripeClient.clear_all_connection_managers
|
141
|
+
StripeClient.clear_all_connection_managers(config: self)
|
131
142
|
end
|
132
143
|
|
133
144
|
def uploads_base=(uploads_base)
|
134
145
|
@uploads_base = uploads_base
|
135
|
-
StripeClient.clear_all_connection_managers
|
146
|
+
StripeClient.clear_all_connection_managers(config: self)
|
136
147
|
end
|
137
148
|
|
138
149
|
def connect_base=(connect_base)
|
139
150
|
@connect_base = connect_base
|
140
|
-
StripeClient.clear_all_connection_managers
|
151
|
+
StripeClient.clear_all_connection_managers(config: self)
|
141
152
|
end
|
142
153
|
|
143
154
|
def api_base=(api_base)
|
144
155
|
@api_base = api_base
|
145
|
-
StripeClient.clear_all_connection_managers
|
156
|
+
StripeClient.clear_all_connection_managers(config: self)
|
146
157
|
end
|
147
158
|
|
148
159
|
def ca_bundle_path=(path)
|
@@ -151,7 +162,7 @@ module Stripe
|
|
151
162
|
# empty this field so a new store is initialized
|
152
163
|
@ca_store = nil
|
153
164
|
|
154
|
-
StripeClient.clear_all_connection_managers
|
165
|
+
StripeClient.clear_all_connection_managers(config: self)
|
155
166
|
end
|
156
167
|
|
157
168
|
# A certificate store initialized from the the bundle in #ca_bundle_path and
|
@@ -174,5 +185,13 @@ module Stripe
|
|
174
185
|
def enable_telemetry?
|
175
186
|
enable_telemetry
|
176
187
|
end
|
188
|
+
|
189
|
+
# Generates a deterministic key to identify configuration objects with
|
190
|
+
# identical configuration values.
|
191
|
+
def key
|
192
|
+
instance_variables
|
193
|
+
.collect { |variable| instance_variable_get(variable) }
|
194
|
+
.join
|
195
|
+
end
|
177
196
|
end
|
178
197
|
end
|
data/lib/stripe/stripe_object.rb
CHANGED
@@ -267,6 +267,27 @@ module Stripe
|
|
267
267
|
[]
|
268
268
|
end
|
269
269
|
|
270
|
+
# When designing APIs, we now make a conscious effort server-side to avoid
|
271
|
+
# naming fields after important built-ins in various languages (e.g. class,
|
272
|
+
# method, etc.).
|
273
|
+
#
|
274
|
+
# However, a long time ago we made the mistake (either consciously or by
|
275
|
+
# accident) of initializing our `metadata` fields as instances of
|
276
|
+
# `StripeObject`, and metadata can have a wide range of different keys
|
277
|
+
# defined in it. This is somewhat a convenient in that it allows users to
|
278
|
+
# access data like `obj.metadata.my_field`, but is almost certainly not
|
279
|
+
# worth the cost.
|
280
|
+
#
|
281
|
+
# Naming metadata fields bad things like `class` causes `initialize_from`
|
282
|
+
# to produce strange results, so we ban known offenders here.
|
283
|
+
#
|
284
|
+
# In a future major version we should consider leaving `metadata` as a hash
|
285
|
+
# and forcing people to access it with `obj.metadata[:my_field]` because
|
286
|
+
# the potential for trouble is just too high. For now, reserve names.
|
287
|
+
RESERVED_FIELD_NAMES = [
|
288
|
+
:class,
|
289
|
+
].freeze
|
290
|
+
|
270
291
|
protected def metaclass
|
271
292
|
class << self; self; end
|
272
293
|
end
|
@@ -277,6 +298,7 @@ module Stripe
|
|
277
298
|
|
278
299
|
metaclass.instance_eval do
|
279
300
|
keys.each do |k|
|
301
|
+
next if RESERVED_FIELD_NAMES.include?(k)
|
280
302
|
next if protected_fields.include?(k)
|
281
303
|
next if @@permanent_attributes.include?(k)
|
282
304
|
|
@@ -312,6 +334,7 @@ module Stripe
|
|
312
334
|
|
313
335
|
metaclass.instance_eval do
|
314
336
|
keys.each do |k|
|
337
|
+
next if RESERVED_FIELD_NAMES.include?(k)
|
315
338
|
next if protected_fields.include?(k)
|
316
339
|
next if @@permanent_attributes.include?(k)
|
317
340
|
|
@@ -406,13 +429,13 @@ module Stripe
|
|
406
429
|
# * +:opts:+ Options for StripeObject like an API key.
|
407
430
|
# * +:partial:+ Indicates that the re-initialization should not attempt to
|
408
431
|
# remove accessors.
|
409
|
-
protected def initialize_from(values, opts
|
432
|
+
protected def initialize_from(values, opts)
|
410
433
|
@opts = Util.normalize_opts(opts)
|
411
434
|
|
412
435
|
# the `#send` is here so that we can keep this method private
|
413
436
|
@original_values = self.class.send(:deep_copy, values)
|
414
437
|
|
415
|
-
removed =
|
438
|
+
removed = Set.new(@values.keys - values.keys)
|
416
439
|
added = Set.new(values.keys - @values.keys)
|
417
440
|
|
418
441
|
# Wipe old state before setting new. This is useful for e.g. updating a
|
@@ -1,63 +1,54 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Stripe
|
4
|
-
#
|
5
|
-
# the
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def self.from_net_http(resp)
|
14
|
-
new(resp.to_hash)
|
15
|
-
end
|
4
|
+
# Headers provides an access wrapper to an API response's header data. It
|
5
|
+
# mainly exists so that we don't need to expose the entire
|
6
|
+
# `Net::HTTPResponse` object while still getting some of its benefits like
|
7
|
+
# case-insensitive access to header names and flattening of header values.
|
8
|
+
class StripeResponseHeaders
|
9
|
+
# Initializes a Headers object from a Net::HTTP::HTTPResponse object.
|
10
|
+
def self.from_net_http(resp)
|
11
|
+
new(resp.to_hash)
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
14
|
+
# `hash` is expected to be a hash mapping header names to arrays of
|
15
|
+
# header values. This is the default format generated by calling
|
16
|
+
# `#to_hash` on a `Net::HTTPResponse` object because headers can be
|
17
|
+
# repeated multiple times. Using `#[]` will collapse values down to just
|
18
|
+
# the first.
|
19
|
+
def initialize(hash)
|
20
|
+
if !hash.is_a?(Hash) ||
|
21
|
+
!hash.keys.all? { |n| n.is_a?(String) } ||
|
22
|
+
!hash.values.all? { |a| a.is_a?(Array) } ||
|
23
|
+
!hash.values.all? { |a| a.all? { |v| v.is_a?(String) } }
|
24
|
+
raise ArgumentError,
|
25
|
+
"expect hash to be a map of string header names to arrays of " \
|
26
|
+
"header values"
|
27
|
+
end
|
31
28
|
|
32
|
-
|
29
|
+
@hash = {}
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
31
|
+
# This shouldn't be strictly necessary because `Net::HTTPResponse` will
|
32
|
+
# produce a hash with all headers downcased, but do it anyway just in
|
33
|
+
# case an object of this class was constructed manually.
|
34
|
+
#
|
35
|
+
# Also has the effect of duplicating the hash, which is desirable for a
|
36
|
+
# little extra object safety.
|
37
|
+
hash.each do |k, v|
|
38
|
+
@hash[k.downcase] = v
|
43
39
|
end
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
values ? values.first : nil
|
42
|
+
def [](name)
|
43
|
+
values = @hash[name.downcase]
|
44
|
+
if values && values.count > 1
|
45
|
+
warn("Duplicate header values for `#{name}`; returning only first")
|
51
46
|
end
|
47
|
+
values ? values.first : nil
|
52
48
|
end
|
49
|
+
end
|
53
50
|
|
54
|
-
|
55
|
-
# JSON.
|
56
|
-
attr_accessor :data
|
57
|
-
|
58
|
-
# The raw HTTP body of the response.
|
59
|
-
attr_accessor :http_body
|
60
|
-
|
51
|
+
module StripeResponseBase
|
61
52
|
# A Hash of the HTTP headers of the response.
|
62
53
|
attr_accessor :http_headers
|
63
54
|
|
@@ -67,15 +58,52 @@ module Stripe
|
|
67
58
|
# The Stripe request ID of the response.
|
68
59
|
attr_accessor :request_id
|
69
60
|
|
61
|
+
def self.populate_for_net_http(resp, http_resp)
|
62
|
+
resp.http_headers = StripeResponseHeaders.from_net_http(http_resp)
|
63
|
+
resp.http_status = http_resp.code.to_i
|
64
|
+
resp.request_id = http_resp["request-id"]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# StripeResponse encapsulates some vitals of a response that came back from
|
69
|
+
# the Stripe API.
|
70
|
+
class StripeResponse
|
71
|
+
include StripeResponseBase
|
72
|
+
# The data contained by the HTTP body of the response deserialized from
|
73
|
+
# JSON.
|
74
|
+
attr_accessor :data
|
75
|
+
|
76
|
+
# The raw HTTP body of the response.
|
77
|
+
attr_accessor :http_body
|
78
|
+
|
70
79
|
# Initializes a StripeResponse object from a Net::HTTP::HTTPResponse
|
71
80
|
# object.
|
72
81
|
def self.from_net_http(http_resp)
|
73
82
|
resp = StripeResponse.new
|
74
83
|
resp.data = JSON.parse(http_resp.body, symbolize_names: true)
|
75
84
|
resp.http_body = http_resp.body
|
76
|
-
resp
|
77
|
-
resp
|
78
|
-
|
85
|
+
StripeResponseBase.populate_for_net_http(resp, http_resp)
|
86
|
+
resp
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# We have to alias StripeResponseHeaders to StripeResponse::Headers, as this
|
91
|
+
# class used to be embedded within StripeResponse and we want to be backwards
|
92
|
+
# compatible.
|
93
|
+
StripeResponse::Headers = StripeResponseHeaders
|
94
|
+
|
95
|
+
# StripeHeadersOnlyResponse includes only header-related vitals of the
|
96
|
+
# response. This is used for streaming requests where the response was read
|
97
|
+
# directly in a block and we explicitly don't want to store the body of the
|
98
|
+
# response in memory.
|
99
|
+
class StripeHeadersOnlyResponse
|
100
|
+
include StripeResponseBase
|
101
|
+
|
102
|
+
# Initializes a StripeHeadersOnlyResponse object from a
|
103
|
+
# Net::HTTP::HTTPResponse object.
|
104
|
+
def self.from_net_http(http_resp)
|
105
|
+
resp = StripeHeadersOnlyResponse.new
|
106
|
+
StripeResponseBase.populate_for_net_http(resp, http_resp)
|
79
107
|
resp
|
80
108
|
end
|
81
109
|
end
|
data/lib/stripe/util.rb
CHANGED
@@ -47,6 +47,53 @@ module Stripe
|
|
47
47
|
Util.object_classes[object_name] == klass
|
48
48
|
end
|
49
49
|
|
50
|
+
# Adds a custom method to a resource class. This is used to add support for
|
51
|
+
# non-CRUDL API requests, e.g. capturing charges. custom_method takes the
|
52
|
+
# following parameters:
|
53
|
+
# - name: the name of the custom method to create (as a symbol)
|
54
|
+
# - http_verb: the HTTP verb for the API request (:get, :post, or :delete)
|
55
|
+
# - http_path: the path to append to the resource's URL. If not provided,
|
56
|
+
# the name is used as the path
|
57
|
+
# - resource: the resource implementation class
|
58
|
+
# - target: the class that custom static method will be added to
|
59
|
+
#
|
60
|
+
# For example, this call:
|
61
|
+
# custom_method :capture, http_verb: post
|
62
|
+
# adds a `capture` class method to the resource class that, when called,
|
63
|
+
# will send a POST request to `/v1/<object_name>/capture`.
|
64
|
+
def self.custom_method(resource, target, name, http_verb, http_path)
|
65
|
+
unless %i[get post delete].include?(http_verb)
|
66
|
+
raise ArgumentError,
|
67
|
+
"Invalid http_verb value: #{http_verb.inspect}. Should be one " \
|
68
|
+
"of :get, :post or :delete."
|
69
|
+
end
|
70
|
+
unless target.respond_to?(:resource_url)
|
71
|
+
raise ArgumentError,
|
72
|
+
"Invalid target value: #{target}. Target class should have a " \
|
73
|
+
"`resource_url` method."
|
74
|
+
end
|
75
|
+
http_path ||= name.to_s
|
76
|
+
target.define_singleton_method(name) do |id, params = {}, opts = {}|
|
77
|
+
unless id.is_a?(String)
|
78
|
+
raise ArgumentError,
|
79
|
+
"id should be a string representing the ID of an API resource"
|
80
|
+
end
|
81
|
+
|
82
|
+
url = "#{target.resource_url}/"\
|
83
|
+
"#{CGI.escape(id)}/"\
|
84
|
+
"#{CGI.escape(http_path)}"
|
85
|
+
|
86
|
+
resp, opts = resource.execute_resource_request(
|
87
|
+
http_verb,
|
88
|
+
url,
|
89
|
+
params,
|
90
|
+
opts
|
91
|
+
)
|
92
|
+
|
93
|
+
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
50
97
|
# Converts a hash of fields or an array of hashes into a +StripeObject+ or
|
51
98
|
# array of +StripeObject+s. These new objects will be created as a concrete
|
52
99
|
# type as dictated by their `object` field (e.g. an `object` value of
|
@@ -57,9 +104,27 @@ module Stripe
|
|
57
104
|
# ==== Attributes
|
58
105
|
#
|
59
106
|
# * +data+ - Hash of fields and values to be converted into a StripeObject.
|
107
|
+
# * +params+ - Params for +StripeObject+ like filters used in search that
|
108
|
+
# will be reused on subsequent API calls.
|
60
109
|
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
|
61
110
|
# on subsequent API calls.
|
62
111
|
def self.convert_to_stripe_object(data, opts = {})
|
112
|
+
convert_to_stripe_object_with_params(data, {}, opts)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Converts a hash of fields or an array of hashes into a +StripeObject+ or
|
116
|
+
# array of +StripeObject+s. These new objects will be created as a concrete
|
117
|
+
# type as dictated by their `object` field (e.g. an `object` value of
|
118
|
+
# `charge` would create an instance of +Charge+), but if `object` is not
|
119
|
+
# present or of an unknown type, the newly created instance will fall back
|
120
|
+
# to being a +StripeObject+.
|
121
|
+
#
|
122
|
+
# ==== Attributes
|
123
|
+
#
|
124
|
+
# * +data+ - Hash of fields and values to be converted into a StripeObject.
|
125
|
+
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
|
126
|
+
# on subsequent API calls.
|
127
|
+
def self.convert_to_stripe_object_with_params(data, params, opts = {})
|
63
128
|
opts = normalize_opts(opts)
|
64
129
|
|
65
130
|
case data
|
@@ -68,32 +133,47 @@ module Stripe
|
|
68
133
|
when Hash
|
69
134
|
# Try converting to a known object class. If none available, fall back
|
70
135
|
# to generic StripeObject
|
71
|
-
|
72
|
-
|
136
|
+
object_name = data[:object] || data["object"]
|
137
|
+
obj = object_classes.fetch(object_name, StripeObject)
|
138
|
+
.construct_from(data, opts)
|
139
|
+
|
140
|
+
# set filters so that we can fetch the same limit, expansions, and
|
141
|
+
# predicates when accessing the next and previous pages
|
142
|
+
if obj && (obj.is_a?(SearchResultObject) || obj.is_a?(ListObject))
|
143
|
+
obj.filters = params.dup
|
144
|
+
end
|
145
|
+
|
146
|
+
obj
|
73
147
|
else
|
74
148
|
data
|
75
149
|
end
|
76
150
|
end
|
77
151
|
|
78
152
|
def self.log_error(message, data = {})
|
79
|
-
|
80
|
-
|
153
|
+
config = data.delete(:config) || Stripe.config
|
154
|
+
logger = config.logger || Stripe.logger
|
155
|
+
if !logger.nil? ||
|
156
|
+
!config.log_level.nil? && config.log_level <= Stripe::LEVEL_ERROR
|
81
157
|
log_internal(message, data, color: :cyan, level: Stripe::LEVEL_ERROR,
|
82
158
|
logger: Stripe.logger, out: $stderr)
|
83
159
|
end
|
84
160
|
end
|
85
161
|
|
86
162
|
def self.log_info(message, data = {})
|
87
|
-
|
88
|
-
|
163
|
+
config = data.delete(:config) || Stripe.config
|
164
|
+
logger = config.logger || Stripe.logger
|
165
|
+
if !logger.nil? ||
|
166
|
+
!config.log_level.nil? && config.log_level <= Stripe::LEVEL_INFO
|
89
167
|
log_internal(message, data, color: :cyan, level: Stripe::LEVEL_INFO,
|
90
168
|
logger: Stripe.logger, out: $stdout)
|
91
169
|
end
|
92
170
|
end
|
93
171
|
|
94
172
|
def self.log_debug(message, data = {})
|
95
|
-
|
96
|
-
|
173
|
+
config = data.delete(:config) || Stripe.config
|
174
|
+
logger = config.logger || Stripe.logger
|
175
|
+
if !logger.nil? ||
|
176
|
+
!config.log_level.nil? && config.log_level <= Stripe::LEVEL_DEBUG
|
97
177
|
log_internal(message, data, color: :blue, level: Stripe::LEVEL_DEBUG,
|
98
178
|
logger: Stripe.logger, out: $stdout)
|
99
179
|
end
|
@@ -202,7 +282,9 @@ module Stripe
|
|
202
282
|
{ api_key: opts }
|
203
283
|
when Hash
|
204
284
|
check_api_key!(opts.fetch(:api_key)) if opts.key?(:api_key)
|
205
|
-
|
285
|
+
# Explicitly use dup here instead of clone to avoid preserving freeze
|
286
|
+
# state on input params.
|
287
|
+
opts.dup
|
206
288
|
else
|
207
289
|
raise TypeError, "normalize_opts expects a string or a hash"
|
208
290
|
end
|
@@ -335,6 +417,15 @@ module Stripe
|
|
335
417
|
# Hopefully val is a string, but protect in case it's not.
|
336
418
|
val = val.to_s
|
337
419
|
|
420
|
+
# Some values returned by the server are encoded in ASCII-8BIT before
|
421
|
+
# being parsed as UTF-8 by Marshal. If we don't transform these here, then
|
422
|
+
# puts will fail as it tries to render UTF-8 characters as ASCII-8BIT
|
423
|
+
# which is not valid.
|
424
|
+
if val && val.encoding == Encoding::ASCII_8BIT
|
425
|
+
# Dup the string as it is a frozen literal.
|
426
|
+
val = val.dup.force_encoding("UTF-8")
|
427
|
+
end
|
428
|
+
|
338
429
|
if %r{[^\w\-/]} =~ val
|
339
430
|
# If the string contains any special characters, escape any double
|
340
431
|
# quotes it has, remove newlines, and wrap the whole thing in quotes.
|
data/lib/stripe/version.rb
CHANGED
data/lib/stripe.rb
CHANGED
@@ -24,6 +24,7 @@ require "stripe/api_operations/list"
|
|
24
24
|
require "stripe/api_operations/nested_resource"
|
25
25
|
require "stripe/api_operations/request"
|
26
26
|
require "stripe/api_operations/save"
|
27
|
+
require "stripe/api_operations/search"
|
27
28
|
|
28
29
|
# API resource support classes
|
29
30
|
require "stripe/errors"
|
@@ -35,8 +36,10 @@ require "stripe/stripe_client"
|
|
35
36
|
require "stripe/stripe_object"
|
36
37
|
require "stripe/stripe_response"
|
37
38
|
require "stripe/list_object"
|
39
|
+
require "stripe/search_result_object"
|
38
40
|
require "stripe/error_object"
|
39
41
|
require "stripe/api_resource"
|
42
|
+
require "stripe/api_resource_test_helpers"
|
40
43
|
require "stripe/singleton_api_resource"
|
41
44
|
require "stripe/webhook"
|
42
45
|
require "stripe/stripe_configuration"
|
@@ -57,35 +60,36 @@ module Stripe
|
|
57
60
|
|
58
61
|
@app_info = nil
|
59
62
|
|
60
|
-
@
|
63
|
+
@config = Stripe::StripeConfiguration.setup
|
61
64
|
|
62
65
|
class << self
|
63
66
|
extend Forwardable
|
64
67
|
|
68
|
+
attr_reader :config
|
69
|
+
|
65
70
|
# User configurable options
|
66
|
-
def_delegators :@
|
67
|
-
def_delegators :@
|
68
|
-
def_delegators :@
|
69
|
-
def_delegators :@
|
70
|
-
def_delegators :@
|
71
|
-
def_delegators :@
|
72
|
-
def_delegators :@
|
73
|
-
def_delegators :@
|
74
|
-
def_delegators :@
|
75
|
-
def_delegators :@
|
76
|
-
def_delegators :@
|
77
|
-
def_delegators :@
|
78
|
-
def_delegators :@
|
79
|
-
def_delegators :@
|
80
|
-
def_delegators :@
|
81
|
-
def_delegators :@
|
71
|
+
def_delegators :@config, :api_key, :api_key=
|
72
|
+
def_delegators :@config, :api_version, :api_version=
|
73
|
+
def_delegators :@config, :stripe_account, :stripe_account=
|
74
|
+
def_delegators :@config, :api_base, :api_base=
|
75
|
+
def_delegators :@config, :uploads_base, :uploads_base=
|
76
|
+
def_delegators :@config, :connect_base, :connect_base=
|
77
|
+
def_delegators :@config, :open_timeout, :open_timeout=
|
78
|
+
def_delegators :@config, :read_timeout, :read_timeout=
|
79
|
+
def_delegators :@config, :write_timeout, :write_timeout=
|
80
|
+
def_delegators :@config, :proxy, :proxy=
|
81
|
+
def_delegators :@config, :verify_ssl_certs, :verify_ssl_certs=
|
82
|
+
def_delegators :@config, :ca_bundle_path, :ca_bundle_path=
|
83
|
+
def_delegators :@config, :log_level, :log_level=
|
84
|
+
def_delegators :@config, :logger, :logger=
|
85
|
+
def_delegators :@config, :max_network_retries, :max_network_retries=
|
86
|
+
def_delegators :@config, :enable_telemetry=, :enable_telemetry?
|
87
|
+
def_delegators :@config, :client_id=, :client_id
|
82
88
|
|
83
89
|
# Internal configurations
|
84
|
-
def_delegators :@
|
85
|
-
def_delegators :@
|
86
|
-
def_delegators :@
|
87
|
-
|
88
|
-
attr_accessor :client_id
|
90
|
+
def_delegators :@config, :max_network_retry_delay
|
91
|
+
def_delegators :@config, :initial_network_retry_delay
|
92
|
+
def_delegators :@config, :ca_store
|
89
93
|
end
|
90
94
|
|
91
95
|
# Gets the application for a plugin that's identified some. See
|
@@ -102,7 +106,7 @@ module Stripe
|
|
102
106
|
# with API requests. Useful for plugin authors to identify their plugin when
|
103
107
|
# communicating with Stripe.
|
104
108
|
#
|
105
|
-
# Takes a name and optional
|
109
|
+
# Takes a name and optional partner program ID, plugin URL, and version.
|
106
110
|
def self.set_app_info(name, partner_id: nil, url: nil, version: nil)
|
107
111
|
@app_info = {
|
108
112
|
name: name,
|
data/stripe.gemspec
CHANGED
@@ -13,21 +13,28 @@ Gem::Specification.new do |s|
|
|
13
13
|
"See https://stripe.com for details."
|
14
14
|
s.author = "Stripe"
|
15
15
|
s.email = "support@stripe.com"
|
16
|
-
s.homepage = "https://stripe.com/docs/api
|
16
|
+
s.homepage = "https://stripe.com/docs/api?lang=ruby"
|
17
17
|
s.license = "MIT"
|
18
18
|
|
19
19
|
s.metadata = {
|
20
20
|
"bug_tracker_uri" => "https://github.com/stripe/stripe-ruby/issues",
|
21
21
|
"changelog_uri" =>
|
22
22
|
"https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md",
|
23
|
-
"documentation_uri" => "https://stripe.com/docs/api
|
23
|
+
"documentation_uri" => "https://stripe.com/docs/api?lang=ruby",
|
24
24
|
"github_repo" => "ssh://github.com/stripe/stripe-ruby",
|
25
|
-
"homepage_uri" => "https://stripe.com/docs/api
|
25
|
+
"homepage_uri" => "https://stripe.com/docs/api?lang=ruby",
|
26
26
|
"source_code_uri" => "https://github.com/stripe/stripe-ruby",
|
27
27
|
}
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
ignored = Regexp.union(
|
30
|
+
/\A\.editorconfig/,
|
31
|
+
/\A\.git/,
|
32
|
+
/\A\.rubocop/,
|
33
|
+
/\A\.travis.yml/,
|
34
|
+
/\A\.vscode/,
|
35
|
+
/\Atest/
|
36
|
+
)
|
37
|
+
s.files = `git ls-files`.split("\n").reject { |f| ignored.match(f) }
|
31
38
|
s.executables = `git ls-files -- bin/*`.split("\n")
|
32
39
|
.map { |f| ::File.basename(f) }
|
33
40
|
s.require_paths = ["lib"]
|