This commit is contained in:
Iliyan Angelov
2025-11-17 18:26:30 +02:00
parent 48353cde9c
commit 0c59fe1173
2535 changed files with 278997 additions and 2480 deletions

View File

@@ -0,0 +1,39 @@
from typing_extensions import TYPE_CHECKING
from stripe.v2._list_object import ListObject as ListObject
from stripe.v2._amount import Amount as Amount, AmountParam as AmountParam
# The beginning of the section generated from our OpenAPI spec
from importlib import import_module
if TYPE_CHECKING:
from stripe.v2 import billing as billing, core as core
from stripe.v2._billing_service import BillingService as BillingService
from stripe.v2._core_service import CoreService as CoreService
from stripe.v2._deleted_object import DeletedObject as DeletedObject
# name -> (import_target, is_submodule)
_import_map = {
"billing": ("stripe.v2.billing", True),
"core": ("stripe.v2.core", True),
"BillingService": ("stripe.v2._billing_service", False),
"CoreService": ("stripe.v2._core_service", False),
"DeletedObject": ("stripe.v2._deleted_object", False),
}
if not TYPE_CHECKING:
def __getattr__(name):
try:
target, is_submodule = _import_map[name]
module = import_module(target)
if is_submodule:
return module
return getattr(
module,
name,
)
except KeyError:
raise AttributeError()
# The end of the section generated from our OpenAPI spec

View File

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# NOT codegenned
from typing_extensions import TypedDict
from stripe._stripe_object import StripeObject
class Amount(StripeObject):
value: int
currency: str
class AmountParam(TypedDict):
value: int
currency: str

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from importlib import import_module
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe.v2.billing._meter_event_adjustment_service import (
MeterEventAdjustmentService,
)
from stripe.v2.billing._meter_event_service import MeterEventService
from stripe.v2.billing._meter_event_session_service import (
MeterEventSessionService,
)
from stripe.v2.billing._meter_event_stream_service import (
MeterEventStreamService,
)
_subservices = {
"meter_events": [
"stripe.v2.billing._meter_event_service",
"MeterEventService",
],
"meter_event_adjustments": [
"stripe.v2.billing._meter_event_adjustment_service",
"MeterEventAdjustmentService",
],
"meter_event_session": [
"stripe.v2.billing._meter_event_session_service",
"MeterEventSessionService",
],
"meter_event_stream": [
"stripe.v2.billing._meter_event_stream_service",
"MeterEventStreamService",
],
}
class BillingService(StripeService):
meter_events: "MeterEventService"
meter_event_adjustments: "MeterEventAdjustmentService"
meter_event_session: "MeterEventSessionService"
meter_event_stream: "MeterEventStreamService"
def __init__(self, requestor):
super().__init__(requestor)
def __getattr__(self, name):
try:
import_from, service = _subservices[name]
service_class = getattr(
import_module(import_from),
service,
)
setattr(
self,
name,
service_class(self._requestor),
)
return getattr(self, name)
except KeyError:
raise AttributeError()

View File

@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from importlib import import_module
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe.v2.core._event_destination_service import (
EventDestinationService,
)
from stripe.v2.core._event_service import EventService
_subservices = {
"events": ["stripe.v2.core._event_service", "EventService"],
"event_destinations": [
"stripe.v2.core._event_destination_service",
"EventDestinationService",
],
}
class CoreService(StripeService):
events: "EventService"
event_destinations: "EventDestinationService"
def __init__(self, requestor):
super().__init__(requestor)
def __getattr__(self, name):
try:
import_from, service = _subservices[name]
service_class = getattr(
import_module(import_from),
service,
)
setattr(
self,
name,
service_class(self._requestor),
)
return getattr(self, name)
except KeyError:
raise AttributeError()

View File

@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_object import StripeObject
from typing import Optional
class DeletedObject(StripeObject):
id: str
"""
The ID of the object that's being deleted.
"""
object: Optional[str]
"""
String representing the type of the object that has been deleted. Objects of the same type share the same value of the object field.
"""

View File

