Skip to content

Commit 12f1981

Browse files
Merge upstream and update generated code for v2184 and
2 parents 149bbe0 + 611ecf0 commit 12f1981

File tree

9 files changed

+145
-12
lines changed

9 files changed

+145
-12
lines changed

CODEGEN_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9d9eb64ed1c8a7adcdcc153fc393b864deedc180
1+
f613ed838a6f816643faf0cc3e44100d558176cf

OPENAPI_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2182
1+
v2184

lib/stripe/params/subscription_create_params.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,12 @@ class TrialSettings < ::Stripe::RequestParams
920920
class EndBehavior < ::Stripe::RequestParams
921921
# Indicates how the subscription should change when the trial ends if the user did not provide a payment method.
922922
attr_accessor :missing_payment_method
923+
# Indicates how the subscription's billing cycle anchor is reset when a trial ends. Defaults to `now`.
924+
attr_accessor :billing_cycle_anchor
923925

924-
def initialize(missing_payment_method: nil)
926+
def initialize(missing_payment_method: nil, billing_cycle_anchor: nil)
925927
@missing_payment_method = missing_payment_method
928+
@billing_cycle_anchor = billing_cycle_anchor
926929
end
927930
end
928931
# Defines how the subscription should behave when the user's free trial ends.

lib/stripe/params/subscription_update_params.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,12 @@ class TrialSettings < ::Stripe::RequestParams
899899
class EndBehavior < ::Stripe::RequestParams
900900
# Indicates how the subscription should change when the trial ends if the user did not provide a payment method.
901901
attr_accessor :missing_payment_method
902+
# Indicates how the subscription's billing cycle anchor is reset when a trial ends. Defaults to `now`.
903+
attr_accessor :billing_cycle_anchor
902904

903-
def initialize(missing_payment_method: nil)
905+
def initialize(missing_payment_method: nil, billing_cycle_anchor: nil)
904906
@missing_payment_method = missing_payment_method
907+
@billing_cycle_anchor = billing_cycle_anchor
905908
end
906909
end
907910
# Defines how the subscription should behave when the user's free trial ends.

lib/stripe/request_params.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,46 @@ module Stripe
55
# For internal use only. Does not provide a stable API and may be broken
66
# with future non-major changes.
77
class RequestParams
8+
class << self
9+
# Override the object instantiation flow in Ruby in order to track explicitly set keys
10+
# V2 APIs accept null values on the backend. However, we do not want to set a key to nil
11+
# if the user has not explicitly set them to nil
12+
# TODO(major): https://go/j/DEVSDK-2990
13+
def new(**kwargs)
14+
instance = allocate
15+
# Track explicitly set keys for V2 classes only
16+
instance.instance_variable_set(:@_explicitly_set_keys, kwargs.keys.to_set) if name&.start_with?("Stripe::V2::")
17+
instance.send(:initialize, **kwargs)
18+
instance
19+
end
20+
21+
# Override attr_accessor to create setters that track explicitly set keys for V2 classes
22+
def attr_accessor(*names)
23+
names.each do |name|
24+
# Define getter
25+
define_method(name) { instance_variable_get("@#{name}") }
26+
27+
# Define setter that tracks the key as explicitly set
28+
define_method("#{name}=") do |value|
29+
@_explicitly_set_keys&.add(name)
30+
instance_variable_set("@#{name}", value)
31+
end
32+
end
33+
end
34+
end
35+
836
def to_h
937
instance_variables.each_with_object({}) do |var, hash|
38+
# _explicitly_set_keys is set as an instance variable.
39+
# Ignore the var if it is _explicitly_set_keys itself.
40+
next if var == :@_explicitly_set_keys
41+
1042
key = var.to_s.delete("@").to_sym
1143
value = instance_variable_get(var)
1244

