Improve subscription UI with large tier buttons

- Replace dropdown tier selection with attractive visual buttons
- Add tier-button CSS with hover effects and selection states
- Remove 'or pay by card' divider from subscription form for cleaner UI
- Update JavaScript to handle tier button selection events
- Fix Stripe module import conflict by renaming stripe directory to stripe_config
- Add responsive grid layout for tier buttons on mobile devices
This commit is contained in:
2025-10-07 17:22:51 +01:00
parent bfdcee8602
commit 3ddbc40bb5
2655 changed files with 516264 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
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._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

View File

@@ -0,0 +1,585 @@
# -*- 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._request_options import RequestOptions
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,
NotRequired,
TypedDict,
Unpack,
TYPE_CHECKING,
)
if TYPE_CHECKING:
from stripe._customer import Customer
from stripe.billing._meter import Meter
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 Filter(StripeObject):
customer: Optional[ExpandableField["Customer"]]
"""
Limit the scope of the alert to this customer ID
"""
class UsageThresholdConfig(StripeObject):
gte: int
"""
The value at which this alert will trigger.
"""
meter: ExpandableField["Meter"]
"""
The [Billing Meter](https://stripe.com/api/billing/meter) ID whose usage is monitored.
"""
recurrence: Literal["one_time"]
"""
Defines how the alert will behave.
"""
class ActivateParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ArchiveParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class CreateParams(RequestOptions):
alert_type: Literal["usage_threshold"]
"""
The type of alert to create.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
filter: NotRequired["Alert.CreateParamsFilter"]
"""
Filters to limit the scope of an alert.
"""
title: str
"""
The title of the alert.
"""
usage_threshold_config: NotRequired[
"Alert.CreateParamsUsageThresholdConfig"
]
"""
The configuration of the usage threshold.
"""
class CreateParamsFilter(TypedDict):
customer: NotRequired[str]
"""
Limit the scope to this alert only to this customer.
"""
class CreateParamsUsageThresholdConfig(TypedDict):
gte: int
"""
Defines at which value the alert will fire.
"""
meter: NotRequired[str]
"""
The [Billing Meter](https://stripe.com/api/billing/meter) ID whose usage is monitored.
"""
recurrence: Literal["one_time"]
"""
Whether the alert should only fire only once, or once per billing cycle.
"""
class DeactivateParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ListParams(RequestOptions):
alert_type: NotRequired[Literal["usage_threshold"]]
"""
Filter results to only include this type of alert.
"""
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
meter: NotRequired[str]
"""
Filter results to only include alerts with the given meter.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
class RetrieveParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
alert_type: Literal["usage_threshold"]
"""
Defines the type of the alert.
"""
filter: Optional[Filter]
"""
Limits the scope of the alert to a specific [customer](https://stripe.com/docs/api/customers).
"""
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_config: Optional[UsageThresholdConfig]
"""
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["Alert.ActivateParams"]
) -> "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["Alert.ActivateParams"]) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
...
@overload
def activate(self, **params: Unpack["Alert.ActivateParams"]) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
...
@class_method_variant("_cls_activate")
def activate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Alert.ActivateParams"]
) -> "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["Alert.ActivateParams"]
) -> "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["Alert.ActivateParams"]
) -> "Alert":
"""
Reactivates this alert, allowing it to trigger again.
"""
...
@overload
async def activate_async(
self, **params: Unpack["Alert.ActivateParams"]
) -> "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["Alert.ActivateParams"]
) -> "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["Alert.ArchiveParams"]
) -> "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["Alert.ArchiveParams"]) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
...
@overload
def archive(self, **params: Unpack["Alert.ArchiveParams"]) -> "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["Alert.ArchiveParams"]
) -> "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["Alert.ArchiveParams"]
) -> "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["Alert.ArchiveParams"]
) -> "Alert":
"""
Archives this alert, removing it from the list view and APIs. This is non-reversible.
"""
...
@overload
async def archive_async(
self, **params: Unpack["Alert.ArchiveParams"]
) -> "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["Alert.ArchiveParams"]
) -> "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["Alert.CreateParams"]) -> "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["Alert.CreateParams"]
) -> "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["Alert.DeactivateParams"]
) -> "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["Alert.DeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@overload
def deactivate(
self, **params: Unpack["Alert.DeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@class_method_variant("_cls_deactivate")
def deactivate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Alert.DeactivateParams"]
) -> "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["Alert.DeactivateParams"]
) -> "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["Alert.DeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@overload
async def deactivate_async(
self, **params: Unpack["Alert.DeactivateParams"]
) -> "Alert":
"""
Deactivates this alert, preventing it from triggering.
"""
...
@class_method_variant("_cls_deactivate_async")
async def deactivate_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Alert.DeactivateParams"]
) -> "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["Alert.ListParams"]) -> 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["Alert.ListParams"]
) -> 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["Alert.RetrieveParams"]
) -> "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["Alert.RetrieveParams"]
) -> "Alert":
"""
Retrieves a billing alert given an ID
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance
_inner_class_types = {
"filter": Filter,
"usage_threshold_config": UsageThresholdConfig,
}

View File

@@ -0,0 +1,353 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe._stripe_service import StripeService
from stripe._util import sanitize_id
from stripe.billing._alert import Alert
from typing import List, cast
from typing_extensions import Literal, NotRequired, TypedDict
class AlertService(StripeService):
class ActivateParams(TypedDict):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ArchiveParams(TypedDict):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class CreateParams(TypedDict):
alert_type: Literal["usage_threshold"]
"""
The type of alert to create.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
filter: NotRequired["AlertService.CreateParamsFilter"]
"""
Filters to limit the scope of an alert.
"""
title: str
"""
The title of the alert.
"""
usage_threshold_config: NotRequired[
"AlertService.CreateParamsUsageThresholdConfig"
]
"""
The configuration of the usage threshold.
"""
class CreateParamsFilter(TypedDict):
customer: NotRequired[str]
"""
Limit the scope to this alert only to this customer.
"""
class CreateParamsUsageThresholdConfig(TypedDict):
gte: int
"""
Defines at which value the alert will fire.
"""
meter: NotRequired[str]
"""
The [Billing Meter](https://stripe.com/api/billing/meter) ID whose usage is monitored.
"""
recurrence: Literal["one_time"]
"""
Whether the alert should only fire only once, or once per billing cycle.
"""
class DeactivateParams(TypedDict):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ListParams(TypedDict):
alert_type: NotRequired[Literal["usage_threshold"]]
"""
Filter results to only include this type of alert.
"""
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
meter: NotRequired[str]
"""
Filter results to only include alerts with the given meter.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
class RetrieveParams(TypedDict):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
def list(
self,
params: "AlertService.ListParams" = {},
options: RequestOptions = {},
) -> ListObject[Alert]:
"""
Lists billing active and inactive alerts
"""
return cast(
ListObject[Alert],
self._request(
"get",
"/v1/billing/alerts",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: "AlertService.ListParams" = {},
options: RequestOptions = {},
) -> ListObject[Alert]:
"""
Lists billing active and inactive alerts
"""
return cast(
ListObject[Alert],
await self._request_async(
"get",
"/v1/billing/alerts",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def create(
self, params: "AlertService.CreateParams", options: RequestOptions = {}
) -> Alert:
"""
Creates a billing alert
"""
return cast(
Alert,
self._request(
"post",
"/v1/billing/alerts",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self, params: "AlertService.CreateParams", options: RequestOptions = {}
) -> Alert:
"""
Creates a billing alert
"""
return cast(
Alert,
await self._request_async(
"post",
"/v1/billing/alerts",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: "AlertService.RetrieveParams" = {},
options: RequestOptions = {},
) -> Alert:
"""
Retrieves a billing alert given an ID
"""
return cast(
Alert,
self._request(
"get",
"/v1/billing/alerts/{id}".format(id=sanitize_id(id)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: "AlertService.RetrieveParams" = {},
options: RequestOptions = {},
) -> 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)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def activate(
self,
id: str,
params: "AlertService.ActivateParams" = {},
options: RequestOptions = {},
) -> 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)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def activate_async(
self,
id: str,
params: "AlertService.ActivateParams" = {},
options: RequestOptions = {},
) -> 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)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def archive(
self,
id: str,
params: "AlertService.ArchiveParams" = {},
options: RequestOptions = {},
) -> 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)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def archive_async(
self,
id: str,
params: "AlertService.ArchiveParams" = {},
options: RequestOptions = {},
) -> 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)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def deactivate(
self,
id: str,
params: "AlertService.DeactivateParams" = {},
options: RequestOptions = {},
) -> Alert:
"""
Deactivates this alert, preventing it from triggering.
"""
return cast(
Alert,
self._request(
"post",
"/v1/billing/alerts/{id}/deactivate".format(
id=sanitize_id(id)
),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def deactivate_async(
self,
id: str,
params: "AlertService.DeactivateParams" = {},
options: RequestOptions = {},
) -> 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)
),
api_mode="V1",
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,626 @@
# -*- 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._request_options import RequestOptions
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, List, Optional, cast, overload
from typing_extensions import (
Literal,
NotRequired,
TypedDict,
Unpack,
TYPE_CHECKING,
)
if TYPE_CHECKING:
from stripe.billing._meter_event_summary import MeterEventSummary
@nested_resource_class_methods("event_summary")
class Meter(
CreateableAPIResource["Meter"],
ListableAPIResource["Meter"],
UpdateableAPIResource["Meter"],
):
"""
A billing meter is a resource that allows you to track usage of a particular event. For example, you might create a billing meter to track the number of API calls made by a particular user. You can then attach the billing meter to a price and attach the price to a subscription to charge the user for the number of API calls they make.
"""
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", "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.
"""
class CreateParams(RequestOptions):
customer_mapping: NotRequired["Meter.CreateParamsCustomerMapping"]
"""
Fields that specify how to map a meter event to a customer.
"""
default_aggregation: "Meter.CreateParamsDefaultAggregation"
"""
The default settings to aggregate a meter's events with.
"""
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: NotRequired[Literal["day", "hour"]]
"""
The time window to pre-aggregate meter events for, if any.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
value_settings: NotRequired["Meter.CreateParamsValueSettings"]
"""
Fields that specify how to calculate a meter event's value.
"""
class CreateParamsCustomerMapping(TypedDict):
event_payload_key: str
"""
The key in the usage 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. Must be `by_id`.
"""
class CreateParamsDefaultAggregation(TypedDict):
formula: Literal["count", "sum"]
"""
Specifies how events are aggregated. Allowed values are `count` to count the number of events and `sum` to sum each event's value.
"""
class CreateParamsValueSettings(TypedDict):
event_payload_key: str
"""
The key in the usage event payload to use as the value for this meter. For example, if the event payload contains usage on a `bytes_used` field, then set the event_payload_key to "bytes_used".
"""
class DeactivateParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ListEventSummariesParams(RequestOptions):
customer: str
"""
The customer for which to fetch event summaries.
"""
end_time: int
"""
The timestamp from when to stop aggregating meter events (exclusive). Must be aligned with minute boundaries.
"""
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
start_time: int
"""
The timestamp from when to start aggregating meter events (inclusive). Must be aligned with minute boundaries.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
value_grouping_window: NotRequired[Literal["day", "hour"]]
"""
Specifies what granularity to use when generating event summaries. If not specified, a single event summary would be returned for the specified time range. For hourly granularity, start and end times must align with hour boundaries (e.g., 00:00, 01:00, ..., 23:00). For daily granularity, start and end times must align with UTC day boundaries (00:00 UTC).
"""
class ListParams(RequestOptions):
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
status: NotRequired[Literal["active", "inactive"]]
"""
Filter results to only include meters with the given status.
"""
class ModifyParams(RequestOptions):
display_name: NotRequired[str]
"""
The meter's name.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ReactivateParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class RetrieveParams(RequestOptions):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
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 to pre-aggregate meter events 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["Meter.CreateParams"]) -> "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["Meter.CreateParams"]
) -> "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["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
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["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
...
@overload
def deactivate(
self, **params: Unpack["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
...
@class_method_variant("_cls_deactivate")
def deactivate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
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["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
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["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
...
@overload
async def deactivate_async(
self, **params: Unpack["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
...
@class_method_variant("_cls_deactivate_async")
async def deactivate_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Meter.DeactivateParams"]
) -> "Meter":
"""
Deactivates a billing meter
"""
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["Meter.ListParams"]) -> 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["Meter.ListParams"]
) -> 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["Meter.ModifyParams"]
) -> "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["Meter.ModifyParams"]
) -> "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["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
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["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
...
@overload
def reactivate(
self, **params: Unpack["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
...
@class_method_variant("_cls_reactivate")
def reactivate( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
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["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
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["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
...
@overload
async def reactivate_async(
self, **params: Unpack["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
...
@class_method_variant("_cls_reactivate_async")
async def reactivate_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["Meter.ReactivateParams"]
) -> "Meter":
"""
Reactivates a billing meter
"""
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["Meter.RetrieveParams"]
) -> "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["Meter.RetrieveParams"]
) -> "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["Meter.ListEventSummariesParams"]
) -> 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["Meter.ListEventSummariesParams"]
) -> 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,100 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from stripe._request_options import RequestOptions
from typing import ClassVar, Dict, List, cast
from typing_extensions import Literal, NotRequired, Unpack
class MeterEvent(CreateableAPIResource["MeterEvent"]):
"""
A billing meter event represents a customer's usage of a product. Meter events are used to bill a customer based on their usage.
Meter events are associated with billing meters, which define the shape of the event's payload and how those events are aggregated for billing.
"""
OBJECT_NAME: ClassVar[Literal["billing.meter_event"]] = (
"billing.meter_event"
)
class CreateParams(RequestOptions):
event_name: str
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
identifier: NotRequired[str]
"""
A unique identifier for the event. If not provided, one will be generated. We recommend using a globally unique identifier for this. We'll enforce uniqueness within a rolling 24 hour period.
"""
payload: Dict[str, str]
"""
The payload of the event. This must contain 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://docs.stripe.com/billing/subscriptions/usage-based/recording-usage#payload-key-overrides).
"""
timestamp: NotRequired[int]
"""
The time of the event. Measured in seconds since the Unix epoch. Must be within the past 35 calendar days or up to 5 minutes in the future. Defaults to current timestamp if not specified.
"""
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["MeterEvent.CreateParams"]
) -> "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["MeterEvent.CreateParams"]
) -> "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,106 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._createable_api_resource import CreateableAPIResource
from stripe._request_options import RequestOptions
from stripe._stripe_object import StripeObject
from typing import ClassVar, List, Optional, cast
from typing_extensions import Literal, NotRequired, TypedDict, Unpack
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.
"""
class CreateParams(RequestOptions):
cancel: NotRequired["MeterEventAdjustment.CreateParamsCancel"]
"""
Specifies which event to cancel.
"""
event_name: str
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
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.
"""
class CreateParamsCancel(TypedDict):
identifier: NotRequired[str]
"""
Unique identifier for the event. You can only cancel events within 24 hours of Stripe receiving them.
"""
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["MeterEventAdjustment.CreateParams"]
) -> "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["MeterEventAdjustment.CreateParams"]
) -> "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,73 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._request_options import RequestOptions
from stripe._stripe_service import StripeService
from stripe.billing._meter_event_adjustment import MeterEventAdjustment
from typing import List, cast
from typing_extensions import Literal, NotRequired, TypedDict
class MeterEventAdjustmentService(StripeService):
class CreateParams(TypedDict):
cancel: NotRequired["MeterEventAdjustmentService.CreateParamsCancel"]
"""
Specifies which event to cancel.
"""
event_name: str
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
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.
"""
class CreateParamsCancel(TypedDict):
identifier: NotRequired[str]
"""
Unique identifier for the event. You can only cancel events within 24 hours of Stripe receiving them.
"""
def create(
self,
params: "MeterEventAdjustmentService.CreateParams",
options: RequestOptions = {},
) -> MeterEventAdjustment:
"""
Creates a billing meter event adjustment
"""
return cast(
MeterEventAdjustment,
self._request(
"post",
"/v1/billing/meter_event_adjustments",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "MeterEventAdjustmentService.CreateParams",
options: RequestOptions = {},
) -> MeterEventAdjustment:
"""
Creates a billing meter event adjustment
"""
return cast(
MeterEventAdjustment,
await self._request_async(
"post",
"/v1/billing/meter_event_adjustments",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._request_options import RequestOptions
from stripe._stripe_service import StripeService
from stripe.billing._meter_event import MeterEvent
from typing import Dict, List, cast
from typing_extensions import NotRequired, TypedDict
class MeterEventService(StripeService):
class CreateParams(TypedDict):
event_name: str
"""
The name of the meter event. Corresponds with the `event_name` field on a meter.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
identifier: NotRequired[str]
"""
A unique identifier for the event. If not provided, one will be generated. We recommend using a globally unique identifier for this. We'll enforce uniqueness within a rolling 24 hour period.
"""
payload: Dict[str, str]
"""
The payload of the event. This must contain 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://docs.stripe.com/billing/subscriptions/usage-based/recording-usage#payload-key-overrides).
"""
timestamp: NotRequired[int]
"""
The time of the event. Measured in seconds since the Unix epoch. Must be within the past 35 calendar days or up to 5 minutes in the future. Defaults to current timestamp if not specified.
"""
def create(
self,
params: "MeterEventService.CreateParams",
options: RequestOptions = {},
) -> MeterEvent:
"""
Creates a billing meter event
"""
return cast(
MeterEvent,
self._request(
"post",
"/v1/billing/meter_events",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self,
params: "MeterEventService.CreateParams",
options: RequestOptions = {},
) -> MeterEvent:
"""
Creates a billing meter event
"""
return cast(
MeterEvent,
await self._request_async(
"post",
"/v1/billing/meter_events",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,44 @@
# -*- 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.
"""
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,91 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe._stripe_service import StripeService
from stripe._util import sanitize_id
from stripe.billing._meter_event_summary import MeterEventSummary
from typing import List, cast
from typing_extensions import Literal, NotRequired, TypedDict
class MeterEventSummaryService(StripeService):
class ListParams(TypedDict):
customer: str
"""
The customer for which to fetch event summaries.
"""
end_time: int
"""
The timestamp from when to stop aggregating meter events (exclusive). Must be aligned with minute boundaries.
"""
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
start_time: int
"""
The timestamp from when to start aggregating meter events (inclusive). Must be aligned with minute boundaries.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
value_grouping_window: NotRequired[Literal["day", "hour"]]
"""
Specifies what granularity to use when generating event summaries. If not specified, a single event summary would be returned for the specified time range. For hourly granularity, start and end times must align with hour boundaries (e.g., 00:00, 01:00, ..., 23:00). For daily granularity, start and end times must align with UTC day boundaries (00:00 UTC).
"""
def list(
self,
id: str,
params: "MeterEventSummaryService.ListParams",
options: RequestOptions = {},
) -> 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),
),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
id: str,
params: "MeterEventSummaryService.ListParams",
options: RequestOptions = {},
) -> 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),
),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)

