lago_types/requests/
credit_note.rs1use serde::{Deserialize, Serialize};
2
3use crate::filters::common::ListFilters;
4use crate::filters::credit_note::CreditNoteFilter;
5use crate::models::{CreditNoteReason, CreditNoteRefundStatus, PaginationParams};
6
7#[derive(Debug, Clone)]
9pub struct ListCreditNotesRequest {
10 pub pagination: PaginationParams,
11 pub filters: CreditNoteFilter,
12}
13
14impl ListCreditNotesRequest {
15 pub fn new() -> Self {
17 Self {
18 pagination: PaginationParams::default(),
19 filters: CreditNoteFilter::default(),
20 }
21 }
22
23 pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
25 self.pagination = pagination;
26 self
27 }
28
29 pub fn with_filters(mut self, filters: CreditNoteFilter) -> Self {
31 self.filters = filters;
32 self
33 }
34
35 pub fn to_query_params(&self) -> Vec<(&str, String)> {
37 let mut params = self.pagination.to_query_params();
38 params.extend(self.filters.to_query_params());
39 params
40 }
41}
42
43impl Default for ListCreditNotesRequest {
44 fn default() -> Self {
45 Self::new()
46 }
47}
48
49#[derive(Debug, Clone)]
51pub struct GetCreditNoteRequest {
52 pub lago_id: String,
54}
55
56impl GetCreditNoteRequest {
57 pub fn new(lago_id: String) -> Self {
59 Self { lago_id }
60 }
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct CreateCreditNoteItemInput {
66 pub fee_id: String,
68 pub amount_cents: i64,
70}
71
72impl CreateCreditNoteItemInput {
73 pub fn new(fee_id: String, amount_cents: i64) -> Self {
75 Self {
76 fee_id,
77 amount_cents,
78 }
79 }
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct CreateCreditNoteInput {
85 pub invoice_id: String,
87 pub reason: CreditNoteReason,
89 #[serde(skip_serializing_if = "Option::is_none")]
91 pub description: Option<String>,
92 pub credit_amount_cents: i64,
94 pub refund_amount_cents: i64,
96 pub items: Vec<CreateCreditNoteItemInput>,
98}
99
100impl CreateCreditNoteInput {
101 pub fn new(
110 invoice_id: String,
111 reason: CreditNoteReason,
112 credit_amount_cents: i64,
113 refund_amount_cents: i64,
114 items: Vec<CreateCreditNoteItemInput>,
115 ) -> Self {
116 Self {
117 invoice_id,
118 reason,
119 description: None,
120 credit_amount_cents,
121 refund_amount_cents,
122 items,
123 }
124 }
125
126 pub fn with_description(mut self, description: String) -> Self {
128 self.description = Some(description);
129 self
130 }
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
135pub struct CreateCreditNoteRequest {
136 pub credit_note: CreateCreditNoteInput,
137}
138
139impl CreateCreditNoteRequest {
140 pub fn new(credit_note: CreateCreditNoteInput) -> Self {
142 Self { credit_note }
143 }
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct UpdateCreditNoteInput {
149 #[serde(skip_serializing_if = "Option::is_none")]
151 pub refund_status: Option<CreditNoteRefundStatus>,
152}
153
154impl UpdateCreditNoteInput {
155 pub fn new() -> Self {
157 Self {
158 refund_status: None,
159 }
160 }
161
162 pub fn with_refund_status(mut self, status: CreditNoteRefundStatus) -> Self {
164 self.refund_status = Some(status);
165 self
166 }
167}
168
169impl Default for UpdateCreditNoteInput {
170 fn default() -> Self {
171 Self::new()
172 }
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct UpdateCreditNoteRequest {
178 #[serde(skip)]
180 pub lago_id: String,
181 pub credit_note: UpdateCreditNoteInput,
183}
184
185impl UpdateCreditNoteRequest {
186 pub fn new(lago_id: String, input: UpdateCreditNoteInput) -> Self {
188 Self {
189 lago_id,
190 credit_note: input,
191 }
192 }
193}