Debian Codegraph @

stripe/events/_v1_billing_meter_error_report_triggered_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, List, 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.billing._meter import Meter
15
16
17 class V1BillingMeterErrorReportTriggeredEventNotification(EventNotification):
18 LOOKUP_TYPE = "v1.billing.meter.error_report_triggered"
19 type: Literal["v1.billing.meter.error_report_triggered"]
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) -> "V1BillingMeterErrorReportTriggeredEvent":
33 return cast(
34 "V1BillingMeterErrorReportTriggeredEvent",
35 super().fetch_event(),
36 )
37
38 def fetch_related_object(self) -> "Meter":
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 "Meter",
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(
56 self,
57 ) -> "V1BillingMeterErrorReportTriggeredEvent":
58 return cast(
59 "V1BillingMeterErrorReportTriggeredEvent",
60 await super().fetch_event_async(),
61 )
62
63 async def fetch_related_object_async(self) -> "Meter":
64 response = await self._client.raw_request_async(
65 "get",
66 self.related_object.url,
67 stripe_context=self.context,
68 headers={"Stripe-Request-Trigger": f"event={self.id}"},
69 usage=["fetch_related_object"],
70 )
71 return cast(
72 "Meter",
73 self._client.deserialize(
74 response,
75 api_mode=get_api_mode(self.related_object.url),
76 ),
77 )
78
79
80 class V1BillingMeterErrorReportTriggeredEvent(Event):
81 LOOKUP_TYPE = "v1.billing.meter.error_report_triggered"
82 type: Literal["v1.billing.meter.error_report_triggered"]
83
84 class V1BillingMeterErrorReportTriggeredEventData(StripeObject):
85 class Reason(StripeObject):
86 class ErrorType(StripeObject):
87 class SampleError(StripeObject):
88 class Request(StripeObject):
89 identifier: str
90 """
91 The request idempotency key.
92 """
93
94 error_message: str
95 """
96 The error message.
97 """
98 request: Request
99 """
100 The request causes the error.
101 """
102 _inner_class_types = {"request": Request}
103
104 code: Literal[
105 "archived_meter",
106 "meter_event_customer_not_found",
107 "meter_event_dimension_count_too_high",
108 "meter_event_invalid_value",
109 "meter_event_no_customer_defined",
110 "missing_dimension_payload_keys",
111 "no_meter",
112 "timestamp_in_future",
113 "timestamp_too_far_in_past",
114 ]
115 """
116 Open Enum.
117 """
118 error_count: int
119 """
120 The number of errors of this type.
121 """
122 sample_errors: List[SampleError]
123 """
124 A list of sample errors of this type.
125 """
126 _inner_class_types = {"sample_errors": SampleError}
127
128 error_count: int
129 """
130 The total error count within this window.
131 """
132 error_types: List[ErrorType]
133 """
134 The error details.
135 """
136 _inner_class_types = {"error_types": ErrorType}
137
138 developer_message_summary: str
139 """
140 Extra field included in the event's `data` when fetched from /v2/events.
141 """
142 reason: Reason
143 """
144 This contains information about why meter error happens.
145 """
146 validation_end: str
147 """
148 The end of the window that is encapsulated by this summary.
149 """
150 validation_start: str
151 """
152 The start of the window that is encapsulated by this summary.
153 """
154 _inner_class_types = {"reason": Reason}
155
156 data: V1BillingMeterErrorReportTriggeredEventData
157 """
158 Data for the v1.billing.meter.error_report_triggered event
159 """
160
161 @classmethod
162 def _construct_from(
163 cls,
164 *,
165 values: Dict[str, Any],
166 last_response: Optional[StripeResponse] = None,
167 requestor: "_APIRequestor",
168 api_mode: ApiMode,
169 ) -> "V1BillingMeterErrorReportTriggeredEvent":
170 evt = super()._construct_from(
171 values=values,
172 last_response=last_response,
173 requestor=requestor,
174 api_mode=api_mode,
175 )
176 if hasattr(evt, "data"):
177 evt.data = V1BillingMeterErrorReportTriggeredEvent.V1BillingMeterErrorReportTriggeredEventData._construct_from(
178 values=evt.data,
179 last_response=last_response,
180 requestor=requestor,
181 api_mode=api_mode,
182 )
183 return evt
184
185 class RelatedObject(StripeObject):
186 id: str
187 """
188 Unique identifier for the object relevant to the event.
189 """
190 type: str
191 """
192 Type of the object relevant to the event.
193 """
194 url: str
195 """
196 URL to retrieve the resource.
197 """
198
199 related_object: RelatedObject
200 """
201 Object containing the reference to API resource relevant to the event
202 """
203
204 def fetch_related_object(self) -> "Meter":
205 """
206 Retrieves the related object from the API. Makes an API request on every call.
207 """
208 return cast(
209 "Meter",
210 self._requestor.request(
211 "get",
212 self.related_object.url,
213 base_address="api",
214 options={
215 "stripe_context": self.context,
216 "headers": {"Stripe-Request-Trigger": f"event={self.id}"},
217 },
218 ),
219 )