stripe 14.0.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5525691fb4bdeceebc4d8a3ff05952e3b0f2f90f77ffedf9f3b982a6e15cc49
4
- data.tar.gz: 8d2250d5b1941abbf886cbd160ee80bf16fbe1d66412665a9e6121e9b88d4928
3
+ metadata.gz: 9ac9a4371f393b1650cd2b5198d4e2ceed046c9676183b0d339fd985c4b8b815
4
+ data.tar.gz: 3fc59d72c6450657a7797088c39f5c85d9b8bba505992cfc3fdbdc7a8d27fb7d
5
5
  SHA512:
6
- metadata.gz: 3e347248e1f10850cc635b84053a05098ba18366b9614a2d8390905552da62fcdb0eaa17d917b2dc3718f54448c1e34f418258b8d1bc71adc8e0d22c39e91601
7
- data.tar.gz: 3f83f0d0ab7b51b0fb908611293879549c324aeac451661df9182c9771dcd3e2322a083e733fcb0741a2e80576220fa50a7cde87855fd9f7405d9063c24ddef7
6
+ metadata.gz: 4f156649ca332eff3a2837ec1f038ebcc8ab9f5c35194d031e2610b45ef6b74cb0b651b3402d0afa98375a7ac293f0e54761e191dd6237e58e372b42b2cba681
7
+ data.tar.gz: 1cb72620268bf94d44b0ddd6090b41404efc0b25606759907c2a3d6821577b45b488738bdfdac34b6ba3a6e9fb769d9646ad1b184580d84fac3df6451a0fd172
data/CHANGELOG.md CHANGED
@@ -1,4 +1,24 @@
1
1
  # Changelog
