Merge upstream and update generated code for v2026 and 2025-09-30.preview

This commit is contained in:
Stripe OpenAPI 2025-09-29 14:22:34 +00:00
commit 02f2940ca1
14 changed files with 143 additions and 131 deletions

View File

@ -52,7 +52,7 @@ require "stripe/api_resource_test_helpers"
require "stripe/singleton_api_resource"
require "stripe/webhook"
require "stripe/stripe_configuration"
require "stripe/event_notification"
require "stripe/resources/v2/core/event_notification"
# Named API resources
require "stripe/resources"

View File

@ -1,72 +0,0 @@
# frozen_string_literal: true
module Stripe
module V2
class EventReasonRequest
attr_reader :id, :idempotency_key
def initialize(event_reason_request_payload = {})
@id = event_reason_request_payload[:id]
@idempotency_key = event_reason_request_payload[:idempotency_key]
end
end
class EventReason
attr_reader :type, :request
def initialize(event_reason_payload = {})
@type = event_reason_payload[:type]
@request = EventReasonRequest.new(event_reason_payload[:request])
end
end
class RelatedObject
attr_reader :id, :type, :url
def initialize(related_object)
@id = related_object[:id]
@type = related_object[:type]
@url = related_object[:url]
end
end
class EventNotification
attr_reader :id, :type, :created, :context, :livemode, :reason
def initialize(event_payload, client)
@id = event_payload[:id]
@type = event_payload[:type]
@created = event_payload[:created]
@livemode = event_payload[:livemode]
@reason = EventReason.new(event_payload[:reason]) if event_payload[:reason]
if event_payload[:context] && !event_payload[:context].empty?
@context = StripeContext.parse(event_payload[:context])
end
# private unless a child declares an attr_reader
@related_object = RelatedObject.new(event_payload[:related_object]) if event_payload[:related_object]
# internal use
@client = client
end
# Retrieves the Event that generated this EventNotification.
def fetch_event
resp = @client.raw_request(:get, "/v2/core/events/#{id}", opts: { stripe_context: context },
usage: ["fetch_event"])
@client.deserialize(resp.http_body, api_mode: :v2)
end
end
class UnknownEventNotification < EventNotification
attr_reader :related_object
def fetch_related_object
return nil if @related_object.nil?
resp = @client.raw_request(:get, related_object.url, opts: { stripe_context: context },
usage: ["fetch_related_object"])
@client.deserialize(resp.http_body, api_mode: Util.get_api_mode(related_object.url))
end
end
end
end

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
require "stripe/resources/v2/core/event_notification"
module Stripe
module Events
class UnknownEventNotification < Stripe::V2::Core::EventNotification
attr_reader :related_object
def fetch_related_object
return nil if @related_object.nil?
resp = @client.raw_request(:get, related_object.url, opts: { stripe_context: context },
usage: ["fetch_related_object"])
@client.deserialize(resp.http_body, api_mode: Util.get_api_mode(related_object.url))
end
end
end
end

View File

@ -0,0 +1,62 @@
# frozen_string_literal: true
module Stripe
module V2
module Core
class EventReasonRequest
attr_reader :id, :idempotency_key
def initialize(event_reason_request_payload = {})
@id = event_reason_request_payload[:id]
@idempotency_key = event_reason_request_payload[:idempotency_key]
end
end
class EventReason
attr_reader :type, :request
def initialize(event_reason_payload = {})
@type = event_reason_payload[:type]
@request = EventReasonRequest.new(event_reason_payload[:request])
end
end
class RelatedObject
attr_reader :id, :type, :url
def initialize(related_object)
@id = related_object[:id]
@type = related_object[:type]
@url = related_object[:url]
end
end
class EventNotification
attr_reader :id, :type, :created, :context, :livemode, :reason
def initialize(event_payload, client)
@id = event_payload[:id]
@type = event_payload[:type]
@created = event_payload[:created]
@livemode = event_payload[:livemode]
@reason = EventReason.new(event_payload[:reason]) if event_payload[:reason]
if event_payload[:context] && !event_payload[:context].empty?
@context = StripeContext.parse(event_payload[:context])
end
# private unless a child declares an attr_reader
@related_object = RelatedObject.new(event_payload[:related_object]) if event_payload[:related_object]
# internal use
@client = client
end
# Retrieves the Event that generated this EventNotification.
def fetch_event
resp = @client.raw_request(:get, "/v2/core/events/#{id}", opts: { stripe_context: context },
usage: ["fetch_event"])
@client.deserialize(resp.http_body, api_mode: :v2)
end
end
end
end
end

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
require "json"
require "stripe/events/unknown_event_notification"
module Stripe
class StripeClient
@ -67,7 +68,7 @@ module Stripe
parsed = JSON.parse(payload, symbolize_names: true)
cls = Util.event_notification_classes.fetch(parsed[:type], Stripe::V2::UnknownEventNotification)
cls = Util.event_notification_classes.fetch(parsed[:type], Stripe::Events::UnknownEventNotification)
cls.new(parsed, self)
end

