lago_types/models/
credit_note.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use strum_macros::{Display, EnumString};
5use uuid::Uuid;
6
7/// Represents a credit note in the Lago billing system.
8///
9/// Credit notes are issued to refund or credit customers for invoices,
10/// either partially or in full.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct CreditNote {
13    /// Unique identifier for the credit note in Lago
14    pub lago_id: Uuid,
15    /// Sequential identifier for the credit note
16    pub sequential_id: i32,
17    /// Credit note number (e.g., "LAG-1234-CN-001")
18    pub number: String,
19    /// Lago ID of the related invoice
20    pub lago_invoice_id: Uuid,
21    /// Number of the related invoice
22    pub invoice_number: String,
23    /// Date when the credit note was issued
24    pub issuing_date: String,
25    /// Status of the credit (available, consumed, voided)
26    pub credit_status: Option<CreditNoteCreditStatus>,
27    /// Status of the refund (pending, succeeded, failed)
28    pub refund_status: Option<CreditNoteRefundStatus>,
29    /// Reason for the credit note
30    pub reason: CreditNoteReason,
31    /// Optional description for the credit note
32    pub description: Option<String>,
33    /// Currency code (ISO 4217)
34    pub currency: String,
35    /// Total amount in cents
36    pub total_amount_cents: i64,
37    /// Tax amount in cents
38    pub taxes_amount_cents: i64,
39    /// Tax rate percentage
40    pub taxes_rate: f64,
41    /// Subtotal excluding taxes in cents
42    pub sub_total_excluding_taxes_amount_cents: i64,
43    /// Remaining balance in cents
44    pub balance_amount_cents: i64,
45    /// Credit amount in cents
46    pub credit_amount_cents: i64,
47    /// Refund amount in cents
48    pub refund_amount_cents: i64,
49    /// Coupon adjustment amount in cents
50    pub coupons_adjustment_amount_cents: i64,
51    /// URL to the generated PDF file
52    pub file_url: Option<String>,
53    /// Whether this is a self-billed credit note
54    pub self_billed: Option<bool>,
55    /// Creation timestamp
56    pub created_at: DateTime<Utc>,
57    /// Last update timestamp
58    pub updated_at: DateTime<Utc>,
59    /// Line items for the credit note
60    pub items: Option<Vec<CreditNoteItem>>,
61    /// Applied taxes
62    pub applied_taxes: Option<Vec<CreditNoteAppliedTax>>,
63}
64
65/// Status of the credit on a credit note
66#[derive(Debug, Clone, Serialize, Deserialize, Display, EnumString, PartialEq, Eq)]
67#[serde(rename_all = "snake_case")]
68#[strum(serialize_all = "snake_case")]
69pub enum CreditNoteCreditStatus {
70    Available,
71    Consumed,
72    Voided,
73}
74
75/// Status of a refund on a credit note
76#[derive(Debug, Clone, Serialize, Deserialize, Display, EnumString, PartialEq, Eq)]
77#[serde(rename_all = "snake_case")]
78#[strum(serialize_all = "snake_case")]
79pub enum CreditNoteRefundStatus {
80    Pending,
81    Succeeded,
82    Failed,
83}
84
85/// Reason for issuing a credit note
86#[derive(Debug, Clone, Serialize, Deserialize, Display, EnumString, PartialEq, Eq)]
87#[serde(rename_all = "snake_case")]
88#[strum(serialize_all = "snake_case")]
89pub enum CreditNoteReason {
90    DuplicatedCharge,
91    ProductUnsatisfactory,
92    OrderChange,
93    OrderCancellation,
94    FraudulentCharge,
95    Other,
96}
97
98/// A line item in a credit note
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct CreditNoteItem {
101    /// Unique identifier for the item
102    pub lago_id: Uuid,
103    /// Amount in cents for this item
104    pub amount_cents: i64,
105    /// Currency for the amount
106    pub amount_currency: String,
107    /// The associated fee object
108    pub fee: Option<Value>,
109}
110
111/// Tax applied to a credit note
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct CreditNoteAppliedTax {
114    /// Unique identifier for the applied tax
115    pub lago_id: Option<Uuid>,
116    /// Reference to the tax definition
117    pub lago_tax_id: Option<Uuid>,
118    /// Reference to the parent credit note
119    pub lago_credit_note_id: Option<Uuid>,
120    /// Name of the tax
121    pub tax_name: Option<String>,
122    /// Code of the tax
123    pub tax_code: Option<String>,
124    /// Tax rate percentage
125    pub tax_rate: Option<f64>,
126    /// Description of the tax
127    pub tax_description: Option<String>,
128    /// Tax amount in cents
129    pub amount_cents: Option<i64>,
130    /// Currency for the tax amount
131    pub amount_currency: Option<String>,
132    /// Base amount the tax was calculated on
133    pub base_amount_cents: Option<i64>,
134    /// Creation timestamp
135    pub created_at: Option<DateTime<Utc>>,
136}