stripe/resources/
usage_record_ext.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Client, Response, SubscriptionItemId, Timestamp, UsageRecord};
4
5impl UsageRecord {
6    pub fn create(
7        client: &Client,
8        subscription_item_id: &SubscriptionItemId,
9        params: CreateUsageRecord,
10    ) -> Response<UsageRecord> {
11        #[allow(clippy::needless_borrows_for_generic_args)]
12        client.post_form(
13            &format!("/subscription_items/{}/usage_records", subscription_item_id),
14            &params,
15        )
16    }
17}
18
19/// The parameters for `UsageRecord::create`.
20#[derive(Clone, Debug, Serialize, Default)]
21pub struct CreateUsageRecord {
22    /// The usage quantity for the specified timestamp.
23    pub quantity: u64,
24    /// Valid values are `increment` (default) or `set`.
25    /// When using `increment` the specified `quantity` will be added to the usage at the specified timestamp.
26    /// The `set` action will overwrite the usage quantity at that timestamp.
27    /// If the subscription has [billing thresholds](https://stripe.com/docs/api/subscriptions/object#subscription_object-billing_thresholds),
28    /// `increment` is the only allowed value.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub action: Option<UsageRecordAction>,
31    /// The timestamp for the usage event.
32    /// This timestamp must be within the current billing period of the subscription of the provided `subscription_item`,
33    /// and must not be in the future. When passing `"now"`, Stripe records usage for the current time.
34    /// Default is `"now"` if a value is not provided.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub timestamp: Option<Timestamp>,
37}
38
39/// An enum representing the possible values of a `UsageRecord`'s `account` field.
40#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
41#[serde(rename_all = "snake_case")]
42pub enum UsageRecordAction {
43    Increment,
44    Set,
45}