1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
/// Represents the current usage data for a customer's subscription.
///
/// This struct contains information about usage-based billing data
/// within the current billing period.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomerUsage {
/// Start of the billing period
pub from_datetime: DateTime<Utc>,
/// End of the billing period
pub to_datetime: DateTime<Utc>,
/// Invoice issuance date
pub issuing_date: String,
/// Associated invoice identifier (if exists)
pub lago_invoice_id: Option<Uuid>,
/// Currency code (e.g., USD, EUR)
pub currency: String,
/// Total charges amount in cents (excluding taxes)
pub amount_cents: i64,
/// Tax amount in cents
pub taxes_amount_cents: i64,
/// Grand total in cents (amount + taxes)
pub total_amount_cents: i64,
/// Array of charge usage line items
pub charges_usage: Vec<ChargeUsage>,
}
/// Represents usage data for a specific charge.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChargeUsage {
/// Aggregated unit quantity
pub units: String,
/// Total units aggregated across the period
pub total_aggregated_units: Option<String>,
/// Number of events processed
pub events_count: i64,
/// Charge amount in cents
pub amount_cents: i64,
/// Currency code
pub amount_currency: String,
/// Custom pricing unit details
pub pricing_unit_details: Option<PricingUnitDetails>,
/// Charge configuration
pub charge: ChargeInfo,
/// Billable metric details
pub billable_metric: BillableMetricInfo,
/// Applied filter breakdowns
pub filters: Vec<ChargeFilterUsage>,
/// Grouped usage data
pub grouped_usage: Vec<GroupedUsage>,
}
/// Pricing unit details for custom pricing
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PricingUnitDetails {
/// Amount in cents
pub amount_cents: Option<i64>,
/// Short name for the pricing unit
pub short_name: Option<String>,
/// Conversion rate
pub conversion_rate: Option<String>,
}
/// Basic charge information within usage
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChargeInfo {
/// Unique identifier for the charge in Lago
pub lago_id: Uuid,
/// Charge model (standard, graduated, volume, package, percentage)
pub charge_model: String,
/// Display name for invoices
pub invoice_display_name: Option<String>,
}
/// Basic billable metric information within usage
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BillableMetricInfo {
/// Unique identifier for the billable metric in Lago
pub lago_id: Uuid,
/// Name of the billable metric
pub name: String,
/// Unique code for the billable metric
pub code: String,
/// Aggregation type (count_agg, sum_agg, max_agg, etc.)
pub aggregation_type: String,
}
/// Filter usage breakdown
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChargeFilterUsage {
/// Units for this filter
pub units: String,
/// Total aggregated units for this filter
pub total_aggregated_units: Option<String>,
/// Amount in cents for this filter
pub amount_cents: i64,
/// Number of events for this filter
pub events_count: i64,
/// Display name for invoices
pub invoice_display_name: Option<String>,
/// Filter values
pub values: serde_json::Value,
}
/// Grouped usage data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GroupedUsage {
/// Units for this group
pub units: String,
/// Total aggregated units for this group
pub total_aggregated_units: Option<String>,
/// Amount in cents for this group
pub amount_cents: i64,
/// Number of events for this group
pub events_count: i64,
/// Grouped by values
pub grouped_by: serde_json::Value,
/// Filters within this group
pub filters: Vec<ChargeFilterUsage>,
}