Skip to main content

lago_types/requests/
customer_usage.rs

1/// Request parameters for retrieving customer current usage.
2///
3/// This struct contains the identifiers needed to fetch current usage data
4/// for a customer's subscription within the current billing period.
5#[derive(Debug, Clone)]
6pub struct GetCustomerCurrentUsageRequest {
7    /// The customer's external unique identifier (provided by your application)
8    pub external_customer_id: String,
9    /// The subscription's unique identifier within your application
10    pub external_subscription_id: String,
11    /// Optional flag to determine if taxes should be applied (defaults to true)
12    pub apply_taxes: Option<bool>,
13}
14
15impl GetCustomerCurrentUsageRequest {
16    /// Creates a new get customer current usage request.
17    ///
18    /// # Arguments
19    /// * `external_customer_id` - The external unique identifier of the customer
20    /// * `external_subscription_id` - The unique identifier of the subscription
21    ///
22    /// # Returns
23    /// A new `GetCustomerCurrentUsageRequest` instance with the specified identifiers.
24    pub fn new(external_customer_id: String, external_subscription_id: String) -> Self {
25        Self {
26            external_customer_id,
27            external_subscription_id,
28            apply_taxes: None,
29        }
30    }
31
32    /// Sets the apply_taxes flag for the request.
33    ///
34    /// # Arguments
35    /// * `apply_taxes` - Whether taxes should be applied to the usage amounts
36    ///
37    /// # Returns
38    /// The modified request instance for method chaining.
39    pub fn with_apply_taxes(mut self, apply_taxes: bool) -> Self {
40        self.apply_taxes = Some(apply_taxes);
41        self
42    }
43
44    /// Converts the request parameters into HTTP query parameters.
45    ///
46    /// # Returns
47    /// A vector of query parameter tuples for the subscription ID and apply_taxes flag.
48    pub fn to_query_params(&self) -> Vec<(&str, String)> {
49        let mut params: Vec<(&str, String)> = Vec::new();
50
51        params.push((
52            "external_subscription_id",
53            self.external_subscription_id.clone(),
54        ));
55
56        if let Some(apply_taxes) = self.apply_taxes {
57            params.push(("apply_taxes", apply_taxes.to_string()));
58        }
59
60        params
61    }
62}