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
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use strum_macros::{Display, EnumString};
use uuid::Uuid;
/// Represents a credit note in the Lago billing system.
///
/// Credit notes are issued to refund or credit customers for invoices,
/// either partially or in full.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreditNote {
/// Unique identifier for the credit note in Lago
pub lago_id: Uuid,
/// Sequential identifier for the credit note
pub sequential_id: i32,
/// Credit note number (e.g., "LAG-1234-CN-001")
pub number: String,
/// Lago ID of the related invoice
pub lago_invoice_id: Uuid,
/// Number of the related invoice
pub invoice_number: String,
/// Purchase order number of the related invoice
pub purchase_order_number: Option<String>,
/// Date when the credit note was issued
pub issuing_date: String,
/// Status of the credit (available, consumed, voided)
pub credit_status: Option<CreditNoteCreditStatus>,
/// Status of the refund (pending, succeeded, failed)
pub refund_status: Option<CreditNoteRefundStatus>,
/// Reason for the credit note
pub reason: CreditNoteReason,
/// Optional description for the credit note
pub description: Option<String>,
/// Currency code (ISO 4217)
pub currency: String,
/// Total amount in cents
pub total_amount_cents: i64,
/// Tax amount in cents
pub taxes_amount_cents: i64,
/// Tax rate percentage
pub taxes_rate: f64,
/// Subtotal excluding taxes in cents
pub sub_total_excluding_taxes_amount_cents: i64,
/// Remaining balance in cents
pub balance_amount_cents: i64,
/// Credit amount in cents
pub credit_amount_cents: i64,
/// Refund amount in cents
pub refund_amount_cents: i64,
/// Coupon adjustment amount in cents
pub coupons_adjustment_amount_cents: i64,
/// URL to the generated PDF file
pub file_url: Option<String>,
/// Whether this is a self-billed credit note
pub self_billed: Option<bool>,
/// Creation timestamp
pub created_at: DateTime<Utc>,
/// Last update timestamp
pub updated_at: DateTime<Utc>,
/// Line items for the credit note
pub items: Option<Vec<CreditNoteItem>>,
/// Applied taxes
pub applied_taxes: Option<Vec<CreditNoteAppliedTax>>,
}
/// Status of the credit on a credit note
#[derive(Debug, Clone, Serialize, Deserialize, Display, EnumString, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum CreditNoteCreditStatus {
Available,
Consumed,
Voided,
}
/// Status of a refund on a credit note
#[derive(Debug, Clone, Serialize, Deserialize, Display, EnumString, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum CreditNoteRefundStatus {
Pending,
Succeeded,
Failed,
}
/// Reason for issuing a credit note
#[derive(Debug, Clone, Serialize, Deserialize, Display, EnumString, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum CreditNoteReason {
DuplicatedCharge,
ProductUnsatisfactory,
OrderChange,
OrderCancellation,
FraudulentCharge,
Other,
}
/// A line item in a credit note
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreditNoteItem {
/// Unique identifier for the item
pub lago_id: Uuid,
/// Amount in cents for this item
pub amount_cents: i64,
/// Currency for the amount
pub amount_currency: String,
/// The associated fee object
pub fee: Option<Value>,
}
/// Tax applied to a credit note
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreditNoteAppliedTax {
/// Unique identifier for the applied tax
pub lago_id: Option<Uuid>,
/// Reference to the tax definition
pub lago_tax_id: Option<Uuid>,
/// Reference to the parent credit note
pub lago_credit_note_id: Option<Uuid>,
/// Name of the tax
pub tax_name: Option<String>,
/// Code of the tax
pub tax_code: Option<String>,
/// Tax rate percentage
pub tax_rate: Option<f64>,
/// Description of the tax
pub tax_description: Option<String>,
/// Tax amount in cents
pub amount_cents: Option<i64>,
/// Currency for the tax amount
pub amount_currency: Option<String>,
/// Base amount the tax was calculated on
pub base_amount_cents: Option<i64>,
/// Creation timestamp
pub created_at: Option<DateTime<Utc>>,
}