View File

@ -1,41 +0,0 @@
# frozen_string_literal: true
# typed: true
module Stripe
module V2
class EventReasonRequest
sig { returns(String) }
def id; end
sig { returns(String) }
def idempotency_key; end
sig { params(event_reason_request_payload: T::Hash[T.untyped, T.untyped]).void }
def initialize(event_reason_request_payload = {}); end
end
class EventReason
sig { returns(String) }
def type; end
sig { returns(::Stripe::V2::EventReasonRequest) }
def request; end
sig { params(event_reason_payload: T::Hash[T.untyped, T.untyped]).void }
def initialize(event_reason_payload = {}); end
end
class EventNotification
sig { returns(String) }
def id; end
sig { returns(String) }
def type; end
sig { returns(String) }
def created; end
sig { returns(T.nilable(String)) }
def context; end
sig { returns(T::Boolean) }
def livemode; end
sig { returns(T.nilable(::Stripe::V2::EventReason)) }
def reason; end
end
end
end

View File

@ -0,0 +1,43 @@
# frozen_string_literal: true
# typed: true
module Stripe
module V2
module Core
class EventReasonRequest
sig { returns(String) }
def id; end
sig { returns(String) }
def idempotency_key; end
sig { params(event_reason_request_payload: T::Hash[T.untyped, T.untyped]).void }
def initialize(event_reason_request_payload = {}); end
end
class EventReason
sig { returns(String) }
def type; end
sig { returns(::Stripe::V2::Core::EventReasonRequest) }
def request; end
sig { params(event_reason_payload: T::Hash[T.untyped, T.untyped]).void }
def initialize(event_reason_payload = {}); end
end
class EventNotification
sig { returns(String) }
def id; end
sig { returns(String) }
def type; end
sig { returns(String) }
def created; end
sig { returns(T.nilable(String)) }
def context; end
sig { returns(T::Boolean) }
def livemode; end
sig { returns(T.nilable(::Stripe::V2::Core::EventReason)) }
def reason; end
end
end
end
end

View File

@ -10,7 +10,7 @@ module Stripe
secret: String,
tolerance: T.nilable(Integer)
)
.returns(::Stripe::V2::EventNotification)
.returns(::Stripe::V2::Core::EventNotification)
end
def parse_event_notification(payload, sig_header, secret, tolerance:); end
end

View File

@ -35,7 +35,7 @@ Gem::Specification.new do |s|
# Handwritten RBIs
# TODO(helenye): http://go/j/DEVSDK-2769
%r{\Arbi/stripe/stripe_client.rbi\z},
%r{\Arbi/stripe/event_notification.rbi\z}
%r{\Arbi/stripe/resources/v2/core/event_notification.rbi\z}
)
s.files = `git ls-files`.split("\n").grep(included)
s.bindir = "exe"

View File