View File

@@ -0,0 +1,374 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from stripe._list_object import ListObject
from stripe._request_options import RequestOptions
from stripe._stripe_service import StripeService
from stripe._util import sanitize_id
from stripe.billing._meter import Meter
from stripe.billing._meter_event_summary_service import (
MeterEventSummaryService,
)
from typing import List, cast
from typing_extensions import Literal, NotRequired, TypedDict
class MeterService(StripeService):
def __init__(self, requestor):
super().__init__(requestor)
self.event_summaries = MeterEventSummaryService(self._requestor)
class CreateParams(TypedDict):
customer_mapping: NotRequired[
"MeterService.CreateParamsCustomerMapping"
]
"""
Fields that specify how to map a meter event to a customer.
"""
default_aggregation: "MeterService.CreateParamsDefaultAggregation"
"""
The default settings to aggregate a meter's events with.
"""
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: NotRequired[Literal["day", "hour"]]
"""
The time window to pre-aggregate meter events for, if any.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
value_settings: NotRequired["MeterService.CreateParamsValueSettings"]
"""
Fields that specify how to calculate a meter event's value.
"""
class CreateParamsCustomerMapping(TypedDict):
event_payload_key: str
"""
The key in the usage 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. Must be `by_id`.
"""
class CreateParamsDefaultAggregation(TypedDict):
formula: Literal["count", "sum"]
"""
Specifies how events are aggregated. Allowed values are `count` to count the number of events and `sum` to sum each event's value.
"""
class CreateParamsValueSettings(TypedDict):
event_payload_key: str
"""
The key in the usage event payload to use as the value for this meter. For example, if the event payload contains usage on a `bytes_used` field, then set the event_payload_key to "bytes_used".
"""
class DeactivateParams(TypedDict):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class ListParams(TypedDict):
ending_before: NotRequired[str]
"""
A cursor for use in pagination. `ending_before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
limit: NotRequired[int]
"""
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
"""
starting_after: NotRequired[str]
"""
A cursor for use in pagination. `starting_after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
"""
status: NotRequired[Literal["active", "inactive"]]
"""
Filter results to only include meters with the given status.
"""
class ReactivateParams(TypedDict):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class RetrieveParams(TypedDict):
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
class UpdateParams(TypedDict):
display_name: NotRequired[str]
"""
The meter's name.
"""
expand: NotRequired[List[str]]
"""
Specifies which fields in the response should be expanded.
"""
def list(
self,
params: "MeterService.ListParams" = {},
options: RequestOptions = {},
) -> ListObject[Meter]:
"""
Retrieve a list of billing meters.
"""
return cast(
ListObject[Meter],
self._request(
"get",
"/v1/billing/meters",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def list_async(
self,
params: "MeterService.ListParams" = {},
options: RequestOptions = {},
) -> ListObject[Meter]:
"""
Retrieve a list of billing meters.
"""
return cast(
ListObject[Meter],
await self._request_async(
"get",
"/v1/billing/meters",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def create(
self, params: "MeterService.CreateParams", options: RequestOptions = {}
) -> Meter:
"""
Creates a billing meter
"""
return cast(
Meter,
self._request(
"post",
"/v1/billing/meters",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def create_async(
self, params: "MeterService.CreateParams", options: RequestOptions = {}
) -> Meter:
"""
Creates a billing meter
"""
return cast(
Meter,
await self._request_async(
"post",
"/v1/billing/meters",
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def retrieve(
self,
id: str,
params: "MeterService.RetrieveParams" = {},
options: RequestOptions = {},
) -> Meter:
"""
Retrieves a billing meter given an ID
"""
return cast(
Meter,
self._request(
"get",
"/v1/billing/meters/{id}".format(id=sanitize_id(id)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def retrieve_async(
self,
id: str,
params: "MeterService.RetrieveParams" = {},
options: RequestOptions = {},
) -> 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)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def update(
self,
id: str,
params: "MeterService.UpdateParams" = {},
options: RequestOptions = {},
) -> Meter:
"""
Updates a billing meter
"""
return cast(
Meter,
self._request(
"post",
"/v1/billing/meters/{id}".format(id=sanitize_id(id)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def update_async(
self,
id: str,
params: "MeterService.UpdateParams" = {},
options: RequestOptions = {},
) -> Meter:
"""
Updates a billing meter
"""
return cast(
Meter,
await self._request_async(
"post",
"/v1/billing/meters/{id}".format(id=sanitize_id(id)),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def deactivate(
self,
id: str,
params: "MeterService.DeactivateParams" = {},
options: RequestOptions = {},
) -> Meter:
"""
Deactivates a billing meter
"""
return cast(
Meter,
self._request(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(id)
),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def deactivate_async(
self,
id: str,
params: "MeterService.DeactivateParams" = {},
options: RequestOptions = {},
) -> Meter:
"""
Deactivates a billing meter
"""
return cast(
Meter,
await self._request_async(
"post",
"/v1/billing/meters/{id}/deactivate".format(
id=sanitize_id(id)
),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
def reactivate(
self,
id: str,
params: "MeterService.ReactivateParams" = {},
options: RequestOptions = {},
) -> Meter:
"""
Reactivates a billing meter
"""
return cast(
Meter,
self._request(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(id)
),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)
async def reactivate_async(
self,
id: str,
params: "MeterService.ReactivateParams" = {},
options: RequestOptions = {},
) -> Meter:
"""
Reactivates a billing meter
"""
return cast(
Meter,
await self._request_async(
"post",
"/v1/billing/meters/{id}/reactivate".format(
id=sanitize_id(id)
),
api_mode="V1",
base_address="api",
params=params,
options=options,
),
)