45+
# For V2 classes, only include keys that were explicitly set
46+
next if @_explicitly_set_keys && !@_explicitly_set_keys.include?(key)
47+
1348
hash[key] = if value.is_a?(RequestParams)
1449
value.to_h
1550
# Check if value is an array and contains RequestParams objects

rbi/stripe.rbi

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199053,8 +199053,13 @@ module Stripe
199053199053
def missing_payment_method; end
199054199054
sig { params(_missing_payment_method: String).returns(String) }
199055199055
def missing_payment_method=(_missing_payment_method); end
199056-
sig { params(missing_payment_method: String).void }
199057-
def initialize(missing_payment_method: nil); end
199056+
# Indicates how the subscription's billing cycle anchor is reset when a trial ends. Defaults to `now`.
199057+
sig { returns(T.nilable(String)) }
199058+
def billing_cycle_anchor; end
199059+
sig { params(_billing_cycle_anchor: T.nilable(String)).returns(T.nilable(String)) }
199060+
def billing_cycle_anchor=(_billing_cycle_anchor); end
199061+
sig { params(missing_payment_method: String, billing_cycle_anchor: T.nilable(String)).void }
199062+
def initialize(missing_payment_method: nil, billing_cycle_anchor: nil); end
199058199063
end
199059199064
# Defines how the subscription should behave when the user's free trial ends.
199060199065
sig { returns(::Stripe::SubscriptionUpdateParams::TrialSettings::EndBehavior) }
@@ -200981,8 +200986,13 @@ module Stripe
200981200986
def missing_payment_method; end
200982200987
sig { params(_missing_payment_method: String).returns(String) }
200983200988
def missing_payment_method=(_missing_payment_method); end
200984-
sig { params(missing_payment_method: String).void }
200985-
def initialize(missing_payment_method: nil); end
200989+
# Indicates how the subscription's billing cycle anchor is reset when a trial ends. Defaults to `now`.
200990+
sig { returns(T.nilable(String)) }
200991+
def billing_cycle_anchor; end
200992+
sig { params(_billing_cycle_anchor: T.nilable(String)).returns(T.nilable(String)) }
200993+
def billing_cycle_anchor=(_billing_cycle_anchor); end
200994+
sig { params(missing_payment_method: String, billing_cycle_anchor: T.nilable(String)).void }
200995+
def initialize(missing_payment_method: nil, billing_cycle_anchor: nil); end
200986200996
end
200987200997
# Defines how the subscription should behave when the user's free trial ends.
200988200998
sig { returns(::Stripe::SubscriptionCreateParams::TrialSettings::EndBehavior) }

rbi/stripe/params/subscription_create_params.rbi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,13 @@ module Stripe
14481448
def missing_payment_method; end
14491449
sig { params(_missing_payment_method: String).returns(String) }
14501450
def missing_payment_method=(_missing_payment_method); end
1451-
sig { params(missing_payment_method: String).void }
1452-
def initialize(missing_payment_method: nil); end
1451+
# Indicates how the subscription's billing cycle anchor is reset when a trial ends. Defaults to `now`.
1452+
sig { returns(T.nilable(String)) }
1453+
def billing_cycle_anchor; end
1454+
sig { params(_billing_cycle_anchor: T.nilable(String)).returns(T.nilable(String)) }
1455+
def billing_cycle_anchor=(_billing_cycle_anchor); end
1456+
sig { params(missing_payment_method: String, billing_cycle_anchor: T.nilable(String)).void }
1457+
def initialize(missing_payment_method: nil, billing_cycle_anchor: nil); end
14531458
end
14541459
# Defines how the subscription should behave when the user's free trial ends.
14551460
sig { returns(::Stripe::SubscriptionCreateParams::TrialSettings::EndBehavior) }

