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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use strum_macros::EnumString;
use uuid::Uuid;
use crate::models::{FixedCharge, UsageThreshold};
/// Represents a plan in the Lago billing system.
///
/// A plan defines pricing configuration that can be assigned to customers
/// through subscriptions.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Plan {
/// Unique identifier for the plan in Lago.
pub lago_id: Uuid,
/// Name of the plan.
pub name: String,
/// Display name for invoices.
pub invoice_display_name: Option<String>,
/// When the plan was created.
pub created_at: DateTime<Utc>,
/// Unique code for the plan.
pub code: String,
/// Billing interval (weekly, monthly, quarterly, yearly).
pub interval: PlanInterval,
/// Description of the plan.
pub description: Option<String>,
/// Base amount in cents.
pub amount_cents: i64,
/// Currency for the amount.
pub amount_currency: String,
/// Trial period in days.
pub trial_period: Option<f64>,
/// Whether the plan is billed in advance.
pub pay_in_advance: bool,
/// Whether charges are billed monthly for yearly plans.
pub bill_charges_monthly: Option<bool>,
/// Number of active subscriptions using this plan.
pub active_subscriptions_count: Option<i32>,
/// Number of draft invoices for this plan.
pub draft_invoices_count: Option<i32>,
/// Parent plan ID (for plan overrides).
pub parent_id: Option<Uuid>,
/// Charges associated with this plan.
pub charges: Option<Vec<PlanCharge>>,
/// Fixed charges associated with this plan.
pub fixed_charges: Option<Vec<FixedCharge>>,
/// Taxes associated with this plan.
pub taxes: Option<Vec<PlanTax>>,
/// Minimum commitment for this plan.
pub minimum_commitment: Option<PlanMinimumCommitment>,
/// Usage thresholds for progressive billing.
pub usage_thresholds: Option<Vec<UsageThreshold>>,
}
/// Billing interval for a plan.
#[derive(Debug, Clone, Serialize, Deserialize, EnumString, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum PlanInterval {
/// Weekly billing.
Weekly,
/// Monthly billing.
Monthly,
/// Quarterly billing.
Quarterly,
/// Semi-annual billing.
Semiannual,
/// Yearly billing.
Yearly,
}
/// Charge model types.
#[derive(Debug, Clone, Serialize, Deserialize, EnumString, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum ChargeModel {
/// Standard pricing model.
Standard,
/// Graduated pricing model.
Graduated,
/// Volume pricing model.
Volume,
/// Package pricing model.
Package,
/// Percentage pricing model.
Percentage,
/// Graduated percentage pricing model.
GraduatedPercentage,
/// Dynamic pricing model.
Dynamic,
}
/// Represents a charge in a plan.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlanCharge {
/// Unique identifier for the charge in Lago.
pub lago_id: Option<Uuid>,
/// The Lago ID of the billable metric.
pub lago_billable_metric_id: Option<Uuid>,
/// The billable metric ID to reference.
pub billable_metric_id: Option<Uuid>,
/// The code of the billable metric.
pub billable_metric_code: Option<String>,
/// Unique code for the charge.
pub code: Option<String>,
/// When the charge was created.
pub created_at: Option<DateTime<Utc>>,
/// The charge model to use.
pub charge_model: ChargeModel,
/// Whether the charge is invoiceable.
pub invoiceable: Option<bool>,
/// Display name for the charge on invoices.
pub invoice_display_name: Option<String>,
/// Whether the charge is billed in advance.
pub pay_in_advance: Option<bool>,
/// Whether the charge is prorated.
pub prorated: Option<bool>,
/// Minimum amount in cents for this charge.
pub min_amount_cents: Option<i64>,
/// Charge properties (model-specific configuration).
pub properties: Option<serde_json::Value>,
/// Tax codes for this charge.
pub tax_codes: Option<Vec<String>>,
/// Taxes applied to this charge.
pub taxes: Option<Vec<PlanTax>>,
/// Filters for differentiated pricing.
pub filters: Option<Vec<ChargeFilter>>,
/// The regroup paid fees option.
pub regroup_paid_fees: Option<String>,
/// Applied pricing unit for this charge.
pub applied_pricing_unit: Option<serde_json::Value>,
/// Whether the charge accepts a target wallet.
pub accepts_target_wallet: Option<bool>,
}
/// Represents a charge filter for differentiated pricing.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChargeFilter {
/// Invoice display name for this filter.
pub invoice_display_name: Option<String>,
/// Filter properties.
pub properties: Option<serde_json::Value>,
/// Filter values mapping.
pub values: Option<serde_json::Value>,
}
/// Represents a tax applied to a plan or charge.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlanTax {
/// Unique identifier for the tax in Lago.
pub lago_id: Option<Uuid>,
/// Name of the tax.
pub name: Option<String>,
/// Code for the tax.
pub code: Option<String>,
/// Tax rate (percentage).
pub rate: Option<f64>,
/// Description of the tax.
pub description: Option<String>,
/// Whether tax is applied by default.
pub applied_to_organization: Option<bool>,
}
/// Minimum commitment for a plan.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlanMinimumCommitment {
/// Unique identifier in Lago.
pub lago_id: Option<Uuid>,
/// Plan ID this commitment belongs to.
pub plan_code: Option<String>,
/// Minimum commitment amount in cents.
pub amount_cents: Option<i64>,
/// Invoice display name for the minimum commitment.
pub invoice_display_name: Option<String>,
/// When the commitment was created.
pub created_at: Option<DateTime<Utc>>,
/// When the commitment was last updated.
pub updated_at: Option<DateTime<Utc>>,
/// Tax codes for the minimum commitment.
pub tax_codes: Option<Vec<String>>,
/// Taxes applied to the minimum commitment.
pub taxes: Option<Vec<PlanTax>>,
}