2
+ ## 15.0.0 - 2025-04-09
3
+
4
+ ### Breaking change
5
+ * [#1574](https://github.com/stripe/stripe-ruby/pull/1574) Rename `object_id` in V2::Core::EventService::ListParams to `object_id_`
6
+ * ⚠️ Change name of parameter from `object_id` to `object_id_` on `Stripe::V2::Core::EventService::ListParams` to avoid conflict with Ruby native attribute, as found in https://github.com/stripe/stripe-ruby/issues/1567
7
+ * This is a no-op unless you are using this specific parameter that was introduced in `v14.0.0`
8
+
9
+ * [#1576](https://github.com/stripe/stripe-ruby/pull/1576) Explicitly pass through custom headers in retrieve
10
+ * Fix custom options passing for resource-based retrieve
11
+ * [#1571](https://github.com/stripe/stripe-ruby/pull/1571) Validate all instance variable keys returned from the API
12
+ * Validate all keys returned from the API, including custom response fields, to make sure they can be set in an instance variable, as brought up in https://github.com/stripe/stripe-ruby/issues/1564
13
+ * We do not set instance variables for invalid field names (as defined by the [Ruby spec](https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#ident)). We recommend for custom hash map response fields, use the `[]` accessor.
14
+ ```ruby
15
+ c = client.v1.customers.retrieve("cus_123")
16
+ c.metadata["invalid-variable-name!"]
17
+ c.metadata["valid_key_name_works_too"]
18
+ ```
19
+ * [#1575](https://github.com/stripe/stripe-ruby/pull/1575) Remove unused youtube playlist link
20
+ * [#1573](https://github.com/stripe/stripe-ruby/pull/1573) Remove link for stale youtube video playlist
21
+
2
22
  ## 14.0.0 - 2025-04-01
3
23
  * [#1559](https://github.com/stripe/stripe-ruby/pull/1559) Add RBI annotations for fields and params
4
24
  * Adds explicit field types for resources and parameters for methods, and add RBI static annotations for all resources and services
data/README.md CHANGED
@@ -20,8 +20,6 @@ The library also provides other features. For example:
20
20
 
21
21
  See the [Ruby API docs](https://stripe.com/docs/api?lang=ruby).
22
22
 
23
- See [video demonstrations][youtube-playlist] covering how to use the library.
24
-
25
23
  ## Installation
26
24
 
27
25
  You don't need this source code unless you want to modify the gem. If you just
@@ -158,6 +156,9 @@ print(customer.last_response.http_status) # to retrieve status code
158
156
  print(customer.last_response.http_headers) # to retrieve headers
159
157
  ```
160
158
 
159
+ If you are accessing a response field with custom hashes provided by you, such as `Customer.metadata`,
160
+ please access your fields with the `[]` accessor.
161
+
161
162
  ### Configuring a proxy
162
163
 
163
164
  A proxy can be configured with `Stripe.proxy`:
@@ -444,7 +445,6 @@ Update the bundled [stripe-mock] by editing the version number found in
444
445
  [idempotency-keys]: https://stripe.com/docs/api/idempotent_requests?lang=ruby
445
446
  [stripe-mock]: https://github.com/stripe/stripe-mock
446
447
  [versioning]: https://stripe.com/docs/api/versioning?lang=ruby
447
- [youtube-playlist]: https://www.youtube.com/playlist?list=PLy1nL-pvL2M50RmP6ie-gdcSnfOuQCRYk
448
448
 
449
449
  <!--
450
450
  # vim: set tw=79:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 14.0.0
1
+ 15.0.0
@@ -67,7 +67,8 @@ module Stripe
67
67
  values.delete(:id)
68
68
  opts = Util.normalize_opts(opts)
69
69
  APIRequestor.active_requestor.execute_request_initialize_from(:post, save_url, :api, self,
70
- params: values, opts: opts,
70
+ params: values,
71
+ opts: RequestOptions.extract_opts_from_hash(opts),
71
72
  usage: ["save"])
72
73
  end
73
74
  extend Gem::Deprecate
@@ -64,7 +64,8 @@ module Stripe
64
64
  opts = Util.normalize_opts(opts)
65
65
 
66
66
  APIRequestor.active_requestor.execute_request_initialize_from(:post, resource_url, :api, self,
67
- params: values, opts: opts,
67
+ params: values,
68
+ opts: RequestOptions.extract_opts_from_hash(opts),
68
69
  usage: ["save"])
69
70
  end
70
71
  extend Gem::Deprecate
@@ -220,9 +220,11 @@ module Stripe
220
220
  # with future non-major changes.
221
221
  def execute_request_initialize_from(method, path, base_address, object,
222
222
  params: {}, opts: {}, usage: [])
223
- opts = RequestOptions.combine_opts(object.instance_variable_get(:@opts), opts)
223
+ opts = RequestOptions.combine_opts(object.instance_variable_get(:@opts) || {}, opts)
224
224
  opts = Util.normalize_opts(opts)
225
+
225
226
  params = params.to_h if params.is_a?(RequestParams)
227
+
226
228
  http_resp, req_opts = execute_request_internal(
227
229
  method, path, base_address, params, opts, usage
228
230
  )
@@ -98,7 +98,10 @@ module Stripe
98
98
  "It is not possible to refresh v2 objects. Please retrieve the object using the StripeClient instead."
99
99
  end
100
100
 
101
- @obj = @requestor.execute_request_initialize_from(:get, resource_url, :api, self, params: @retrieve_params)
101
+ opts = RequestOptions.extract_opts_from_hash(@retrieve_opts || {})
102
+ @retrieve_opts = {} # Make sure to clear the retrieve options
103
+ @obj = @requestor.execute_request_initialize_from(:get, resource_url, :api, self, params: @retrieve_params,
104
+ opts: opts)
102
105
  initialize_from(
103
106
  @obj.last_response.data,
104
107
  @obj.instance_variable_get(:@opts),
@@ -114,8 +117,12 @@ module Stripe
114
117
  "It is not possible to retrieve v2 objects on the resource. Please use the StripeClient instead."
115
118
  end
116
119
 
117
- opts = Util.normalize_opts(opts)
118
- instance = new(id, opts)
120
+ instance = new(id)
121
+ # Explicitly send options for the retrieve call, to preserve custom headers
122
+ # This is so we can pass custom headers from this static function
123
+ # to the instance variable method call
124
+ # The custom headers will be cleaned up with the rest of the RequestOptions
125
+ instance.instance_variable_set(:@retrieve_opts, Util.normalize_opts(opts))
119
126
  instance.refresh
120
127
  end
121
128
 
@@ -56,7 +56,7 @@ module Stripe
56
56
  # Merges requestor options hash on a StripeObject
57
57
  # with a per-request options hash, giving precedence
58
58
  # to the per-request options. Returns the merged request options.
59
- # Expects two hashes.
59
+ # Expects two hashes, expects extract_opts_from_hash to be called first!!!
60
60
  def self.combine_opts(object_opts, req_opts)
61
61
  merged_opts = {
62
62
  api_key: req_opts[:api_key] || object_opts[:api_key],
@@ -64,6 +64,7 @@ module Stripe
64
64
  stripe_account: req_opts[:stripe_account] || object_opts[:stripe_account],
65
65
  stripe_context: req_opts[:stripe_context] || object_opts[:stripe_context],
66
66
  stripe_version: req_opts[:stripe_version] || object_opts[:stripe_version],
67
+ headers: req_opts[:headers] || {},
67
68
  }
68
69
 
69
70
  # Remove nil values from headers
@@ -1270,7 +1270,7 @@ module Stripe
1270
1270
  "/#{CGI.escape(id)}"
1271
1271
  opts = Util.normalize_opts(opts)
1272
1272
  APIRequestor.active_requestor.execute_request_initialize_from(:delete, url, :api, self,
1273
- params: params, opts: opts)
1273
+ params: params, opts: RequestOptions.extract_opts_from_hash(opts))
1274
1274
  end
1275
1275
 
1276
1276
  def source_transactions(params = {}, opts = {})
@@ -9,11 +9,13 @@ module Stripe
9
9
  # The page size.
10
10
  attr_accessor :limit
11
11
  # Primary object ID used to retrieve related events.
12
- attr_accessor :object_id
12
+ #
13
+ # To avoid conflict with Ruby's ':object_id', this attribute has been renamed. If using a hash parameter map instead, please use the original name ':object_id' with NO trailing underscore as the provided param key.
14
+ attr_accessor :object_id_
13
15
 
14
- def initialize(limit: nil, object_id: nil)
16
+ def initialize(limit: nil, object_id_: nil)
15
17
  @limit = limit
16
- @object_id = object_id
18
+ @object_id_ = object_id_
17
19
  end
18
20
  end
19
21
 
@@ -336,7 +336,7 @@ module Stripe
336
336
  end
337
337
  end
338
338
 
339
- protected def add_accessors(keys, values)
339
+ protected def add_accessors(keys, values) # rubocop:todo Metrics/PerceivedComplexity
340
340
  # not available in the #instance_eval below
341
341
  protected_fields = self.class.protected_fields
342
342
 
@@ -372,7 +372,16 @@ module Stripe
372
372
  end
373
373
 
374
374
  keys.each do |k|
375
- instance_variable_set(:"@#{k}", values[k])
375
+ if Util.valid_variable_name?(k)
376
+ instance_variable_set(:"@#{k}", values[k])
377
+ else
378
+ Util.log_info(<<~LOG
379
+ The variable name '#{k}' is not a valid Ruby variable name.
380
+ Use ["#{k}"] to access this field, skipping instance variable instantiation...
381
+ LOG
382
+ )
383
+
384
+ end
376
385
  end
377
386
  end
378
387
 
@@ -473,13 +482,14 @@ module Stripe
473
482
 
474
483
  # Should only be for v2 events and lists, for now.
475
484
  protected def _request(method:, path:, base_address:, params: {}, opts: {})
476
- req_opts = RequestOptions.combine_opts(@opts, opts)
485
+ req_opts = RequestOptions.extract_opts_from_hash(opts)
486
+ req_opts = RequestOptions.combine_opts(@opts, req_opts)
477
487
  @requestor.execute_request(
478
488
  method,
479
489
  path,
480
490
  base_address,
481
491
  params: params,
482
- opts: RequestOptions.extract_opts_from_hash(req_opts)
492
+ opts: req_opts
483
493
  )
484
494
  end
485
495
 
data/lib/stripe/util.rb CHANGED
@@ -4,6 +4,9 @@ require "cgi"
4
4
 
5
5
  module Stripe
6
6
  module Util
7
+ LEGAL_FIRST_CHARACTER = /[a-zA-Z_]/.freeze
8
+ LEGAL_VARIABLE_CHARACTER = /[a-zA-Z0-9_]/.freeze
9
+
7
10
  def self.objects_to_ids(obj)
8
11
  case obj
9
12
  when APIResource
@@ -309,6 +312,14 @@ module Stripe
309
312
  end
310
313
  end
311
314
 
315
+ # Return false for strings that are invalid variable names
316
+ # Does NOT expect there to be a preceding '@' for instance variables
317
+ def self.valid_variable_name?(key)
318
+ return false if key.empty? || key[0] !~ LEGAL_FIRST_CHARACTER
319
+
320
+ key[1..-1].chars.all? { |char| char =~ LEGAL_VARIABLE_CHARACTER }
321
+ end
322
+
312
323
  def self.check_string_argument!(key)
313
324
  raise TypeError, "argument must be a string" unless key.is_a?(String)
314
325
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "14.0.0"
4
+ VERSION = "15.0.0"
5
5
  end
@@ -11,10 +11,12 @@ module Stripe
11
11
  sig { returns(T.nilable(Integer)) }
12
12
  attr_accessor :limit
13
13
  # Primary object ID used to retrieve related events.
14
+ #
15
+ # To avoid conflict with Ruby's ':object_id', this attribute has been renamed. If using a hash parameter map instead, please use the original name ':object_id' with NO trailing underscore as the provided param key.
14
16
  sig { returns(String) }
15
- attr_accessor :object_id
16
- sig { params(limit: T.nilable(Integer), object_id: String).void }
17
- def initialize(limit: nil, object_id: nil); end
17
+ attr_accessor :object_id_
18
+ sig { params(limit: T.nilable(Integer), object_id_: String).void }
19
+ def initialize(limit: nil, object_id_: nil); end
18
20
  end
19
21
  class RetrieveParams < Stripe::RequestParams
20
22
 
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: 14.0.0
4
+ version: 15.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-01 00:00:00.000000000 Z
11
+ date: 2025-04-09 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.