rbi/stripe/params/subscription_update_params.rbi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,13 @@ module Stripe
14141414
def missing_payment_method; end
14151415
sig { params(_missing_payment_method: String).returns(String) }
14161416
def missing_payment_method=(_missing_payment_method); end
1417-
sig { params(missing_payment_method: String).void }
1418-
def initialize(missing_payment_method: nil); end
1417+
# Indicates how the subscription's billing cycle anchor is reset when a trial ends. Defaults to `now`.
1418+
sig { returns(T.nilable(String)) }
1419+
def billing_cycle_anchor; end
1420+
sig { params(_billing_cycle_anchor: T.nilable(String)).returns(T.nilable(String)) }
1421+
def billing_cycle_anchor=(_billing_cycle_anchor); end
1422+
sig { params(missing_payment_method: String, billing_cycle_anchor: T.nilable(String)).void }
1423+
def initialize(missing_payment_method: nil, billing_cycle_anchor: nil); end
14191424
end
14201425
# Defines how the subscription should behave when the user's free trial ends.
14211426
sig { returns(::Stripe::SubscriptionUpdateParams::TrialSettings::EndBehavior) }

test/stripe/request_params_test.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,77 @@ def initialize(games: nil)
269269
assert_equal expected, params.to_h
270270
end
271271
end
272+
273+
context "V2 RequestParams explicit key tracking" do
274+
should "only serialize explicitly set fields for V2 classes" do
275+
params = Stripe::V2::Billing::MeterEventCreateParams.new(
276+
event_name: "my_event",
277+
payload: { stripe_customer_id: "cus_123", value: "25" }
278+
)
279+
280+
result = params.to_h
281+
282+
assert_equal "my_event", result[:event_name]
283+
assert_equal({ stripe_customer_id: "cus_123", value: "25" }, result[:payload])
284+
refute result.key?(:identifier), "identifier was not set and should not be in the hash"
285+
refute result.key?(:timestamp), "timestamp was not set and should not be in the hash"
286+
end
287+
288+
should "serialize fields explicitly set to nil for V2 classes" do
289+
params = Stripe::V2::Billing::MeterEventCreateParams.new(
290+
event_name: "my_event",
291+
identifier: nil,
292+
payload: { stripe_customer_id: "cus_123", value: "25" }
293+
)
294+
295+
result = params.to_h
296+
297+
assert_equal "my_event", result[:event_name]
298+
assert result.key?(:identifier), "identifier was explicitly set to nil and should be in the hash"
299+
assert_nil result[:identifier]
300+
assert_equal({ stripe_customer_id: "cus_123", value: "25" }, result[:payload])
301+
refute result.key?(:timestamp), "timestamp was not set and should not be in the hash"
302+
end
303+
304+
should "serialize fields explicitly set after initialization for V2 classes" do
305+
params = Stripe::V2::Billing::MeterEventCreateParams.new(
306+
event_name: "my_event",
307+
payload: { stripe_customer_id: "cus_123", value: "25" }
308+
)
309+
310+
params.identifier = "Something"
311+
params.timestamp = nil
312+
313+
result = params.to_h
314+
315+
assert_equal "my_event", result[:event_name]
316+
assert_equal "Something", result[:identifier]
317+
assert_equal({ stripe_customer_id: "cus_123", value: "25" }, result[:payload])
318+
assert result.key?(:timestamp)
319+
assert_nil result[:timestamp]
320+
end
321+
322+
should "serialize all fields even if some fields are set after initialization for V1 classes" do
323+
params = FooCreateParams.new
324+
325+
params.fun = "games"
326+
327+
result = params.to_h
328+
329+
assert_equal "games", result[:fun]
330+
assert result.key?(:team), "V1 classes should include all fields even if not explicitly set"
331+
assert_nil result[:team]
332+
end
333+
334+
should "serialize all fields including nil defaults for V1 classes" do
335+
params = FooCreateParams.new(fun: "games")
336+
337+
result = params.to_h
338+
339+
assert_equal "games", result[:fun]
340+
assert result.key?(:team), "V1 classes should include all fields even if not explicitly set"
341+
assert_nil result[:team]
342+
end
343+
end
272344
end
273345
end

0 commit comments

Comments
 (0)