@@ -0,0 +1,59 @@
from stripe._stripe_object import StripeObject
from typing import List, Optional, TypeVar, Generic
T = TypeVar("T", bound=StripeObject)
class ListObject(StripeObject, Generic[T]):
"""
Represents one page of a list of V2 Stripe objects. Use `.data` to access
the objects on this page, or use
for item in list_object.auto_paging_iter():
# do something with item
to iterate over this and all following pages.
"""
OBJECT_NAME = "list"
data: List[T]
next_page_url: Optional[str]
def __getitem__(self, k):
if isinstance(k, str): # type: ignore
return super(ListObject, self).__getitem__(k)
else:
raise KeyError(
"You tried to access the %s index, but ListObjectV2 types only "
"support string keys. (HINT: List calls return an object with "
"a 'data' (which is the data array). You likely want to call "
".data[%s])" % (repr(k), repr(k))
)
def __iter__(self):
return getattr(self, "data", []).__iter__()
def __len__(self):
return getattr(self, "data", []).__len__()
def __reversed__(self):
return getattr(self, "data", []).__reversed__()
def auto_paging_iter(self):
page = self.data
next_page_url = self.next_page_url
while True:
for item in page:
yield item
if next_page_url is None:
break
result = self._request(
"get",
next_page_url,
base_address="api",
)
assert isinstance(result, ListObject)
page = result.data
next_page_url = result.next_page_url

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from importlib import import_module
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe.v2.billing._meter_event import MeterEvent as MeterEvent
from stripe.v2.billing._meter_event_adjustment import (
MeterEventAdjustment as MeterEventAdjustment,
)
from stripe.v2.billing._meter_event_adjustment_service import (
MeterEventAdjustmentService as MeterEventAdjustmentService,
)
from stripe.v2.billing._meter_event_service import (
MeterEventService as MeterEventService,
)
from stripe.v2.billing._meter_event_session import (
MeterEventSession as MeterEventSession,
)
from stripe.v2.billing._meter_event_session_service import (
MeterEventSessionService as MeterEventSessionService,
)
from stripe.v2.billing._meter_event_stream_service import (
MeterEventStreamService as MeterEventStreamService,
)
# name -> (import_target, is_submodule)
_import_map = {
"MeterEvent": ("stripe.v2.billing._meter_event", False),
"MeterEventAdjustment": (
"stripe.v2.billing._meter_event_adjustment",
False,
),
"MeterEventAdjustmentService": (
"stripe.v2.billing._meter_event_adjustment_service",
False,
),
"MeterEventService": ("stripe.v2.billing._meter_event_service", False),
"MeterEventSession": ("stripe.v2.billing._meter_event_session", False),
"MeterEventSessionService": (
"stripe.v2.billing._meter_event_session_service",
False,
),
"MeterEventStreamService": (
"stripe.v2.billing._meter_event_stream_service",
False,
),
}
if not TYPE_CHECKING:
def __getattr__(name):
try:
target, is_submodule = _import_map[name]
module = import_module(target)
if is_submodule:
return module
return getattr(
module,
name,
)
except KeyError:
raise AttributeError()

View File

