Debian Codegraph @

stripe/billing/_alert.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._createable_api_resource import CreateableAPIResource
4 from stripe._expandable_field import ExpandableField
5 from stripe._list_object import ListObject
6 from stripe._listable_api_resource import ListableAPIResource
7 from stripe._stripe_object import StripeObject
8 from stripe._util import class_method_variant, sanitize_id
9 from typing import ClassVar, List, Optional, cast, overload
10 from typing_extensions import Literal, Unpack, TYPE_CHECKING
11
12 if TYPE_CHECKING:
13 from stripe._customer import Customer
14 from stripe.billing._meter import Meter
15 from stripe.params.billing._alert_activate_params import (
16 AlertActivateParams,
17 )
18 from stripe.params.billing._alert_archive_params import AlertArchiveParams
19 from stripe.params.billing._alert_create_params import AlertCreateParams
20 from stripe.params.billing._alert_deactivate_params import (
21 AlertDeactivateParams,
22 )
23 from stripe.params.billing._alert_list_params import AlertListParams
24 from stripe.params.billing._alert_retrieve_params import (
25 AlertRetrieveParams,
26 )
27
28
29 class Alert(CreateableAPIResource["Alert"], ListableAPIResource["Alert"]):
30 """
31 A billing alert is a resource that notifies you when a certain usage threshold on a meter is crossed. For example, you might create a billing alert to notify you when a certain user made 100 API requests.
32 """
33
34 OBJECT_NAME: ClassVar[Literal["billing.alert"]] = "billing.alert"
35
36 class UsageThreshold(StripeObject):
37 class Filter(StripeObject):
38 customer: Optional[ExpandableField["Customer"]]
39 """
40 Limit the scope of the alert to this customer ID
41 """
42 type: Literal["customer"]
43
44 filters: Optional[List[Filter]]
45 """
46 The filters allow limiting the scope of this usage alert. You can only specify up to one filter at this time.
47 """
48 gte: int
49 """
50 The value at which this alert will trigger.
51 """
52 meter: ExpandableField["Meter"]
53 """
54 The [Billing Meter](https://docs.stripe.com/api/billing/meter) ID whose usage is monitored.
55 """
56 recurrence: Literal["one_time"]
57 """
58 Defines how the alert will behave.
59 """
60 _inner_class_types = {"filters": Filter}
61
62 alert_type: Literal["usage_threshold"]
63 """
64 Defines the type of the alert.
65 """
66 id: str
67 """
68 Unique identifier for the object.
69 """
70 livemode: bool
71 """
72 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
73 """
74 object: Literal["billing.alert"]
75 """
76 String representing the object's type. Objects of the same type share the same value.
77 """
78 status: Optional[Literal["active", "archived", "inactive"]]
79 """
80 Status of the alert. This can be active, inactive or archived.
81 """
82 title: str
83 """
84 Title of the alert.
85 """
86 usage_threshold: Optional[UsageThreshold]
87 """
88 Encapsulates configuration of the alert to monitor usage on a specific [Billing Meter](https://docs.stripe.com/api/billing/meter).
89 """
90
91 @classmethod
92 def _cls_activate(
93 cls, id: str, **params: Unpack["AlertActivateParams"]
94 ) -> "Alert":
95 """
96 Reactivates this alert, allowing it to trigger again.
97 """
98 return cast(
99 "Alert",
100 cls._static_request(
101 "post",
102 "/v1/billing/alerts/{id}/activate".format(id=sanitize_id(id)),
103 params=params,
104 ),
105 )
106
107 @overload
108 @staticmethod
109 def activate(id: str, **params: Unpack["AlertActivateParams"]) -> "Alert":
110 """
111 Reactivates this alert, allowing it to trigger again.
112 """
113 ...
114
115 @overload
116 def activate(self, **params: Unpack["AlertActivateParams"]) -> "Alert":
117 """
118 Reactivates this alert, allowing it to trigger again.
119 """
120 ...
121
122 @class_method_variant("_cls_activate")
123 def activate( # pyright: ignore[reportGeneralTypeIssues]
124 self, **params: Unpack["AlertActivateParams"]
125 ) -> "Alert":
126 """
127 Reactivates this alert, allowing it to trigger again.
128 """
129 return cast(
130 "Alert",
131 self._request(
132 "post",
133 "/v1/billing/alerts/{id}/activate".format(
134 id=sanitize_id(self.get("id"))
135 ),
136 params=params,
137 ),
138 )
139
140 @classmethod
141 async def _cls_activate_async(
142 cls, id: str, **params: Unpack["AlertActivateParams"]
143 ) -> "Alert":
144 """
145 Reactivates this alert, allowing it to trigger again.
146 """
147 return cast(
148 "Alert",
149 await cls._static_request_async(
150 "post",
151 "/v1/billing/alerts/{id}/activate".format(id=sanitize_id(id)),
152 params=params,
153 ),
154 )
155
156 @overload
157 @staticmethod
158 async def activate_async(
159 id: str, **params: Unpack["AlertActivateParams"]
160 ) -> "Alert":
161 """
162 Reactivates this alert, allowing it to trigger again.
163 """
164 ...
165
166 @overload
167 async def activate_async(
168 self, **params: Unpack["AlertActivateParams"]
169 ) -> "Alert":
170 """
171 Reactivates this alert, allowing it to trigger again.
172 """
173 ...
174
175 @class_method_variant("_cls_activate_async")
176 async def activate_async( # pyright: ignore[reportGeneralTypeIssues]
177 self, **params: Unpack["AlertActivateParams"]
178 ) -> "Alert":
179 """
180 Reactivates this alert, allowing it to trigger again.
181 """
182 return cast(
183 "Alert",
184 await self._request_async(
185 "post",
186 "/v1/billing/alerts/{id}/activate".format(
187 id=sanitize_id(self.get("id"))
188 ),
189 params=params,
190 ),
191 )
192
193 @classmethod
194 def _cls_archive(
195 cls, id: str, **params: Unpack["AlertArchiveParams"]
196 ) -> "Alert":
197 """
198 Archives this alert, removing it from the list view and APIs. This is non-reversible.
199 """
200 return cast(
201 "Alert",
202 cls._static_request(
203 "post",
204 "/v1/billing/alerts/{id}/archive".format(id=sanitize_id(id)),
205 params=params,
206 ),
207 )
208
209 @overload
210 @staticmethod
211 def archive(id: str, **params: Unpack["AlertArchiveParams"]) -> "Alert":
212 """
213 Archives this alert, removing it from the list view and APIs. This is non-reversible.
214 """
215 ...
216
217 @overload
218 def archive(self, **params: Unpack["AlertArchiveParams"]) -> "Alert":
219 """
220 Archives this alert, removing it from the list view and APIs. This is non-reversible.
221 """
222 ...
223
224 @class_method_variant("_cls_archive")
225 def archive( # pyright: ignore[reportGeneralTypeIssues]
226 self, **params: Unpack["AlertArchiveParams"]
227 ) -> "Alert":
228 """
229 Archives this alert, removing it from the list view and APIs. This is non-reversible.
230 """
231 return cast(
232 "Alert",
233 self._request(
234 "post",
235 "/v1/billing/alerts/{id}/archive".format(
236 id=sanitize_id(self.get("id"))
237 ),
238 params=params,
239 ),
240 )
241
242 @classmethod
243 async def _cls_archive_async(
244 cls, id: str, **params: Unpack["AlertArchiveParams"]
245 ) -> "Alert":
246 """
247 Archives this alert, removing it from the list view and APIs. This is non-reversible.
248 """
249 return cast(
250 "Alert",
251 await cls._static_request_async(
252 "post",
253 "/v1/billing/alerts/{id}/archive".format(id=sanitize_id(id)),
254 params=params,
255 ),
256 )
257
258 @overload
259 @staticmethod
260 async def archive_async(
261 id: str, **params: Unpack["AlertArchiveParams"]
262 ) -> "Alert":
263 """
264 Archives this alert, removing it from the list view and APIs. This is non-reversible.
265 """
266 ...
267
268 @overload
269 async def archive_async(
270 self, **params: Unpack["AlertArchiveParams"]
271 ) -> "Alert":
272 """
273 Archives this alert, removing it from the list view and APIs. This is non-reversible.
274 """
275 ...
276
277 @class_method_variant("_cls_archive_async")
278 async def archive_async( # pyright: ignore[reportGeneralTypeIssues]
279 self, **params: Unpack["AlertArchiveParams"]
280 ) -> "Alert":
281 """
282 Archives this alert, removing it from the list view and APIs. This is non-reversible.
283 """
284 return cast(
285 "Alert",
286 await self._request_async(
287 "post",
288 "/v1/billing/alerts/{id}/archive".format(
289 id=sanitize_id(self.get("id"))
290 ),
291 params=params,
292 ),
293 )
294
295 @classmethod
296 def create(cls, **params: Unpack["AlertCreateParams"]) -> "Alert":
297 """
298 Creates a billing alert
299 """
300 return cast(
301 "Alert",
302 cls._static_request(
303 "post",
304 cls.class_url(),
305 params=params,
306 ),
307 )
308
309 @classmethod
310 async def create_async(
311 cls, **params: Unpack["AlertCreateParams"]
312 ) -> "Alert":
313 """
314 Creates a billing alert
315 """
316 return cast(
317 "Alert",
318 await cls._static_request_async(
319 "post",
320 cls.class_url(),
321 params=params,
322 ),
323 )
324
325 @classmethod
326 def _cls_deactivate(
327 cls, id: str, **params: Unpack["AlertDeactivateParams"]
328 ) -> "Alert":
329 """
330 Deactivates this alert, preventing it from triggering.
331 """
332 return cast(
333 "Alert",
334 cls._static_request(
335 "post",
336 "/v1/billing/alerts/{id}/deactivate".format(
337 id=sanitize_id(id)
338 ),
339 params=params,
340 ),
341 )
342
343 @overload
344 @staticmethod
345 def deactivate(
346 id: str, **params: Unpack["AlertDeactivateParams"]
347 ) -> "Alert":
348 """
349 Deactivates this alert, preventing it from triggering.
350 """
351 ...
352
353 @overload
354 def deactivate(self, **params: Unpack["AlertDeactivateParams"]) -> "Alert":
355 """
356 Deactivates this alert, preventing it from triggering.
357 """
358 ...
359
360 @class_method_variant("_cls_deactivate")
361 def deactivate( # pyright: ignore[reportGeneralTypeIssues]
362 self, **params: Unpack["AlertDeactivateParams"]
363 ) -> "Alert":
364 """
365 Deactivates this alert, preventing it from triggering.
366 """
367 return cast(
368 "Alert",
369 self._request(
370 "post",
371 "/v1/billing/alerts/{id}/deactivate".format(
372 id=sanitize_id(self.get("id"))
373 ),
374 params=params,
375 ),
376 )
377
378 @classmethod
379 async def _cls_deactivate_async(
380 cls, id: str, **params: Unpack["AlertDeactivateParams"]
381 ) -> "Alert":
382 """
383 Deactivates this alert, preventing it from triggering.
384 """
385 return cast(
386 "Alert",
387 await cls._static_request_async(
388 "post",
389 "/v1/billing/alerts/{id}/deactivate".format(
390 id=sanitize_id(id)
391 ),
392 params=params,
393 ),
394 )
395
396 @overload
397 @staticmethod
398 async def deactivate_async(
399 id: str, **params: Unpack["AlertDeactivateParams"]
400 ) -> "Alert":
401 """
402 Deactivates this alert, preventing it from triggering.
403 """
404 ...
405
406 @overload
407 async def deactivate_async(
408 self, **params: Unpack["AlertDeactivateParams"]
409 ) -> "Alert":
410 """
411 Deactivates this alert, preventing it from triggering.
412 """
413 ...
414
415 @class_method_variant("_cls_deactivate_async")
416 async def deactivate_async( # pyright: ignore[reportGeneralTypeIssues]
417 self, **params: Unpack["AlertDeactivateParams"]
418 ) -> "Alert":
419 """
420 Deactivates this alert, preventing it from triggering.
421 """
422 return cast(
423 "Alert",
424 await self._request_async(
425 "post",
426 "/v1/billing/alerts/{id}/deactivate".format(
427 id=sanitize_id(self.get("id"))
428 ),
429 params=params,
430 ),
431 )
432
433 @classmethod
434 def list(cls, **params: Unpack["AlertListParams"]) -> ListObject["Alert"]:
435 """
436 Lists billing active and inactive alerts
437 """
438 result = cls._static_request(
439 "get",
440 cls.class_url(),
441 params=params,
442 )
443 if not isinstance(result, ListObject):
444 raise TypeError(
445 "Expected list object from API, got %s"
446 % (type(result).__name__)
447 )
448
449 return result
450
451 @classmethod
452 async def list_async(
453 cls, **params: Unpack["AlertListParams"]
454 ) -> ListObject["Alert"]:
455 """
456 Lists billing active and inactive alerts
457 """
458 result = await cls._static_request_async(
459 "get",
460 cls.class_url(),
461 params=params,
462 )
463 if not isinstance(result, ListObject):
464 raise TypeError(
465 "Expected list object from API, got %s"
466 % (type(result).__name__)
467 )
468
469 return result
470
471 @classmethod
472 def retrieve(
473 cls, id: str, **params: Unpack["AlertRetrieveParams"]
474 ) -> "Alert":
475 """
476 Retrieves a billing alert given an ID
477 """
478 instance = cls(id, **params)
479 instance.refresh()
480 return instance
481
482 @classmethod
483 async def retrieve_async(
484 cls, id: str, **params: Unpack["AlertRetrieveParams"]
485 ) -> "Alert":
486 """
487 Retrieves a billing alert given an ID
488 """
489 instance = cls(id, **params)
490 await instance.refresh_async()
491 return instance
492
493 _inner_class_types = {"usage_threshold": UsageThreshold}