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 pub search_term: Option<String>,
14}
15
16impl ListCreditNotesRequest {
17 pub fn new() -> Self {
19 Self {
20 pagination: PaginationParams::default(),
21 filters: CreditNoteFilter::default(),
22 search_term: None,
23 }
24 }
25
26 pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
28 self.pagination = pagination;
29 self
30 }
31
32 pub fn with_filters(mut self, filters: CreditNoteFilter) -> Self {
34 self.filters = filters;
35 self
36 }
37
38 pub fn with_search_term(mut self, term: String) -> Self {
42 self.search_term = Some(term);
43 self
44 }
45
46 pub fn to_query_params(&self) -> Vec<(&str, String)> {
48 let mut params = self.pagination.to_query_params();
49 params.extend(self.filters.to_query_params());
50
51 if let Some(ref term) = self.search_term {
52 params.push(("search_term", term.clone()));
53 }
54
55 params
56 }
57}
58
59impl Default for ListCreditNotesRequest {
60 fn default() -> Self {
61 Self::new()
62 }
63}
64
65#[derive(Debug, Clone)]
67pub struct GetCreditNoteRequest {
68 pub lago_id: String,
70}
71
72impl GetCreditNoteRequest {
73 pub fn new(lago_id: String) -> Self {
75 Self { lago_id }
76 }
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct CreateCreditNoteItemInput {
82 pub fee_id: String,
84 pub amount_cents: i64,
86}
87
88impl CreateCreditNoteItemInput {
89 pub fn new(fee_id: String, amount_cents: i64) -> Self {
91 Self {
92 fee_id,
93 amount_cents,
94 }
95 }
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct CreateCreditNoteInput {
101 pub invoice_id: String,
103 pub reason: CreditNoteReason,
105 #[serde(skip_serializing_if = "Option::is_none")]
107 pub description: Option<String>,
108 pub credit_amount_cents: i64,
110 pub refund_amount_cents: i64,
112 pub items: Vec<CreateCreditNoteItemInput>,
114}
115
116impl CreateCreditNoteInput {
117 pub fn new(
126 invoice_id: String,
127 reason: CreditNoteReason,
128 credit_amount_cents: i64,
129 refund_amount_cents: i64,
130 items: Vec<CreateCreditNoteItemInput>,
131 ) -> Self {
132 Self {
133 invoice_id,
134 reason,
135 description: None,
136 credit_amount_cents,
137 refund_amount_cents,
138 items,
139 }
140 }
141
142 pub fn with_description(mut self, description: String) -> Self {
144 self.description = Some(description);
145 self
146 }
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct CreateCreditNoteRequest {
152 pub credit_note: CreateCreditNoteInput,
153}
154
155impl CreateCreditNoteRequest {
156 pub fn new(credit_note: CreateCreditNoteInput) -> Self {
158 Self { credit_note }
159 }
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize)]
164pub struct UpdateCreditNoteInput {
165 #[serde(skip_serializing_if = "Option::is_none")]
167 pub refund_status: Option<CreditNoteRefundStatus>,
168}
169
170impl UpdateCreditNoteInput {
171 pub fn new() -> Self {
173 Self {
174 refund_status: None,
175 }
176 }
177
178 pub fn with_refund_status(mut self, status: CreditNoteRefundStatus) -> Self {
180 self.refund_status = Some(status);
181 self
182 }
183}
184
185impl Default for UpdateCreditNoteInput {
186 fn default() -> Self {
187 Self::new()
188 }
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
193pub struct UpdateCreditNoteRequest {
194 #[serde(skip)]
196 pub lago_id: String,
197 pub credit_note: UpdateCreditNoteInput,
199}
200
201impl UpdateCreditNoteRequest {
202 pub fn new(lago_id: String, input: UpdateCreditNoteInput) -> Self {
204 Self {
205 lago_id,
206 credit_note: input,
207 }
208 }
209}