@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_object import StripeObject
from typing import ClassVar, Dict
from typing_extensions import Literal
class MeterEvent(StripeObject):
"""
Fix me empty_doc_string.
"""
OBJECT_NAME: ClassVar[Literal["v2.billing.meter_event"]] = (
"v2.billing.meter_event"
)
created: str
"""
The creation time of this meter event.
"""
event_name: str
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
identifier: str
"""
A unique identifier for the event. If not provided, one will be generated. We recommend using a globally unique identifier for this. We'll enforce uniqueness within a rolling 24 hour period.
"""
livemode: bool
"""
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
"""
object: Literal["v2.billing.meter_event"]
"""
String representing the object's type. Objects of the same type share the same value of the object field.
"""
payload: Dict[str, str]
"""
The payload of the event. This must contain the fields corresponding to a meter's
`customer_mapping.event_payload_key` (default is `stripe_customer_id`) and
`value_settings.event_payload_key` (default is `value`). Read more about
the [payload](https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage#payload-key-overrides)..
"""
timestamp: str
"""
The time of the event. Must be within the past 35 calendar days or up to
5 minutes in the future. Defaults to current timestamp if not specified.
"""

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_object import StripeObject
from typing import ClassVar
from typing_extensions import Literal
class MeterEventAdjustment(StripeObject):
OBJECT_NAME: ClassVar[Literal["v2.billing.meter_event_adjustment"]] = (
"v2.billing.meter_event_adjustment"
)
class Cancel(StripeObject):
identifier: str
"""
Unique identifier for the event. You can only cancel events within 24 hours of Stripe receiving them.
"""
cancel: Cancel
"""
Specifies which event to cancel.
"""
created: str
"""
The time the adjustment was created.
"""
event_name: str
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
id: str
"""
The unique id of this meter event adjustment.
"""
livemode: bool
"""
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
"""
object: Literal["v2.billing.meter_event_adjustment"]
"""
String representing the object's type. Objects of the same type share the same value of the object field.
"""
status: Literal["complete", "pending"]
"""
Open Enum. The meter event adjustment's status.
"""
type: Literal["cancel"]
"""
Open Enum. Specifies whether to cancel a single event or a range of events for a time period. Time period cancellation is not supported yet.
"""
_inner_class_types = {"cancel": Cancel}

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from typing import Optional, cast
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._request_options import RequestOptions
from stripe.params.v2.billing._meter_event_adjustment_create_params import (
MeterEventAdjustmentCreateParams,
)
from stripe.v2.billing._meter_event_adjustment import MeterEventAdjustment
class MeterEventAdjustmentService(StripeService):
def create(
self,
params: "MeterEventAdjustmentCreateParams",
options: Optional["RequestOptions"] = None,
) -> "MeterEventAdjustment":
"""
Creates a meter event adjustment to cancel a previously sent meter event.
"""
return cast(
"MeterEventAdjustment",
self._request(
"post",
"/v2/billing/meter_event_adjustments",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "MeterEventAdjustmentCreateParams",
options: Optional["RequestOptions"] = None,
) -> "MeterEventAdjustment":
"""
Creates a meter event adjustment to cancel a previously sent meter event.
"""
return cast(
"MeterEventAdjustment",
await self._request_async(
"post",
"/v2/billing/meter_event_adjustments",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from typing import Optional, cast
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._request_options import RequestOptions
from stripe.params.v2.billing._meter_event_create_params import (
MeterEventCreateParams,
)
from stripe.v2.billing._meter_event import MeterEvent
class MeterEventService(StripeService):
def create(
self,
params: "MeterEventCreateParams",
options: Optional["RequestOptions"] = None,
) -> "MeterEvent":
"""
Creates a meter event. Events are validated synchronously, but are processed asynchronously. Supports up to 1,000 events per second in livemode. For higher rate-limits, please use meter event streams instead.
"""
return cast(
"MeterEvent",
self._request(
"post",
"/v2/billing/meter_events",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "MeterEventCreateParams",
options: Optional["RequestOptions"] = None,
) -> "MeterEvent":
"""
Creates a meter event. Events are validated synchronously, but are processed asynchronously. Supports up to 1,000 events per second in livemode. For higher rate-limits, please use meter event streams instead.
"""
return cast(
"MeterEvent",
await self._request_async(
"post",
"/v2/billing/meter_events",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_object import StripeObject
from typing import ClassVar
from typing_extensions import Literal
class MeterEventSession(StripeObject):
OBJECT_NAME: ClassVar[Literal["v2.billing.meter_event_session"]] = (
"v2.billing.meter_event_session"
)
authentication_token: str
"""
The authentication token for this session. Use this token when calling the
high-throughput meter event API.
"""
created: str
"""
The creation time of this session.
"""
expires_at: str
"""
The time at which this session will expire.
"""
id: str
"""
The unique id of this auth session.
"""
livemode: bool
"""
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
"""
object: Literal["v2.billing.meter_event_session"]
"""
String representing the object's type. Objects of the same type share the same value of the object field.
"""

View File

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from typing import Optional, cast
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._request_options import RequestOptions
from stripe.params.v2.billing._meter_event_session_create_params import (
MeterEventSessionCreateParams,
)
from stripe.v2.billing._meter_event_session import MeterEventSession
class MeterEventSessionService(StripeService):
def create(
self,
params: Optional["MeterEventSessionCreateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "MeterEventSession":
"""
Creates a meter event session to send usage on the high-throughput meter event stream. Authentication tokens are only valid for 15 minutes, so you will need to create a new meter event session when your token expires.
"""
return cast(
"MeterEventSession",
self._request(
"post",
"/v2/billing/meter_event_session",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: Optional["MeterEventSessionCreateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "MeterEventSession":
"""
Creates a meter event session to send usage on the high-throughput meter event stream. Authentication tokens are only valid for 15 minutes, so you will need to create a new meter event session when your token expires.
"""
return cast(
"MeterEventSession",
await self._request_async(
"post",
"/v2/billing/meter_event_session",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from typing import Optional
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._request_options import RequestOptions
from stripe.params.v2.billing._meter_event_stream_create_params import (
MeterEventStreamCreateParams,
)
class MeterEventStreamService(StripeService):
def create(
self,
params: "MeterEventStreamCreateParams",
options: Optional["RequestOptions"] = None,
) -> "None":
"""
Creates meter events. Events are processed asynchronously, including validation. Requires a meter event session for authentication. Supports up to 10,000 requests per second in livemode. For even higher rate-limits, contact sales.
"""
self._request(
"post",
"/v2/billing/meter_event_stream",
base_address="meter_events",
params=params,
options=options,
)
async def create_async(
self,
params: "MeterEventStreamCreateParams",
options: Optional["RequestOptions"] = None,
) -> "None":
"""
Creates meter events. Events are processed asynchronously, including validation. Requires a meter event session for authentication. Supports up to 10,000 requests per second in livemode. For even higher rate-limits, contact sales.
"""
await self._request_async(
"post",
"/v2/billing/meter_event_stream",
base_address="meter_events",
params=params,
options=options,
)

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
from typing_extensions import TYPE_CHECKING
from stripe.v2.core._event import (
EventNotification as EventNotification,
RelatedObject as RelatedObject,
Reason as Reason,
ReasonRequest as ReasonRequest,
)
# The beginning of the section generated from our OpenAPI spec
from importlib import import_module
if TYPE_CHECKING:
from stripe.v2.core._event import Event as Event
from stripe.v2.core._event_destination import (
EventDestination as EventDestination,
)
from stripe.v2.core._event_destination_service import (
EventDestinationService as EventDestinationService,
)
from stripe.v2.core._event_service import EventService as EventService
# name -> (import_target, is_submodule)
_import_map = {
"Event": ("stripe.v2.core._event", False),
"EventDestination": ("stripe.v2.core._event_destination", False),
"EventDestinationService": (
"stripe.v2.core._event_destination_service",
False,
),
"EventService": ("stripe.v2.core._event_service", False),
}
if not TYPE_CHECKING:
def __getattr__(name):
try:
target, is_submodule = _import_map[name]
module = import_module(target)
if is_submodule:
return module
return getattr(
module,
name,
)
except KeyError:
raise AttributeError()
# The end of the section generated from our OpenAPI spec

View File

@@ -0,0 +1,250 @@
# -*- coding: utf-8 -*-
import json
from typing import Any, ClassVar, Dict, Optional, cast
from typing_extensions import Literal, TYPE_CHECKING
from stripe._stripe_object import StripeObject
from stripe._util import get_api_mode
from stripe._stripe_context import StripeContext
if TYPE_CHECKING:
from stripe._stripe_client import StripeClient
# The beginning of the section generated from our OpenAPI spec
class Event(StripeObject):
"""
Events are generated to keep you informed of activity in your business account. APIs in the /v2 namespace generate [thin events](https://docs.stripe.com/event-destinations#benefits-of-thin-events) which have small, unversioned payloads that include a reference to the ID of the object that has changed. The Events v2 API returns these new thin events. [Retrieve the event object](https://docs.stripe.com/event-destinations#fetch-data) for additional data about the event. Use the related object ID in the event payload to [fetch the API resource](https://docs.stripe.com/event-destinations#retrieve-the-object-associated-with-thin-events) of the object associated with the event. Comparatively, events generated by most API v1 include a versioned snapshot of an API object in their payload.
"""
OBJECT_NAME: ClassVar[Literal["v2.core.event"]] = "v2.core.event"
class Reason(StripeObject):
class Request(StripeObject):
id: str
"""
ID of the API request that caused the event.
"""
idempotency_key: str
"""
The idempotency key transmitted during the request.
"""
request: Optional[Request]
"""
Information on the API request that instigated the event.
"""
type: Literal["request"]
"""
Event reason type.
"""
_inner_class_types = {"request": Request}
context: Optional[str]
"""
Authentication context needed to fetch the event or related object.
"""
created: str
"""
Time at which the object was created.
"""
id: str
"""
Unique identifier for the event.
"""
livemode: bool
"""
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
"""
object: Literal["v2.core.event"]
"""
String representing the object's type. Objects of the same type share the same value of the object field.
"""
reason: Optional[Reason]
"""
Reason for the event.
"""
type: str
"""
The type of the event.
"""
_inner_class_types = {"reason": Reason}
# The end of the section generated from our OpenAPI spec
class ReasonRequest:
id: str
idempotency_key: str
def __init__(self, d) -> None:
self.id = d["id"]
self.idempotency_key = d["idempotency_key"]
def __repr__(self) -> str:
return f"<ReasonRequest id={self.id} idempotency_key={self.idempotency_key}>"
class Reason:
type: Literal["request"]
request: Optional[ReasonRequest] = None
def __init__(self, d) -> None:
self.type = d["type"]
if self.type == "request":
self.request = ReasonRequest(d["request"])
def __repr__(self) -> str:
return f"<Reason type={self.type} request={self.request}>"
class RelatedObject:
id: str
type: str
url: str
def __init__(self, d) -> None:
self.id = d["id"]
self.type = d["type"]
self.url = d["url"]
def __repr__(self) -> str:
return f"<RelatedObject id={self.id} type={self.type} url={self.url}>"
class EventNotification:
"""
EventNotification represents the json that's delivered from an Event Destination. It's a basic struct-like object with a few convenience methods. Use `fetch_event()` to get the full event object.
"""
id: str
"""
Unique identifier for the event.
"""
type: str
"""
The type of the event.
"""
created: str
"""
Time at which the object was created.
"""
livemode: bool
"""
Livemode indicates if the event is from a production(true) or test(false) account.
"""
context: Optional[StripeContext] = None
"""
[Optional] Authentication context needed to fetch the event or related object.
"""
reason: Optional[Reason] = None
"""
[Optional] Reason for the event.
"""
def __init__(
self, parsed_body: Dict[str, Any], client: "StripeClient"
) -> None:
self.id = parsed_body["id"]
self.type = parsed_body["type"]
self.created = parsed_body["created"]
self.livemode = bool(parsed_body.get("livemode"))
context_value = parsed_body.get("context")
if context_value:
self.context = StripeContext.parse(context_value)
if parsed_body.get("reason"):
self.reason = Reason(parsed_body["reason"])
self._client = client
@staticmethod
def from_json(payload: str, client: "StripeClient") -> "EventNotification":
"""
Helper for constructing an Event Notification. Doesn't perform signature validation, so you
should use StripeClient.parseEventNotification() instead for initial handling.
This is useful in unit tests and working with EventNotifications that you've already validated the authenticity of.
"""
parsed_body = json.loads(payload)
# circular import busting
from stripe.events._event_classes import (
get_v2_event_notification_class,
)
event_class = get_v2_event_notification_class(parsed_body["type"])
return event_class(parsed_body, client)
def __repr__(self) -> str:
return f"<EventNotification id={self.id} type={self.type} created={self.created} context={self.context} reason={self.reason}>"
def fetch_event(self) -> Event:
response = self._client.raw_request(
"get",
f"/v2/core/events/{self.id}",
stripe_context=self.context,
usage=["pushed_event_pull"],
)
return cast(Event, self._client.deserialize(response, api_mode="V2"))
async def fetch_event_async(self) -> Event:
response = await self._client.raw_request_async(
"get",
f"/v2/core/events/{self.id}",
stripe_context=self.context,
usage=["pushed_event_pull", "pushed_event_pull_async"],
)
return cast(Event, self._client.deserialize(response, api_mode="V2"))
class UnknownEventNotification(EventNotification):
"""
Represents an EventNotification payload that the SDK doesn't have types for. May have a related object.
"""
related_object: Optional[RelatedObject] = None
"""
[Optional] Object containing the reference to API resource relevant to the event.
"""
def __init__(
self, parsed_body: Dict[str, Any], client: "StripeClient"
) -> None:
super().__init__(parsed_body, client)
if parsed_body.get("related_object"):
self.related_object = RelatedObject(parsed_body["related_object"])
def fetch_related_object(self) -> Optional[StripeObject]:
if self.related_object is None:
return None
response = self._client.raw_request(
"get",
self.related_object.url,
stripe_context=self.context,
usage=["fetch_related_object", "unknown_event"],
)
return self._client.deserialize(
response,
api_mode=get_api_mode(self.related_object.url),
)
async def fetch_related_object_async(self) -> Optional[StripeObject]:
if self.related_object is None:
return None
response = await self._client.raw_request_async(
"get",
self.related_object.url,
stripe_context=self.context,
usage=["fetch_related_object", "unknown_event"],
)
return self._client.deserialize(
response,
api_mode=get_api_mode(self.related_object.url),
)

View File

@@ -0,0 +1,128 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_object import StripeObject
from typing import ClassVar, Dict, List, Optional
from typing_extensions import Literal
class EventDestination(StripeObject):
"""
Set up an event destination to receive events from Stripe across multiple destination types, including [webhook endpoints](https://docs.stripe.com/webhooks) and [Amazon EventBridge](https://docs.stripe.com/event-destinations/eventbridge). Event destinations support receiving [thin events](https://docs.stripe.com/api/v2/events) and [snapshot events](https://docs.stripe.com/api/events).
"""
OBJECT_NAME: ClassVar[Literal["v2.core.event_destination"]] = (
"v2.core.event_destination"
)
class AmazonEventbridge(StripeObject):
aws_account_id: str
"""
The AWS account ID.
"""
aws_event_source_arn: str
"""
The ARN of the AWS event source.
"""
aws_event_source_status: Literal[
"active", "deleted", "pending", "unknown"
]
"""
The state of the AWS event source.
"""
class StatusDetails(StripeObject):
class Disabled(StripeObject):
reason: Literal["no_aws_event_source_exists", "user"]
"""
Reason event destination has been disabled.
"""
disabled: Optional[Disabled]
"""
Details about why the event destination has been disabled.
"""
_inner_class_types = {"disabled": Disabled}
class WebhookEndpoint(StripeObject):
signing_secret: Optional[str]
"""
The signing secret of the webhook endpoint, only includable on creation.
"""
url: Optional[str]
"""
The URL of the webhook endpoint, includable.
"""
amazon_eventbridge: Optional[AmazonEventbridge]
"""
Amazon EventBridge configuration.
"""
created: str
"""
Time at which the object was created.
"""
description: str
"""
An optional description of what the event destination is used for.
"""
enabled_events: List[str]
"""
The list of events to enable for this endpoint.
"""
event_payload: Literal["snapshot", "thin"]
"""
Payload type of events being subscribed to.
"""
events_from: Optional[List[Literal["other_accounts", "self"]]]
"""
Where events should be routed from.
"""
id: str
"""
Unique identifier for the object.
"""
livemode: bool
"""
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
"""
metadata: Optional[Dict[str, str]]
"""
Metadata.
"""
name: str
"""
Event destination name.
"""
object: Literal["v2.core.event_destination"]
"""
String representing the object's type. Objects of the same type share the same value of the object field.
"""
snapshot_api_version: Optional[str]
"""
If using the snapshot event payload, the API version events are rendered as.
"""
status: Literal["disabled", "enabled"]
"""
Status. It can be set to either enabled or disabled.
"""
status_details: Optional[StatusDetails]
"""
Additional information about event destination status.
"""
type: Literal["amazon_eventbridge", "webhook_endpoint"]
"""
Event destination type.
"""
updated: str
"""
Time at which the object was last updated.
"""
webhook_endpoint: Optional[WebhookEndpoint]
"""
Webhook endpoint configuration.
"""
_inner_class_types = {
"amazon_eventbridge": AmazonEventbridge,
"status_details": StatusDetails,
"webhook_endpoint": WebhookEndpoint,
}

View File

@@ -0,0 +1,367 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from stripe._util import sanitize_id
from typing import Optional, cast
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._request_options import RequestOptions
from stripe.params.v2.core._event_destination_create_params import (
EventDestinationCreateParams,
)
from stripe.params.v2.core._event_destination_delete_params import (
EventDestinationDeleteParams,
)
from stripe.params.v2.core._event_destination_disable_params import (
EventDestinationDisableParams,
)
from stripe.params.v2.core._event_destination_enable_params import (
EventDestinationEnableParams,
)
from stripe.params.v2.core._event_destination_list_params import (
EventDestinationListParams,
)
from stripe.params.v2.core._event_destination_ping_params import (
EventDestinationPingParams,
)
from stripe.params.v2.core._event_destination_retrieve_params import (
EventDestinationRetrieveParams,
)
from stripe.params.v2.core._event_destination_update_params import (
EventDestinationUpdateParams,
)
from stripe.v2._deleted_object import DeletedObject
from stripe.v2._list_object import ListObject
from stripe.v2.core._event import Event
from stripe.v2.core._event_destination import EventDestination
class EventDestinationService(StripeService):
def list(
self,
params: Optional["EventDestinationListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[EventDestination]":
"""
Lists all event destinations.
"""
return cast(
"ListObject[EventDestination]",
self._request(
"get",
"/v2/core/event_destinations",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: Optional["EventDestinationListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[EventDestination]":
"""
Lists all event destinations.
"""
return cast(
"ListObject[EventDestination]",
await self._request_async(
"get",
"/v2/core/event_destinations",
base_address="api",
params=params,
options=options,
),
)
def create(
self,
params: "EventDestinationCreateParams",
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Create a new event destination.
"""
return cast(
"EventDestination",
self._request(
"post",
"/v2/core/event_destinations",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "EventDestinationCreateParams",
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Create a new event destination.
"""
return cast(
"EventDestination",
await self._request_async(
"post",
"/v2/core/event_destinations",
base_address="api",
params=params,
options=options,
),
)
def delete(
self,
id: str,
params: Optional["EventDestinationDeleteParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "DeletedObject":
"""
Delete an event destination.
"""
return cast(
"DeletedObject",
self._request(
"delete",
"/v2/core/event_destinations/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def delete_async(
self,
id: str,
params: Optional["EventDestinationDeleteParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "DeletedObject":
"""
Delete an event destination.
"""
return cast(
"DeletedObject",
await self._request_async(
"delete",
"/v2/core/event_destinations/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: Optional["EventDestinationRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Retrieves the details of an event destination.
"""
return cast(
"EventDestination",
self._request(
"get",
"/v2/core/event_destinations/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: Optional["EventDestinationRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Retrieves the details of an event destination.
"""
return cast(
"EventDestination",
await self._request_async(
"get",
"/v2/core/event_destinations/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def update(
self,
id: str,
params: Optional["EventDestinationUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Update the details of an event destination.
"""
return cast(
"EventDestination",
self._request(
"post",
"/v2/core/event_destinations/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def update_async(
self,
id: str,
params: Optional["EventDestinationUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Update the details of an event destination.
"""
return cast(
"EventDestination",
await self._request_async(
"post",
"/v2/core/event_destinations/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def disable(
self,
id: str,
params: Optional["EventDestinationDisableParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Disable an event destination.
"""
return cast(
"EventDestination",
self._request(
"post",
"/v2/core/event_destinations/{id}/disable".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
async def disable_async(
self,
id: str,
params: Optional["EventDestinationDisableParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Disable an event destination.
"""
return cast(
"EventDestination",
await self._request_async(
"post",
"/v2/core/event_destinations/{id}/disable".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
def enable(
self,
id: str,
params: Optional["EventDestinationEnableParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Enable an event destination.
"""
return cast(
"EventDestination",
self._request(
"post",
"/v2/core/event_destinations/{id}/enable".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
async def enable_async(
self,
id: str,
params: Optional["EventDestinationEnableParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "EventDestination":
"""
Enable an event destination.
"""
return cast(
"EventDestination",
await self._request_async(
"post",
"/v2/core/event_destinations/{id}/enable".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
def ping(
self,
id: str,
params: Optional["EventDestinationPingParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Event":
"""
Send a `ping` event to an event destination.
"""
return cast(
"Event",
self._request(
"post",
"/v2/core/event_destinations/{id}/ping".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
async def ping_async(
self,
id: str,
params: Optional["EventDestinationPingParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Event":
"""
Send a `ping` event to an event destination.
"""
return cast(
"Event",
await self._request_async(
"post",
"/v2/core/event_destinations/{id}/ping".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_service import StripeService
from stripe._util import sanitize_id
from typing import Optional, cast
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._request_options import RequestOptions
from stripe.params.v2.core._event_list_params import EventListParams
from stripe.params.v2.core._event_retrieve_params import (
EventRetrieveParams,
)
from stripe.v2._list_object import ListObject
from stripe.v2.core._event import Event
class EventService(StripeService):
def list(
self,
params: Optional["EventListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[Event]":
"""
List events, going back up to 30 days.
"""
return cast(
"ListObject[Event]",
self._request(
"get",
"/v2/core/events",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: Optional["EventListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[Event]":
"""
List events, going back up to 30 days.
"""
return cast(
"ListObject[Event]",
await self._request_async(
"get",
"/v2/core/events",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: Optional["EventRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Event":
"""
Retrieves the details of an event.
"""
return cast(
"Event",
self._request(
"get",
"/v2/core/events/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: Optional["EventRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Event":
"""
Retrieves the details of an event.
"""
return cast(
"Event",
await self._request_async(
"get",
"/v2/core/events/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)