Debian Codegraph @

stripe/events/_v2_core_account_person_created_event.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._api_mode import ApiMode
4 from stripe._stripe_object import StripeObject
5 from stripe._stripe_response import StripeResponse
6 from stripe._util import get_api_mode
7 from stripe.v2.core._event import Event, EventNotification, RelatedObject
8 from typing import Any, Dict, Optional, cast
9 from typing_extensions import Literal, TYPE_CHECKING, override
10
11 if TYPE_CHECKING:
12 from stripe._api_requestor import _APIRequestor
13 from stripe._stripe_client import StripeClient
14 from stripe.v2.core._account_person import AccountPerson
15
16
17 class V2CoreAccountPersonCreatedEventNotification(EventNotification):
18 LOOKUP_TYPE = "v2.core.account_person.created"
19 type: Literal["v2.core.account_person.created"]
20 related_object: RelatedObject
21
22 def __init__(
23 self, parsed_body: Dict[str, Any], client: "StripeClient"
24 ) -> None:
25 super().__init__(
26 parsed_body,
27 client,
28 )
29 self.related_object = RelatedObject(parsed_body["related_object"])
30
31 @override
32 def fetch_event(self) -> "V2CoreAccountPersonCreatedEvent":
33 return cast(
34 "V2CoreAccountPersonCreatedEvent",
35 super().fetch_event(),
36 )
37
38 def fetch_related_object(self) -> "AccountPerson":
39 response = self._client.raw_request(
40 "get",
41 self.related_object.url,
42 stripe_context=self.context,
43 headers={"Stripe-Request-Trigger": f"event={self.id}"},
44 usage=["fetch_related_object"],
45 )
46 return cast(
47 "AccountPerson",
48 self._client.deserialize(
49 response,
50 api_mode=get_api_mode(self.related_object.url),
51 ),
52 )
53
54 @override
55 async def fetch_event_async(self) -> "V2CoreAccountPersonCreatedEvent":
56 return cast(
57 "V2CoreAccountPersonCreatedEvent",
58 await super().fetch_event_async(),
59 )
60
61 async def fetch_related_object_async(self) -> "AccountPerson":
62 response = await self._client.raw_request_async(
63 "get",
64 self.related_object.url,
65 stripe_context=self.context,
66 headers={"Stripe-Request-Trigger": f"event={self.id}"},
67 usage=["fetch_related_object"],
68 )
69 return cast(
70 "AccountPerson",
71 self._client.deserialize(
72 response,
73 api_mode=get_api_mode(self.related_object.url),
74 ),
75 )
76
77
78 class V2CoreAccountPersonCreatedEvent(Event):
79 LOOKUP_TYPE = "v2.core.account_person.created"
80 type: Literal["v2.core.account_person.created"]
81
82 class V2CoreAccountPersonCreatedEventData(StripeObject):
83 account_id: str
84 """
85 The ID of the v2 account.
86 """
87
88 data: V2CoreAccountPersonCreatedEventData
89 """
90 Data for the v2.core.account_person.created event
91 """
92
93 @classmethod
94 def _construct_from(
95 cls,
96 *,
97 values: Dict[str, Any],
98 last_response: Optional[StripeResponse] = None,
99 requestor: "_APIRequestor",
100 api_mode: ApiMode,
101 ) -> "V2CoreAccountPersonCreatedEvent":
102 evt = super()._construct_from(
103 values=values,
104 last_response=last_response,
105 requestor=requestor,
106 api_mode=api_mode,
107 )
108 if hasattr(evt, "data"):
109 evt.data = V2CoreAccountPersonCreatedEvent.V2CoreAccountPersonCreatedEventData._construct_from(
110 values=evt.data,
111 last_response=last_response,
112 requestor=requestor,
113 api_mode=api_mode,
114 )
115 return evt
116
117 class RelatedObject(StripeObject):
118 id: str
119 """
120 Unique identifier for the object relevant to the event.
121 """
122 type: str
123 """
124 Type of the object relevant to the event.
125 """
126 url: str
127 """
128 URL to retrieve the resource.
129 """
130
131 related_object: RelatedObject
132 """
133 Object containing the reference to API resource relevant to the event
134 """
135
136 def fetch_related_object(self) -> "AccountPerson":
137 """
138 Retrieves the related object from the API. Makes an API request on every call.
139 """
140 return cast(
141 "AccountPerson",
142 self._requestor.request(
143 "get",
144 self.related_object.url,
145 base_address="api",
146 options={
147 "stripe_context": self.context,
148 "headers": {"Stripe-Request-Trigger": f"event={self.id}"},
149 },
150 ),
151 )