Debian Codegraph @

stripe/events/_v2_core_account_updated_event.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._stripe_object import StripeObject
4 from stripe._util import get_api_mode
5 from stripe.v2.core._event import Event, EventNotification, RelatedObject
6 from typing import Any, Dict, cast
7 from typing_extensions import Literal, TYPE_CHECKING, override
8
9 if TYPE_CHECKING:
10 from stripe._stripe_client import StripeClient
11 from stripe.v2.core._account import Account
12
13
14 class V2CoreAccountUpdatedEventNotification(EventNotification):
15 LOOKUP_TYPE = "v2.core.account.updated"
16 type: Literal["v2.core.account.updated"]
17 related_object: RelatedObject
18
19 def __init__(
20 self, parsed_body: Dict[str, Any], client: "StripeClient"
21 ) -> None:
22 super().__init__(
23 parsed_body,
24 client,
25 )
26 self.related_object = RelatedObject(parsed_body["related_object"])
27
28 @override
29 def fetch_event(self) -> "V2CoreAccountUpdatedEvent":
30 return cast(
31 "V2CoreAccountUpdatedEvent",
32 super().fetch_event(),
33 )
34
35 def fetch_related_object(self) -> "Account":
36 response = self._client.raw_request(
37 "get",
38 self.related_object.url,
39 stripe_context=self.context,
40 headers={"Stripe-Request-Trigger": f"event={self.id}"},
41 usage=["fetch_related_object"],
42 )
43 return cast(
44 "Account",
45 self._client.deserialize(
46 response,
47 api_mode=get_api_mode(self.related_object.url),
48 ),
49 )
50
51 @override
52 async def fetch_event_async(self) -> "V2CoreAccountUpdatedEvent":
53 return cast(
54 "V2CoreAccountUpdatedEvent",
55 await super().fetch_event_async(),
56 )
57
58 async def fetch_related_object_async(self) -> "Account":
59 response = await self._client.raw_request_async(
60 "get",
61 self.related_object.url,
62 stripe_context=self.context,
63 headers={"Stripe-Request-Trigger": f"event={self.id}"},
64 usage=["fetch_related_object"],
65 )
66 return cast(
67 "Account",
68 self._client.deserialize(
69 response,
70 api_mode=get_api_mode(self.related_object.url),
71 ),
72 )
73
74
75 class V2CoreAccountUpdatedEvent(Event):
76 LOOKUP_TYPE = "v2.core.account.updated"
77 type: Literal["v2.core.account.updated"]
78
79 class RelatedObject(StripeObject):
80 id: str
81 """
82 Unique identifier for the object relevant to the event.
83 """
84 type: str
85 """
86 Type of the object relevant to the event.
87 """
88 url: str
89 """
90 URL to retrieve the resource.
91 """
92
93 related_object: RelatedObject
94 """
95 Object containing the reference to API resource relevant to the event
96 """
97
98 def fetch_related_object(self) -> "Account":
99 """
100 Retrieves the related object from the API. Makes an API request on every call.
101 """
102 return cast(
103 "Account",
104 self._requestor.request(
105 "get",
106 self.related_object.url,
107 base_address="api",
108 options={
109 "stripe_context": self.context,
110 "headers": {"Stripe-Request-Trigger": f"event={self.id}"},
111 },
112 ),
113 )