@ -927,13 +927,13 @@ module Stripe
context "v2 resources" do
should "raise an NotImplementedError on resource_url" do
assert_raises NotImplementedError do
Stripe::V2::Event.resource_url
Stripe::V2::Core::Event.resource_url
end
end
should "raise an NotImplementedError on retrieve" do
assert_raises NotImplementedError do
Stripe::V2::Event.retrieve("acct_123")
Stripe::V2::Core::Event.retrieve("acct_123")
end
end

View File

@ -158,7 +158,7 @@ module Stripe
assert_equal nil, req.headers["Content-Type"]
assert resp.is_a?(Stripe::V2::Event)
assert resp.is_a?(Stripe::V2::Core::Event)
assert_equal "sk_test_123", resp.instance_variable_get(:@opts)[:api_key]
assert_equal 200, resp.last_response.http_status
end
@ -380,7 +380,7 @@ module Stripe
obj = @client.deserialize(expected_body, api_mode: :v2)
assert_equal obj.class, Stripe::V2::Event
assert_equal obj.class, Stripe::V2::Core::Event
assert_equal obj.id, "evt_123"
end
end

View File

@ -377,7 +377,7 @@ module Stripe
context: "workspace/account/customer",
}
notification = Stripe::V2::EventNotification.new(event_payload, client)
notification = Stripe::V2::Core::EventNotification.new(event_payload, client)
assert_not_nil notification.context
assert_equal "workspace/account/customer", notification.context.to_s
@ -395,7 +395,7 @@ module Stripe
context: nil,
}
notification = Stripe::V2::EventNotification.new(event_payload, client)
notification = Stripe::V2::Core::EventNotification.new(event_payload, client)
assert_nil notification.context
end
@ -410,7 +410,7 @@ module Stripe
context: "",
}
notification = Stripe::V2::EventNotification.new(event_payload, client)
notification = Stripe::V2::Core::EventNotification.new(event_payload, client)
assert_nil notification.context
end

View File

@ -95,7 +95,7 @@ module Stripe
context ".event_signing" do
should "parse v2 events" do
event = parse_signed_event(@v2_push_payload)
assert event.is_a?(Stripe::V2::EventNotification)
assert event.is_a?(Stripe::V2::Core::EventNotification)
assert_equal "evt_234", event.id
assert_equal "v1.billing.meter.error_report_triggered", event.type
assert_equal "2022-02-15T00:27:45.330Z", event.created
@ -104,9 +104,9 @@ module Stripe
should "parse v2 events with livemode and reason" do
event = parse_signed_event(@v2_push_payload_with_livemode_and_reason)
assert event.is_a?(Stripe::V2::EventNotification)
assert event.related_object.is_a?(Stripe::V2::RelatedObject)
assert event.reason.is_a?(Stripe::V2::EventReason)
assert event.is_a?(Stripe::V2::Core::EventNotification)
assert event.related_object.is_a?(Stripe::V2::Core::RelatedObject)
assert event.reason.is_a?(Stripe::V2::Core::EventReason)
assert_equal "evt_234", event.id
assert_equal "v1.billing.meter.error_report_triggered", event.type
@ -158,7 +158,7 @@ module Stripe
should "parse unknown events" do
event_notif = parse_signed_event(@v2_payload_fake_event)
assert event_notif.instance_of?(Stripe::V2::UnknownEventNotification)
assert event_notif.instance_of?(Stripe::Events::UnknownEventNotification)
stub_request(:get, "#{Stripe::DEFAULT_API_BASE}/v2/core/events/evt_234")
.to_return(body: {
@ -169,7 +169,7 @@ module Stripe
}.to_json)
event = event_notif.fetch_event
assert event.instance_of?(Stripe::V2::Event)
assert event.instance_of?(Stripe::V2::Core::Event)
end
end
end

View File

@ -199,7 +199,7 @@ module Stripe
.to_return(body: JSON.generate(data: [{ id: 2, object: "v2.core.event" }, { id: 3, object: "v2.core.event" }, { id: 4, object: "v2.core.event" }], next_page_url: nil))
list.each do |obj|
assert_instance_of(Stripe::V2::Event, obj)
assert_instance_of(Stripe::V2::Core::Event, obj)
end
end