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,96 @@
# -*- 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.billing._alert import Alert as Alert
from stripe.billing._alert_service import AlertService as AlertService
from stripe.billing._alert_triggered import (
AlertTriggered as AlertTriggered,
)
from stripe.billing._credit_balance_summary import (
CreditBalanceSummary as CreditBalanceSummary,
)
from stripe.billing._credit_balance_summary_service import (
CreditBalanceSummaryService as CreditBalanceSummaryService,
)
from stripe.billing._credit_balance_transaction import (
CreditBalanceTransaction as CreditBalanceTransaction,
)
from stripe.billing._credit_balance_transaction_service import (
CreditBalanceTransactionService as CreditBalanceTransactionService,
)
from stripe.billing._credit_grant import CreditGrant as CreditGrant
from stripe.billing._credit_grant_service import (
CreditGrantService as CreditGrantService,
)
from stripe.billing._meter import Meter as Meter
from stripe.billing._meter_event import MeterEvent as MeterEvent
from stripe.billing._meter_event_adjustment import (
MeterEventAdjustment as MeterEventAdjustment,
)
from stripe.billing._meter_event_adjustment_service import (
MeterEventAdjustmentService as MeterEventAdjustmentService,
)
from stripe.billing._meter_event_service import (
MeterEventService as MeterEventService,
)
from stripe.billing._meter_event_summary import (
MeterEventSummary as MeterEventSummary,
)
from stripe.billing._meter_event_summary_service import (
MeterEventSummaryService as MeterEventSummaryService,
)
from stripe.billing._meter_service import MeterService as MeterService
# name -> (import_target, is_submodule)
_import_map = {
"Alert": ("stripe.billing._alert", False),
"AlertService": ("stripe.billing._alert_service", False),
"AlertTriggered": ("stripe.billing._alert_triggered", False),
"CreditBalanceSummary": ("stripe.billing._credit_balance_summary", False),
"CreditBalanceSummaryService": (
"stripe.billing._credit_balance_summary_service",
False,
),
"CreditBalanceTransaction": (
"stripe.billing._credit_balance_transaction",
False,
),
"CreditBalanceTransactionService": (
"stripe.billing._credit_balance_transaction_service",
False,
),
"CreditGrant": ("stripe.billing._credit_grant", False),
"CreditGrantService": ("stripe.billing._credit_grant_service", False),
"Meter": ("stripe.billing._meter", False),
"MeterEvent": ("stripe.billing._meter_event", False),
"MeterEventAdjustment": ("stripe.billing._meter_event_adjustment", False),
"MeterEventAdjustmentService": (
"stripe.billing._meter_event_adjustment_service",
False,
),
"MeterEventService": ("stripe.billing._meter_event_service", False),
"MeterEventSummary": ("stripe.billing._meter_event_summary", False),
"MeterEventSummaryService": (
"stripe.billing._meter_event_summary_service",
False,
),
"MeterService": ("stripe.billing._meter_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,493 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from stripe._expandable_field import ExpandableField
from stripe._list_object import ListObject
from stripe._listable_api_resource import ListableAPIResource
from stripe._stripe_object import StripeObject
from stripe._util import class_method_variant, sanitize_id
from typing import ClassVar, List, Optional, cast, overload
from typing_extensions import Literal, Unpack, TYPE_CHECKING
if TYPE_CHECKING:
from stripe._customer import Customer
from stripe.billing._meter import Meter
from stripe.params.billing._alert_activate_params import (
AlertActivateParams,
)
from stripe.params.billing._alert_archive_params import AlertArchiveParams
from stripe.params.billing._alert_create_params import AlertCreateParams
from stripe.params.billing._alert_deactivate_params import (
AlertDeactivateParams,
)
from stripe.params.billing._alert_list_params import AlertListParams
from stripe.params.billing._alert_retrieve_params import (
AlertRetrieveParams,
)
class Alert(CreateableAPIResource["Alert"], ListableAPIResource["Alert"]):
"""
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.
"""
OBJECT_NAME: ClassVar[Literal["billing.alert"]] = "billing.alert"
class UsageThreshold(StripeObject):
class Filter(StripeObject):
customer: Optional[ExpandableField["Customer"]]
"""
Limit the scope of the alert to this customer ID
"""
type: Literal["customer"]
filters: Optional[List[Filter]]
"""
The filters allow limiting the scope of this usage alert. You can only specify up to one filter at this time.
"""
gte: int
"""
The value at which this alert will trigger.
"""
meter: ExpandableField["Meter"]
"""
The [Billing Meter](https://docs.stripe.com/api/billing/meter) ID whose usage is monitored.
"""
recurrence: Literal["one_time"]
"""
Defines how the alert will behave.
"""
_inner_class_types = {"filters": Filter}
alert_type: Literal["usage_threshold"]
"""
Defines the type of the alert.
"""
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.
"""
object: Literal["billing.alert"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
status: Optional[Literal["active", "archived", "inactive"]]
"""
Status of the alert. This can be active, inactive or archived.
"""
title: str
"""
Title of the alert.
"""
usage_threshold: Optional[UsageThreshold]
"""
Encapsulates configuration of the alert to monitor usage on a specific [Billing Meter](https://stripe.com/docs/api/billing/meter).
"""
@classmethod
def _cls_activate(
cls, id: str, **params: Unpack["AlertActivateParams"]
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
return cast(
"Alert",
cls._static_request(
"post",
"/v1/billing/alerts/{id}/activate".format(id=sanitize_id(id)),
params=params,
),
)
@overload
@staticmethod
def activate(id: str, **params: Unpack["AlertActivateParams"]) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
...
@overload
def activate(self, **params: Unpack["AlertActivateParams"]) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
...
@class_method_variant("_cls_activate")
def activate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["AlertActivateParams"]
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
return cast(
"Alert",
self._request(
"post",
"/v1/billing/alerts/{id}/activate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_activate_async(
cls, id: str, **params: Unpack["AlertActivateParams"]
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
return cast(
"Alert",
await cls._static_request_async(
"post",
"/v1/billing/alerts/{id}/activate".format(id=sanitize_id(id)),
params=params,
),
)
@overload
@staticmethod
async def activate_async(
id: str, **params: Unpack["AlertActivateParams"]
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
...
@overload
async def activate_async(
self, **params: Unpack["AlertActivateParams"]
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
...
@class_method_variant("_cls_activate_async")
async def activate_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["AlertActivateParams"]
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
return cast(
"Alert",
await self._request_async(
"post",
"/v1/billing/alerts/{id}/activate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
def _cls_archive(
cls, id: str, **params: Unpack["AlertArchiveParams"]
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
return cast(
"Alert",
cls._static_request(
"post",
"/v1/billing/alerts/{id}/archive".format(id=sanitize_id(id)),
params=params,
),
)
@overload
@staticmethod
def archive(id: str, **params: Unpack["AlertArchiveParams"]) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
...
@overload
def archive(self, **params: Unpack["AlertArchiveParams"]) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
...
@class_method_variant("_cls_archive")
def archive( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["AlertArchiveParams"]
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
return cast(
"Alert",
self._request(
"post",
"/v1/billing/alerts/{id}/archive".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_archive_async(
cls, id: str, **params: Unpack["AlertArchiveParams"]
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
return cast(
"Alert",
await cls._static_request_async(
"post",
"/v1/billing/alerts/{id}/archive".format(id=sanitize_id(id)),
params=params,
),
)
@overload
@staticmethod
async def archive_async(
id: str, **params: Unpack["AlertArchiveParams"]
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
...
@overload
async def archive_async(
self, **params: Unpack["AlertArchiveParams"]
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
...
@class_method_variant("_cls_archive_async")
async def archive_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["AlertArchiveParams"]
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
return cast(
"Alert",
await self._request_async(
"post",
"/v1/billing/alerts/{id}/archive".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
def create(cls, **params: Unpack["AlertCreateParams"]) -> "Alert":
"""
Creates a billing alert
"""
return cast(
"Alert",
cls._static_request(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
async def create_async(
cls, **params: Unpack["AlertCreateParams"]
) -> "Alert":
"""
Creates a billing alert
"""
return cast(
"Alert",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
def _cls_deactivate(
cls, id: str, **params: Unpack["AlertDeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
return cast(
"Alert",
cls._static_request(
"post",
"/v1/billing/alerts/{id}/deactivate".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
def deactivate(
id: str, **params: Unpack["AlertDeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@overload
def deactivate(self, **params: Unpack["AlertDeactivateParams"]) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@class_method_variant("_cls_deactivate")
def deactivate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["AlertDeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
return cast(
"Alert",
self._request(
"post",
"/v1/billing/alerts/{id}/deactivate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_deactivate_async(
cls, id: str, **params: Unpack["AlertDeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
return cast(
"Alert",
await cls._static_request_async(
"post",
"/v1/billing/alerts/{id}/deactivate".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
async def deactivate_async(
id: str, **params: Unpack["AlertDeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@overload
async def deactivate_async(
self, **params: Unpack["AlertDeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@class_method_variant("_cls_deactivate_async")
async def deactivate_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["AlertDeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
return cast(
"Alert",
await self._request_async(
"post",
"/v1/billing/alerts/{id}/deactivate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
def list(cls, **params: Unpack["AlertListParams"]) -> ListObject["Alert"]:
"""
Lists billing active and inactive alerts
"""
result = cls._static_request(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
async def list_async(
cls, **params: Unpack["AlertListParams"]
) -> ListObject["Alert"]:
"""
Lists billing active and inactive alerts
"""
result = await cls._static_request_async(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
def retrieve(
cls, id: str, **params: Unpack["AlertRetrieveParams"]
) -> "Alert":
"""
Retrieves a billing alert given an ID
"""
instance = cls(id, **params)
instance.refresh()
return instance
@classmethod
async def retrieve_async(
cls, id: str, **params: Unpack["AlertRetrieveParams"]
) -> "Alert":
"""
Retrieves a billing alert given an ID
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance
_inner_class_types = {"usage_threshold": UsageThreshold}

View File

@@ -0,0 +1,265 @@
# -*- 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._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe.billing._alert import Alert
from stripe.params.billing._alert_activate_params import (
AlertActivateParams,
)
from stripe.params.billing._alert_archive_params import AlertArchiveParams
from stripe.params.billing._alert_create_params import AlertCreateParams
from stripe.params.billing._alert_deactivate_params import (
AlertDeactivateParams,
)
from stripe.params.billing._alert_list_params import AlertListParams
from stripe.params.billing._alert_retrieve_params import (
AlertRetrieveParams,
)
class AlertService(StripeService):
def list(
self,
params: Optional["AlertListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[Alert]":
"""
Lists billing active and inactive alerts
"""
return cast(
"ListObject[Alert]",
self._request(
"get",
"/v1/billing/alerts",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: Optional["AlertListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[Alert]":
"""
Lists billing active and inactive alerts
"""
return cast(
"ListObject[Alert]",
await self._request_async(
"get",
"/v1/billing/alerts",
base_address="api",
params=params,
options=options,
),
)
def create(
self,
params: "AlertCreateParams",
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Creates a billing alert
"""
return cast(
"Alert",
self._request(
"post",
"/v1/billing/alerts",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "AlertCreateParams",
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Creates a billing alert
"""
return cast(
"Alert",
await self._request_async(
"post",
"/v1/billing/alerts",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: Optional["AlertRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Retrieves a billing alert given an ID
"""
return cast(
"Alert",
self._request(
"get",
"/v1/billing/alerts/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: Optional["AlertRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Retrieves a billing alert given an ID
"""
return cast(
"Alert",
await self._request_async(
"get",
"/v1/billing/alerts/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def activate(
self,
id: str,
params: Optional["AlertActivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
return cast(
"Alert",
self._request(
"post",
"/v1/billing/alerts/{id}/activate".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def activate_async(
self,
id: str,
params: Optional["AlertActivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
return cast(
"Alert",
await self._request_async(
"post",
"/v1/billing/alerts/{id}/activate".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def archive(
self,
id: str,
params: Optional["AlertArchiveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
return cast(
"Alert",
self._request(
"post",
"/v1/billing/alerts/{id}/archive".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def archive_async(
self,
id: str,
params: Optional["AlertArchiveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
return cast(
"Alert",
await self._request_async(
"post",
"/v1/billing/alerts/{id}/archive".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def deactivate(
self,
id: str,
params: Optional["AlertDeactivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
return cast(
"Alert",
self._request(
"post",
"/v1/billing/alerts/{id}/deactivate".format(
id=sanitize_id(id)
),
base_address="api",
params=params,
options=options,
),
)
async def deactivate_async(
self,
id: str,
params: Optional["AlertDeactivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
return cast(
"Alert",
await self._request_async(
"post",
"/v1/billing/alerts/{id}/deactivate".format(
id=sanitize_id(id)
),
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._stripe_object import StripeObject
from typing import ClassVar
from typing_extensions import Literal, TYPE_CHECKING
if TYPE_CHECKING:
from stripe.billing._alert import Alert
class AlertTriggered(StripeObject):
OBJECT_NAME: ClassVar[Literal["billing.alert_triggered"]] = (
"billing.alert_triggered"
)
alert: "Alert"
"""
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.
"""
created: int
"""
Time at which the object was created. Measured in seconds since the Unix epoch.
"""
customer: str
"""
ID of customer for which the alert triggered
"""
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["billing.alert_triggered"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
value: int
"""
The value triggering the alert
"""

View File

@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._expandable_field import ExpandableField
from stripe._singleton_api_resource import SingletonAPIResource
from stripe._stripe_object import StripeObject
from typing import ClassVar, List, Optional
from typing_extensions import Literal, Unpack, TYPE_CHECKING
if TYPE_CHECKING:
from stripe._customer import Customer
from stripe.params.billing._credit_balance_summary_retrieve_params import (
CreditBalanceSummaryRetrieveParams,
)
class CreditBalanceSummary(SingletonAPIResource["CreditBalanceSummary"]):
"""
Indicates the billing credit balance for billing credits granted to a customer.
"""
OBJECT_NAME: ClassVar[Literal["billing.credit_balance_summary"]] = (
"billing.credit_balance_summary"
)
class Balance(StripeObject):
class AvailableBalance(StripeObject):
class Monetary(StripeObject):
currency: str
"""
Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
"""
value: int
"""
A positive integer representing the amount.
"""
monetary: Optional[Monetary]
"""
The monetary amount.
"""
type: Literal["monetary"]
"""
The type of this amount. We currently only support `monetary` billing credits.
"""
_inner_class_types = {"monetary": Monetary}
class LedgerBalance(StripeObject):
class Monetary(StripeObject):
currency: str
"""
Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
"""
value: int
"""
A positive integer representing the amount.
"""
monetary: Optional[Monetary]
"""
The monetary amount.
"""
type: Literal["monetary"]
"""
The type of this amount. We currently only support `monetary` billing credits.
"""
_inner_class_types = {"monetary": Monetary}
available_balance: AvailableBalance
ledger_balance: LedgerBalance
_inner_class_types = {
"available_balance": AvailableBalance,
"ledger_balance": LedgerBalance,
}
balances: List[Balance]
"""
The billing credit balances. One entry per credit grant currency. If a customer only has credit grants in a single currency, then this will have a single balance entry.
"""
customer: ExpandableField["Customer"]
"""
The customer the balance is for.
"""
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["billing.credit_balance_summary"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
@classmethod
def retrieve(
cls, **params: Unpack["CreditBalanceSummaryRetrieveParams"]
) -> "CreditBalanceSummary":
"""
Retrieves the credit balance summary for a customer.
"""
instance = cls(None, **params)
instance.refresh()
return instance
@classmethod
async def retrieve_async(
cls, **params: Unpack["CreditBalanceSummaryRetrieveParams"]
) -> "CreditBalanceSummary":
"""
Retrieves the credit balance summary for a customer.
"""
instance = cls(None, **params)
await instance.refresh_async()
return instance
@classmethod
def class_url(cls):
return "/v1/billing/credit_balance_summary"
_inner_class_types = {"balances": Balance}

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.billing._credit_balance_summary import CreditBalanceSummary
from stripe.params.billing._credit_balance_summary_retrieve_params import (
CreditBalanceSummaryRetrieveParams,
)
class CreditBalanceSummaryService(StripeService):
def retrieve(
self,
params: "CreditBalanceSummaryRetrieveParams",
options: Optional["RequestOptions"] = None,
) -> "CreditBalanceSummary":
"""
Retrieves the credit balance summary for a customer.
"""
return cast(
"CreditBalanceSummary",
self._request(
"get",
"/v1/billing/credit_balance_summary",
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
params: "CreditBalanceSummaryRetrieveParams",
options: Optional["RequestOptions"] = None,
) -> "CreditBalanceSummary":
"""
Retrieves the credit balance summary for a customer.
"""
return cast(
"CreditBalanceSummary",
await self._request_async(
"get",
"/v1/billing/credit_balance_summary",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,234 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._expandable_field import ExpandableField
from stripe._list_object import ListObject
from stripe._listable_api_resource import ListableAPIResource
from stripe._stripe_object import StripeObject
from typing import ClassVar, Optional
from typing_extensions import Literal, Unpack, TYPE_CHECKING
if TYPE_CHECKING:
from stripe._invoice import Invoice
from stripe.billing._credit_grant import CreditGrant
from stripe.params.billing._credit_balance_transaction_list_params import (
CreditBalanceTransactionListParams,
)
from stripe.params.billing._credit_balance_transaction_retrieve_params import (
CreditBalanceTransactionRetrieveParams,
)
from stripe.test_helpers._test_clock import TestClock
class CreditBalanceTransaction(
ListableAPIResource["CreditBalanceTransaction"]
):
"""
A credit balance transaction is a resource representing a transaction (either a credit or a debit) against an existing credit grant.
"""
OBJECT_NAME: ClassVar[Literal["billing.credit_balance_transaction"]] = (
"billing.credit_balance_transaction"
)
class Credit(StripeObject):
class Amount(StripeObject):
class Monetary(StripeObject):
currency: str
"""
Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
"""
value: int
"""
A positive integer representing the amount.
"""
monetary: Optional[Monetary]
"""
The monetary amount.
"""
type: Literal["monetary"]
"""
The type of this amount. We currently only support `monetary` billing credits.
"""
_inner_class_types = {"monetary": Monetary}
class CreditsApplicationInvoiceVoided(StripeObject):
invoice: ExpandableField["Invoice"]
"""
The invoice to which the reinstated billing credits were originally applied.
"""
invoice_line_item: str
"""
The invoice line item to which the reinstated billing credits were originally applied.
"""
amount: Amount
credits_application_invoice_voided: Optional[
CreditsApplicationInvoiceVoided
]
"""
Details of the invoice to which the reinstated credits were originally applied. Only present if `type` is `credits_application_invoice_voided`.
"""
type: Literal["credits_application_invoice_voided", "credits_granted"]
"""
The type of credit transaction.
"""
_inner_class_types = {
"amount": Amount,
"credits_application_invoice_voided": CreditsApplicationInvoiceVoided,
}
class Debit(StripeObject):
class Amount(StripeObject):
class Monetary(StripeObject):
currency: str
"""
Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
"""
value: int
"""
A positive integer representing the amount.
"""
monetary: Optional[Monetary]
"""
The monetary amount.
"""
type: Literal["monetary"]
"""
The type of this amount. We currently only support `monetary` billing credits.
"""
_inner_class_types = {"monetary": Monetary}
class CreditsApplied(StripeObject):
invoice: ExpandableField["Invoice"]
"""
The invoice to which the billing credits were applied.
"""
invoice_line_item: str
"""
The invoice line item to which the billing credits were applied.
"""
amount: Amount
credits_applied: Optional[CreditsApplied]
"""
Details of how the billing credits were applied to an invoice. Only present if `type` is `credits_applied`.
"""
type: Literal["credits_applied", "credits_expired", "credits_voided"]
"""
The type of debit transaction.
"""
_inner_class_types = {
"amount": Amount,
"credits_applied": CreditsApplied,
}
created: int
"""
Time at which the object was created. Measured in seconds since the Unix epoch.
"""
credit: Optional[Credit]
"""
Credit details for this credit balance transaction. Only present if type is `credit`.
"""
credit_grant: ExpandableField["CreditGrant"]
"""
The credit grant associated with this credit balance transaction.
"""
debit: Optional[Debit]
"""
Debit details for this credit balance transaction. Only present if type is `debit`.
"""
effective_at: int
"""
The effective time of this credit balance transaction.
"""
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.
"""
object: Literal["billing.credit_balance_transaction"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
test_clock: Optional[ExpandableField["TestClock"]]
"""
ID of the test clock this credit balance transaction belongs to.
"""
type: Optional[Literal["credit", "debit"]]
"""
The type of credit balance transaction (credit or debit).
"""
@classmethod
def list(
cls, **params: Unpack["CreditBalanceTransactionListParams"]
) -> ListObject["CreditBalanceTransaction"]:
"""
Retrieve a list of credit balance transactions.
"""
result = cls._static_request(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
async def list_async(
cls, **params: Unpack["CreditBalanceTransactionListParams"]
) -> ListObject["CreditBalanceTransaction"]:
"""
Retrieve a list of credit balance transactions.
"""
result = await cls._static_request_async(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
def retrieve(
cls,
id: str,
**params: Unpack["CreditBalanceTransactionRetrieveParams"],
) -> "CreditBalanceTransaction":
"""
Retrieves a credit balance transaction.
"""
instance = cls(id, **params)
instance.refresh()
return instance
@classmethod
async def retrieve_async(
cls,
id: str,
**params: Unpack["CreditBalanceTransactionRetrieveParams"],
) -> "CreditBalanceTransaction":
"""
Retrieves a credit balance transaction.
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance
_inner_class_types = {"credit": Credit, "debit": Debit}

View File

@@ -0,0 +1,103 @@
# -*- 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._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe.billing._credit_balance_transaction import (
CreditBalanceTransaction,
)
from stripe.params.billing._credit_balance_transaction_list_params import (
CreditBalanceTransactionListParams,
)
from stripe.params.billing._credit_balance_transaction_retrieve_params import (
CreditBalanceTransactionRetrieveParams,
)
class CreditBalanceTransactionService(StripeService):
def list(
self,
params: "CreditBalanceTransactionListParams",
options: Optional["RequestOptions"] = None,
) -> "ListObject[CreditBalanceTransaction]":
"""
Retrieve a list of credit balance transactions.
"""
return cast(
"ListObject[CreditBalanceTransaction]",
self._request(
"get",
"/v1/billing/credit_balance_transactions",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: "CreditBalanceTransactionListParams",
options: Optional["RequestOptions"] = None,
) -> "ListObject[CreditBalanceTransaction]":
"""
Retrieve a list of credit balance transactions.
"""
return cast(
"ListObject[CreditBalanceTransaction]",
await self._request_async(
"get",
"/v1/billing/credit_balance_transactions",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: Optional["CreditBalanceTransactionRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditBalanceTransaction":
"""
Retrieves a credit balance transaction.
"""
return cast(
"CreditBalanceTransaction",
self._request(
"get",
"/v1/billing/credit_balance_transactions/{id}".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: Optional["CreditBalanceTransactionRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditBalanceTransaction":
"""
Retrieves a credit balance transaction.
"""
return cast(
"CreditBalanceTransaction",
await self._request_async(
"get",
"/v1/billing/credit_balance_transactions/{id}".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,503 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from stripe._expandable_field import ExpandableField
from stripe._list_object import ListObject
from stripe._listable_api_resource import ListableAPIResource
from stripe._stripe_object import StripeObject
from stripe._updateable_api_resource import UpdateableAPIResource
from stripe._util import class_method_variant, sanitize_id
from typing import ClassVar, Dict, List, Optional, cast, overload
from typing_extensions import Literal, Unpack, TYPE_CHECKING
if TYPE_CHECKING:
from stripe._customer import Customer
from stripe.params.billing._credit_grant_create_params import (
CreditGrantCreateParams,
)
from stripe.params.billing._credit_grant_expire_params import (
CreditGrantExpireParams,
)
from stripe.params.billing._credit_grant_list_params import (
CreditGrantListParams,
)
from stripe.params.billing._credit_grant_modify_params import (
CreditGrantModifyParams,
)
from stripe.params.billing._credit_grant_retrieve_params import (
CreditGrantRetrieveParams,
)
from stripe.params.billing._credit_grant_void_grant_params import (
CreditGrantVoidGrantParams,
)
from stripe.test_helpers._test_clock import TestClock
class CreditGrant(
CreateableAPIResource["CreditGrant"],
ListableAPIResource["CreditGrant"],
UpdateableAPIResource["CreditGrant"],
):
"""
A credit grant is an API resource that documents the allocation of some billing credits to a customer.
Related guide: [Billing credits](https://docs.stripe.com/billing/subscriptions/usage-based/billing-credits)
"""
OBJECT_NAME: ClassVar[Literal["billing.credit_grant"]] = (
"billing.credit_grant"
)
class Amount(StripeObject):
class Monetary(StripeObject):
currency: str
"""
Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
"""
value: int
"""
A positive integer representing the amount.
"""
monetary: Optional[Monetary]
"""
The monetary amount.
"""
type: Literal["monetary"]
"""
The type of this amount. We currently only support `monetary` billing credits.
"""
_inner_class_types = {"monetary": Monetary}
class ApplicabilityConfig(StripeObject):
class Scope(StripeObject):
class Price(StripeObject):
id: Optional[str]
"""
Unique identifier for the object.
"""
price_type: Optional[Literal["metered"]]
"""
The price type that credit grants can apply to. We currently only support the `metered` price type. This refers to prices that have a [Billing Meter](https://docs.stripe.com/api/billing/meter) attached to them. Cannot be used in combination with `prices`.
"""
prices: Optional[List[Price]]
"""
The prices that credit grants can apply to. We currently only support `metered` prices. This refers to prices that have a [Billing Meter](https://docs.stripe.com/api/billing/meter) attached to them. Cannot be used in combination with `price_type`.
"""
_inner_class_types = {"prices": Price}
scope: Scope
_inner_class_types = {"scope": Scope}
amount: Amount
applicability_config: ApplicabilityConfig
category: Literal["paid", "promotional"]
"""
The category of this credit grant. This is for tracking purposes and isn't displayed to the customer.
"""
created: int
"""
Time at which the object was created. Measured in seconds since the Unix epoch.
"""
customer: ExpandableField["Customer"]
"""
ID of the customer receiving the billing credits.
"""
effective_at: Optional[int]
"""
The time when the billing credits become effective-when they're eligible for use.
"""
expires_at: Optional[int]
"""
The time when the billing credits expire. If not present, the billing credits don't expire.
"""
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: Dict[str, str]
"""
Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
"""
name: Optional[str]
"""
A descriptive name shown in dashboard.
"""
object: Literal["billing.credit_grant"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
priority: Optional[int]
"""
The priority for applying this credit grant. The highest priority is 0 and the lowest is 100.
"""
test_clock: Optional[ExpandableField["TestClock"]]
"""
ID of the test clock this credit grant belongs to.
"""
updated: int
"""
Time at which the object was last updated. Measured in seconds since the Unix epoch.
"""
voided_at: Optional[int]
"""
The time when this credit grant was voided. If not present, the credit grant hasn't been voided.
"""
@classmethod
def create(
cls, **params: Unpack["CreditGrantCreateParams"]
) -> "CreditGrant":
"""
Creates a credit grant.
"""
return cast(
"CreditGrant",
cls._static_request(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
async def create_async(
cls, **params: Unpack["CreditGrantCreateParams"]
) -> "CreditGrant":
"""
Creates a credit grant.
"""
return cast(
"CreditGrant",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
def _cls_expire(
cls, id: str, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
return cast(
"CreditGrant",
cls._static_request(
"post",
"/v1/billing/credit_grants/{id}/expire".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
def expire(
id: str, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
...
@overload
def expire(
self, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
...
@class_method_variant("_cls_expire")
def expire( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
return cast(
"CreditGrant",
self._request(
"post",
"/v1/billing/credit_grants/{id}/expire".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_expire_async(
cls, id: str, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
return cast(
"CreditGrant",
await cls._static_request_async(
"post",
"/v1/billing/credit_grants/{id}/expire".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
async def expire_async(
id: str, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
...
@overload
async def expire_async(
self, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
...
@class_method_variant("_cls_expire_async")
async def expire_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["CreditGrantExpireParams"]
) -> "CreditGrant":
"""
Expires a credit grant.
"""
return cast(
"CreditGrant",
await self._request_async(
"post",
"/v1/billing/credit_grants/{id}/expire".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
def list(
cls, **params: Unpack["CreditGrantListParams"]
) -> ListObject["CreditGrant"]:
"""
Retrieve a list of credit grants.
"""
result = cls._static_request(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
async def list_async(
cls, **params: Unpack["CreditGrantListParams"]
) -> ListObject["CreditGrant"]:
"""
Retrieve a list of credit grants.
"""
result = await cls._static_request_async(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
def modify(
cls, id: str, **params: Unpack["CreditGrantModifyParams"]
) -> "CreditGrant":
"""
Updates a credit grant.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(id))
return cast(
"CreditGrant",
cls._static_request(
"post",
url,
params=params,
),
)
@classmethod
async def modify_async(
cls, id: str, **params: Unpack["CreditGrantModifyParams"]
) -> "CreditGrant":
"""
Updates a credit grant.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(id))
return cast(
"CreditGrant",
await cls._static_request_async(
"post",
url,
params=params,
),
)
@classmethod
def retrieve(
cls, id: str, **params: Unpack["CreditGrantRetrieveParams"]
) -> "CreditGrant":
"""
Retrieves a credit grant.
"""
instance = cls(id, **params)
instance.refresh()
return instance
@classmethod
async def retrieve_async(
cls, id: str, **params: Unpack["CreditGrantRetrieveParams"]
) -> "CreditGrant":
"""
Retrieves a credit grant.
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance
@classmethod
def _cls_void_grant(
cls, id: str, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
return cast(
"CreditGrant",
cls._static_request(
"post",
"/v1/billing/credit_grants/{id}/void".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
def void_grant(
id: str, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
...
@overload
def void_grant(
self, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
...
@class_method_variant("_cls_void_grant")
def void_grant( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
return cast(
"CreditGrant",
self._request(
"post",
"/v1/billing/credit_grants/{id}/void".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_void_grant_async(
cls, id: str, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
return cast(
"CreditGrant",
await cls._static_request_async(
"post",
"/v1/billing/credit_grants/{id}/void".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
async def void_grant_async(
id: str, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
...
@overload
async def void_grant_async(
self, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
...
@class_method_variant("_cls_void_grant_async")
async def void_grant_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["CreditGrantVoidGrantParams"]
) -> "CreditGrant":
"""
Voids a credit grant.
"""
return cast(
"CreditGrant",
await self._request_async(
"post",
"/v1/billing/credit_grants/{id}/void".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
_inner_class_types = {
"amount": Amount,
"applicability_config": ApplicabilityConfig,
}

View File

@@ -0,0 +1,275 @@
# -*- 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._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe.billing._credit_grant import CreditGrant
from stripe.params.billing._credit_grant_create_params import (
CreditGrantCreateParams,
)
from stripe.params.billing._credit_grant_expire_params import (
CreditGrantExpireParams,
)
from stripe.params.billing._credit_grant_list_params import (
CreditGrantListParams,
)
from stripe.params.billing._credit_grant_retrieve_params import (
CreditGrantRetrieveParams,
)
from stripe.params.billing._credit_grant_update_params import (
CreditGrantUpdateParams,
)
from stripe.params.billing._credit_grant_void_grant_params import (
CreditGrantVoidGrantParams,
)
class CreditGrantService(StripeService):
def list(
self,
params: Optional["CreditGrantListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[CreditGrant]":
"""
Retrieve a list of credit grants.
"""
return cast(
"ListObject[CreditGrant]",
self._request(
"get",
"/v1/billing/credit_grants",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: Optional["CreditGrantListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[CreditGrant]":
"""
Retrieve a list of credit grants.
"""
return cast(
"ListObject[CreditGrant]",
await self._request_async(
"get",
"/v1/billing/credit_grants",
base_address="api",
params=params,
options=options,
),
)
def create(
self,
params: "CreditGrantCreateParams",
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Creates a credit grant.
"""
return cast(
"CreditGrant",
self._request(
"post",
"/v1/billing/credit_grants",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "CreditGrantCreateParams",
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Creates a credit grant.
"""
return cast(
"CreditGrant",
await self._request_async(
"post",
"/v1/billing/credit_grants",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: Optional["CreditGrantRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Retrieves a credit grant.
"""
return cast(
"CreditGrant",
self._request(
"get",
"/v1/billing/credit_grants/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: Optional["CreditGrantRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Retrieves a credit grant.
"""
return cast(
"CreditGrant",
await self._request_async(
"get",
"/v1/billing/credit_grants/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def update(
self,
id: str,
params: Optional["CreditGrantUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Updates a credit grant.
"""
return cast(
"CreditGrant",
self._request(
"post",
"/v1/billing/credit_grants/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def update_async(
self,
id: str,
params: Optional["CreditGrantUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Updates a credit grant.
"""
return cast(
"CreditGrant",
await self._request_async(
"post",
"/v1/billing/credit_grants/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def expire(
self,
id: str,
params: Optional["CreditGrantExpireParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Expires a credit grant.
"""
return cast(
"CreditGrant",
self._request(
"post",
"/v1/billing/credit_grants/{id}/expire".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
async def expire_async(
self,
id: str,
params: Optional["CreditGrantExpireParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Expires a credit grant.
"""
return cast(
"CreditGrant",
await self._request_async(
"post",
"/v1/billing/credit_grants/{id}/expire".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
def void_grant(
self,
id: str,
params: Optional["CreditGrantVoidGrantParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Voids a credit grant.
"""
return cast(
"CreditGrant",
self._request(
"post",
"/v1/billing/credit_grants/{id}/void".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
async def void_grant_async(
self,
id: str,
params: Optional["CreditGrantVoidGrantParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "CreditGrant":
"""
Voids a credit grant.
"""
return cast(
"CreditGrant",
await self._request_async(
"post",
"/v1/billing/credit_grants/{id}/void".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,494 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from stripe._list_object import ListObject
from stripe._listable_api_resource import ListableAPIResource
from stripe._nested_resource_class_methods import nested_resource_class_methods
from stripe._stripe_object import StripeObject
from stripe._updateable_api_resource import UpdateableAPIResource
from stripe._util import class_method_variant, sanitize_id
from typing import ClassVar, Optional, cast, overload
from typing_extensions import Literal, Unpack, TYPE_CHECKING
if TYPE_CHECKING:
from stripe.billing._meter_event_summary import MeterEventSummary
from stripe.params.billing._meter_create_params import MeterCreateParams
from stripe.params.billing._meter_deactivate_params import (
MeterDeactivateParams,
)
from stripe.params.billing._meter_list_event_summaries_params import (
MeterListEventSummariesParams,
)
from stripe.params.billing._meter_list_params import MeterListParams
from stripe.params.billing._meter_modify_params import MeterModifyParams
from stripe.params.billing._meter_reactivate_params import (
MeterReactivateParams,
)
from stripe.params.billing._meter_retrieve_params import (
MeterRetrieveParams,
)
@nested_resource_class_methods("event_summary")
class Meter(
CreateableAPIResource["Meter"],
ListableAPIResource["Meter"],
UpdateableAPIResource["Meter"],
):
"""
Meters specify how to aggregate meter events over a billing period. Meter events represent the actions that customers take in your system. Meters attach to prices and form the basis of the bill.
Related guide: [Usage based billing](https://docs.stripe.com/billing/subscriptions/usage-based)
"""
OBJECT_NAME: ClassVar[Literal["billing.meter"]] = "billing.meter"
class CustomerMapping(StripeObject):
event_payload_key: str
"""
The key in the meter event payload to use for mapping the event to a customer.
"""
type: Literal["by_id"]
"""
The method for mapping a meter event to a customer.
"""
class DefaultAggregation(StripeObject):
formula: Literal["count", "last", "sum"]
"""
Specifies how events are aggregated.
"""
class StatusTransitions(StripeObject):
deactivated_at: Optional[int]
"""
The time the meter was deactivated, if any. Measured in seconds since Unix epoch.
"""
class ValueSettings(StripeObject):
event_payload_key: str
"""
The key in the meter event payload to use as the value for this meter.
"""
created: int
"""
Time at which the object was created. Measured in seconds since the Unix epoch.
"""
customer_mapping: CustomerMapping
default_aggregation: DefaultAggregation
display_name: str
"""
The meter's name.
"""
event_name: str
"""
The name of the meter event to record usage for. Corresponds with the `event_name` field on meter events.
"""
event_time_window: Optional[Literal["day", "hour"]]
"""
The time window which meter events have been pre-aggregated for, if any.
"""
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.
"""
object: Literal["billing.meter"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
status: Literal["active", "inactive"]
"""
The meter's status.
"""
status_transitions: StatusTransitions
updated: int
"""
Time at which the object was last updated. Measured in seconds since the Unix epoch.
"""
value_settings: ValueSettings
@classmethod
def create(cls, **params: Unpack["MeterCreateParams"]) -> "Meter":
"""
Creates a billing meter.
"""
return cast(
"Meter",
cls._static_request(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
async def create_async(
cls, **params: Unpack["MeterCreateParams"]
) -> "Meter":
"""
Creates a billing meter.
"""
return cast(
"Meter",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
def _cls_deactivate(
cls, id: str, **params: Unpack["MeterDeactivateParams"]
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
return cast(
"Meter",
cls._static_request(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
def deactivate(
id: str, **params: Unpack["MeterDeactivateParams"]
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
...
@overload
def deactivate(self, **params: Unpack["MeterDeactivateParams"]) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
...
@class_method_variant("_cls_deactivate")
def deactivate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["MeterDeactivateParams"]
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
return cast(
"Meter",
self._request(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_deactivate_async(
cls, id: str, **params: Unpack["MeterDeactivateParams"]
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
return cast(
"Meter",
await cls._static_request_async(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
async def deactivate_async(
id: str, **params: Unpack["MeterDeactivateParams"]
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
...
@overload
async def deactivate_async(
self, **params: Unpack["MeterDeactivateParams"]
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
...
@class_method_variant("_cls_deactivate_async")
async def deactivate_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["MeterDeactivateParams"]
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
return cast(
"Meter",
await self._request_async(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
def list(cls, **params: Unpack["MeterListParams"]) -> ListObject["Meter"]:
"""
Retrieve a list of billing meters.
"""
result = cls._static_request(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
async def list_async(
cls, **params: Unpack["MeterListParams"]
) -> ListObject["Meter"]:
"""
Retrieve a list of billing meters.
"""
result = await cls._static_request_async(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):
raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)
return result
@classmethod
def modify(cls, id: str, **params: Unpack["MeterModifyParams"]) -> "Meter":
"""
Updates a billing meter.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(id))
return cast(
"Meter",
cls._static_request(
"post",
url,
params=params,
),
)
@classmethod
async def modify_async(
cls, id: str, **params: Unpack["MeterModifyParams"]
) -> "Meter":
"""
Updates a billing meter.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(id))
return cast(
"Meter",
await cls._static_request_async(
"post",
url,
params=params,
),
)
@classmethod
def _cls_reactivate(
cls, id: str, **params: Unpack["MeterReactivateParams"]
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
return cast(
"Meter",
cls._static_request(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
def reactivate(
id: str, **params: Unpack["MeterReactivateParams"]
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
...
@overload
def reactivate(self, **params: Unpack["MeterReactivateParams"]) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
...
@class_method_variant("_cls_reactivate")
def reactivate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["MeterReactivateParams"]
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
return cast(
"Meter",
self._request(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
async def _cls_reactivate_async(
cls, id: str, **params: Unpack["MeterReactivateParams"]
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
return cast(
"Meter",
await cls._static_request_async(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(id)
),
params=params,
),
)
@overload
@staticmethod
async def reactivate_async(
id: str, **params: Unpack["MeterReactivateParams"]
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
...
@overload
async def reactivate_async(
self, **params: Unpack["MeterReactivateParams"]
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
...
@class_method_variant("_cls_reactivate_async")
async def reactivate_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["MeterReactivateParams"]
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
return cast(
"Meter",
await self._request_async(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(self.get("id"))
),
params=params,
),
)
@classmethod
def retrieve(
cls, id: str, **params: Unpack["MeterRetrieveParams"]
) -> "Meter":
"""
Retrieves a billing meter given an ID.
"""
instance = cls(id, **params)
instance.refresh()
return instance
@classmethod
async def retrieve_async(
cls, id: str, **params: Unpack["MeterRetrieveParams"]
) -> "Meter":
"""
Retrieves a billing meter given an ID.
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance
@classmethod
def list_event_summaries(
cls, id: str, **params: Unpack["MeterListEventSummariesParams"]
) -> ListObject["MeterEventSummary"]:
"""
Retrieve a list of billing meter event summaries.
"""
return cast(
ListObject["MeterEventSummary"],
cls._static_request(
"get",
"/v1/billing/meters/{id}/event_summaries".format(
id=sanitize_id(id)
),
params=params,
),
)
@classmethod
async def list_event_summaries_async(
cls, id: str, **params: Unpack["MeterListEventSummariesParams"]
) -> ListObject["MeterEventSummary"]:
"""
Retrieve a list of billing meter event summaries.
"""
return cast(
ListObject["MeterEventSummary"],
await cls._static_request_async(
"get",
"/v1/billing/meters/{id}/event_summaries".format(
id=sanitize_id(id)
),
params=params,
),
)
_inner_class_types = {
"customer_mapping": CustomerMapping,
"default_aggregation": DefaultAggregation,
"status_transitions": StatusTransitions,
"value_settings": ValueSettings,
}

View File

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from typing import ClassVar, Dict, cast
from typing_extensions import Literal, Unpack, TYPE_CHECKING
if TYPE_CHECKING:
from stripe.params.billing._meter_event_create_params import (
MeterEventCreateParams,
)
class MeterEvent(CreateableAPIResource["MeterEvent"]):
"""
Meter events represent actions that customers take in your system. You can use meter events to bill a customer based on their usage. Meter events are associated with billing meters, which define both the contents of the event's payload and how to aggregate those events.
"""
OBJECT_NAME: ClassVar[Literal["billing.meter_event"]] = (
"billing.meter_event"
)
created: int
"""
Time at which the object was created. Measured in seconds since the Unix epoch.
"""
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.
"""
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["billing.meter_event"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
payload: Dict[str, str]
"""
The payload of the event. This contains 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://stripe.com/docs/billing/subscriptions/usage-based/recording-usage#payload-key-overrides).
"""
timestamp: int
"""
The timestamp passed in when creating the event. Measured in seconds since the Unix epoch.
"""
@classmethod
def create(
cls, **params: Unpack["MeterEventCreateParams"]
) -> "MeterEvent":
"""
Creates a billing meter event.
"""
return cast(
"MeterEvent",
cls._static_request(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
async def create_async(
cls, **params: Unpack["MeterEventCreateParams"]
) -> "MeterEvent":
"""
Creates a billing meter event.
"""
return cast(
"MeterEvent",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)

View File

@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from stripe._stripe_object import StripeObject
from typing import ClassVar, Optional, cast
from typing_extensions import Literal, Unpack, TYPE_CHECKING
if TYPE_CHECKING:
from stripe.params.billing._meter_event_adjustment_create_params import (
MeterEventAdjustmentCreateParams,
)
class MeterEventAdjustment(CreateableAPIResource["MeterEventAdjustment"]):
"""
A billing meter event adjustment is a resource that allows you to cancel a meter event. For example, you might create a billing meter event adjustment to cancel a meter event that was created in error or attached to the wrong customer.
"""
OBJECT_NAME: ClassVar[Literal["billing.meter_event_adjustment"]] = (
"billing.meter_event_adjustment"
)
class Cancel(StripeObject):
identifier: Optional[str]
"""
Unique identifier for the event.
"""
cancel: Optional[Cancel]
"""
Specifies which event to cancel.
"""
event_name: str
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
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["billing.meter_event_adjustment"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
status: Literal["complete", "pending"]
"""
The meter event adjustment's status.
"""
type: Literal["cancel"]
"""
Specifies whether to cancel a single event or a range of events for a time period. Time period cancellation is not supported yet.
"""
@classmethod
def create(
cls, **params: Unpack["MeterEventAdjustmentCreateParams"]
) -> "MeterEventAdjustment":
"""
Creates a billing meter event adjustment.
"""
return cast(
"MeterEventAdjustment",
cls._static_request(
"post",
cls.class_url(),
params=params,
),
)
@classmethod
async def create_async(
cls, **params: Unpack["MeterEventAdjustmentCreateParams"]
) -> "MeterEventAdjustment":
"""
Creates a billing meter event adjustment.
"""
return cast(
"MeterEventAdjustment",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)
_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.billing._meter_event_adjustment import MeterEventAdjustment
from stripe.params.billing._meter_event_adjustment_create_params import (
MeterEventAdjustmentCreateParams,
)
class MeterEventAdjustmentService(StripeService):
def create(
self,
params: "MeterEventAdjustmentCreateParams",
options: Optional["RequestOptions"] = None,
) -> "MeterEventAdjustment":
"""
Creates a billing meter event adjustment.
"""
return cast(
"MeterEventAdjustment",
self._request(
"post",
"/v1/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 billing meter event adjustment.
"""
return cast(
"MeterEventAdjustment",
await self._request_async(
"post",
"/v1/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.billing._meter_event import MeterEvent
from stripe.params.billing._meter_event_create_params import (
MeterEventCreateParams,
)
class MeterEventService(StripeService):
def create(
self,
params: "MeterEventCreateParams",
options: Optional["RequestOptions"] = None,
) -> "MeterEvent":
"""
Creates a billing meter event.
"""
return cast(
"MeterEvent",
self._request(
"post",
"/v1/billing/meter_events",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "MeterEventCreateParams",
options: Optional["RequestOptions"] = None,
) -> "MeterEvent":
"""
Creates a billing meter event.
"""
return cast(
"MeterEvent",
await self._request_async(
"post",
"/v1/billing/meter_events",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,46 @@
# -*- 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 MeterEventSummary(StripeObject):
"""
A billing meter event summary represents an aggregated view of a customer's billing meter events within a specified timeframe. It indicates how much
usage was accrued by a customer for that period.
Note: Meters events are aggregated asynchronously so the meter event summaries provide an eventually consistent view of the reported usage.
"""
OBJECT_NAME: ClassVar[Literal["billing.meter_event_summary"]] = (
"billing.meter_event_summary"
)
aggregated_value: float
"""
Aggregated value of all the events within `start_time` (inclusive) and `end_time` (inclusive). The aggregation strategy is defined on meter via `default_aggregation`.
"""
end_time: int
"""
End timestamp for this event summary (exclusive). Must be aligned with minute boundaries.
"""
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.
"""
meter: str
"""
The meter associated with this event summary.
"""
object: Literal["billing.meter_event_summary"]
"""
String representing the object's type. Objects of the same type share the same value.
"""
start_time: int
"""
Start timestamp for this event summary (inclusive). Must be aligned with minute boundaries.
"""

View File

@@ -0,0 +1,60 @@
# -*- 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._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe.billing._meter_event_summary import MeterEventSummary
from stripe.params.billing._meter_event_summary_list_params import (
MeterEventSummaryListParams,
)
class MeterEventSummaryService(StripeService):
def list(
self,
id: str,
params: "MeterEventSummaryListParams",
options: Optional["RequestOptions"] = None,
) -> "ListObject[MeterEventSummary]":
"""
Retrieve a list of billing meter event summaries.
"""
return cast(
"ListObject[MeterEventSummary]",
self._request(
"get",
"/v1/billing/meters/{id}/event_summaries".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
id: str,
params: "MeterEventSummaryListParams",
options: Optional["RequestOptions"] = None,
) -> "ListObject[MeterEventSummary]":
"""
Retrieve a list of billing meter event summaries.
"""
return cast(
"ListObject[MeterEventSummary]",
await self._request_async(
"get",
"/v1/billing/meters/{id}/event_summaries".format(
id=sanitize_id(id),
),
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,301 @@
# -*- 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 importlib import import_module
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from stripe._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe.billing._meter import Meter
from stripe.billing._meter_event_summary_service import (
MeterEventSummaryService,
)
from stripe.params.billing._meter_create_params import MeterCreateParams
from stripe.params.billing._meter_deactivate_params import (
MeterDeactivateParams,
)
from stripe.params.billing._meter_list_params import MeterListParams
from stripe.params.billing._meter_reactivate_params import (
MeterReactivateParams,
)
from stripe.params.billing._meter_retrieve_params import (
MeterRetrieveParams,
)
from stripe.params.billing._meter_update_params import MeterUpdateParams
_subservices = {
"event_summaries": [
"stripe.billing._meter_event_summary_service",
"MeterEventSummaryService",
],
}
class MeterService(StripeService):
event_summaries: "MeterEventSummaryService"
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()
def list(
self,
params: Optional["MeterListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[Meter]":
"""
Retrieve a list of billing meters.
"""
return cast(
"ListObject[Meter]",
self._request(
"get",
"/v1/billing/meters",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: Optional["MeterListParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "ListObject[Meter]":
"""
Retrieve a list of billing meters.
"""
return cast(
"ListObject[Meter]",
await self._request_async(
"get",
"/v1/billing/meters",
base_address="api",
params=params,
options=options,
),
)
def create(
self,
params: "MeterCreateParams",
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
Creates a billing meter.
"""
return cast(
"Meter",
self._request(
"post",
"/v1/billing/meters",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "MeterCreateParams",
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
Creates a billing meter.
"""
return cast(
"Meter",
await self._request_async(
"post",
"/v1/billing/meters",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: Optional["MeterRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
Retrieves a billing meter given an ID.
"""
return cast(
"Meter",
self._request(
"get",
"/v1/billing/meters/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: Optional["MeterRetrieveParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
Retrieves a billing meter given an ID.
"""
return cast(
"Meter",
await self._request_async(
"get",
"/v1/billing/meters/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def update(
self,
id: str,
params: Optional["MeterUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
Updates a billing meter.
"""
return cast(
"Meter",
self._request(
"post",
"/v1/billing/meters/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
async def update_async(
self,
id: str,
params: Optional["MeterUpdateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
Updates a billing meter.
"""
return cast(
"Meter",
await self._request_async(
"post",
"/v1/billing/meters/{id}".format(id=sanitize_id(id)),
base_address="api",
params=params,
options=options,
),
)
def deactivate(
self,
id: str,
params: Optional["MeterDeactivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
return cast(
"Meter",
self._request(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(id)
),
base_address="api",
params=params,
options=options,
),
)
async def deactivate_async(
self,
id: str,
params: Optional["MeterDeactivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
When a meter is deactivated, no more meter events will be accepted for this meter. You can't attach a deactivated meter to a price.
"""
return cast(
"Meter",
await self._request_async(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(id)
),
base_address="api",
params=params,
options=options,
),
)
def reactivate(
self,
id: str,
params: Optional["MeterReactivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
return cast(
"Meter",
self._request(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(id)
),
base_address="api",
params=params,
options=options,
),
)
async def reactivate_async(
self,
id: str,
params: Optional["MeterReactivateParams"] = None,
options: Optional["RequestOptions"] = None,
) -> "Meter":
"""
When a meter is reactivated, events for this meter can be accepted and you can attach the meter to a price.
"""
return cast(
"Meter",
await self._request_async(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(id)
),
base_address="api",
params=params,
options=options,
),
)