1use serde::{Deserialize, Serialize};
2
3use crate::models::PaginationParams;
4
5use crate::filters::{common::ListFilters, invoice::InvoiceFilters};
6
7#[derive(Debug, Clone)]
12pub struct ListInvoicesRequest {
13 pub pagination: PaginationParams,
14 pub filters: InvoiceFilters,
15 pub search_term: Option<String>,
17}
18
19impl ListInvoicesRequest {
20 pub fn new() -> Self {
25 Self {
26 pagination: PaginationParams::default(),
27 filters: InvoiceFilters::default(),
28 search_term: None,
29 }
30 }
31
32 pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
40 self.pagination = pagination;
41 self
42 }
43
44 pub fn with_filters(mut self, filters: InvoiceFilters) -> Self {
52 self.filters = filters;
53 self
54 }
55
56 pub fn with_search_term(mut self, term: String) -> Self {
66 self.search_term = Some(term);
67 self
68 }
69
70 pub fn to_query_params(&self) -> Vec<(&str, String)> {
75 let mut params = self.pagination.to_query_params();
76 params.extend(self.filters.to_query_params());
77
78 if let Some(ref term) = self.search_term {
79 params.push(("search_term", term.clone()));
80 }
81
82 params
83 }
84}
85
86impl Default for ListInvoicesRequest {
87 fn default() -> Self {
88 Self::new()
89 }
90}
91
92#[derive(Debug, Clone)]
97pub struct GetInvoiceRequest {
98 pub invoice_id: String,
99}
100
101impl GetInvoiceRequest {
102 pub fn new(invoice_id: String) -> Self {
110 Self { invoice_id }
111 }
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(rename_all = "snake_case")]
117pub enum BillingTime {
118 Anniversary,
120 Calendar,
122}
123
124#[derive(Debug, Clone, Default, Serialize, Deserialize)]
129pub struct InvoicePreviewCustomer {
130 #[serde(skip_serializing_if = "Option::is_none")]
131 pub external_id: Option<String>,
132 #[serde(skip_serializing_if = "Option::is_none")]
133 pub name: Option<String>,
134 #[serde(skip_serializing_if = "Option::is_none")]
135 pub address_line1: Option<String>,
136 #[serde(skip_serializing_if = "Option::is_none")]
137 pub address_line2: Option<String>,
138 #[serde(skip_serializing_if = "Option::is_none")]
139 pub city: Option<String>,
140 #[serde(skip_serializing_if = "Option::is_none")]
141 pub state: Option<String>,
142 #[serde(skip_serializing_if = "Option::is_none")]
143 pub country: Option<String>,
144 #[serde(skip_serializing_if = "Option::is_none")]
145 pub currency: Option<String>,
146 #[serde(skip_serializing_if = "Option::is_none")]
147 pub timezone: Option<String>,
148 #[serde(skip_serializing_if = "Option::is_none")]
149 pub tax_identification_number: Option<String>,
150 #[serde(skip_serializing_if = "Option::is_none")]
151 pub shipping_address: Option<InvoicePreviewAddress>,
152 #[serde(skip_serializing_if = "Option::is_none")]
153 pub integration_customers: Option<Vec<InvoicePreviewIntegrationCustomer>>,
154}
155
156impl InvoicePreviewCustomer {
157 pub fn with_external_id(external_id: String) -> Self {
165 Self {
166 external_id: Some(external_id),
167 ..Default::default()
168 }
169 }
170
171 pub fn new() -> Self {
176 Self::default()
177 }
178
179 pub fn with_name(mut self, name: String) -> Self {
180 self.name = Some(name);
181 self
182 }
183
184 pub fn with_address(
185 mut self,
186 address_line1: String,
187 address_line2: Option<String>,
188 city: Option<String>,
189 state: Option<String>,
190 country: Option<String>,
191 ) -> Self {
192 self.address_line1 = Some(address_line1);
193 self.address_line2 = address_line2;
194 self.city = city;
195 self.state = state;
196 self.country = country;
197 self
198 }
199
200 pub fn with_currency(mut self, currency: String) -> Self {
201 self.currency = Some(currency);
202 self
203 }
204
205 pub fn with_timezone(mut self, timezone: String) -> Self {
206 self.timezone = Some(timezone);
207 self
208 }
209
210 pub fn with_tax_identification_number(mut self, tax_id: String) -> Self {
211 self.tax_identification_number = Some(tax_id);
212 self
213 }
214
215 pub fn with_shipping_address(mut self, address: InvoicePreviewAddress) -> Self {
216 self.shipping_address = Some(address);
217 self
218 }
219
220 pub fn with_integration_customers(
221 mut self,
222 integrations: Vec<InvoicePreviewIntegrationCustomer>,
223 ) -> Self {
224 self.integration_customers = Some(integrations);
225 self
226 }
227}
228
229#[derive(Debug, Clone, Default, Serialize, Deserialize)]
231pub struct InvoicePreviewAddress {
232 #[serde(skip_serializing_if = "Option::is_none")]
233 pub address_line1: Option<String>,
234 #[serde(skip_serializing_if = "Option::is_none")]
235 pub address_line2: Option<String>,
236 #[serde(skip_serializing_if = "Option::is_none")]
237 pub city: Option<String>,
238 #[serde(skip_serializing_if = "Option::is_none")]
239 pub state: Option<String>,
240 #[serde(skip_serializing_if = "Option::is_none")]
241 pub country: Option<String>,
242 #[serde(skip_serializing_if = "Option::is_none")]
243 pub zipcode: Option<String>,
244}
245
246#[derive(Debug, Clone, Serialize, Deserialize)]
248pub struct InvoicePreviewIntegrationCustomer {
249 pub integration_type: String,
250 pub integration_code: String,
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize)]
255pub struct InvoicePreviewCoupon {
256 pub code: String,
257 #[serde(skip_serializing_if = "Option::is_none")]
258 pub name: Option<String>,
259 #[serde(skip_serializing_if = "Option::is_none")]
260 pub coupon_type: Option<InvoicePreviewCouponType>,
261 #[serde(skip_serializing_if = "Option::is_none")]
262 pub amount_cents: Option<i64>,
263 #[serde(skip_serializing_if = "Option::is_none")]
264 pub amount_currency: Option<String>,
265 #[serde(skip_serializing_if = "Option::is_none")]
266 pub percentage_rate: Option<String>,
267 #[serde(skip_serializing_if = "Option::is_none")]
268 pub frequency_duration: Option<i32>,
269}
270
271impl InvoicePreviewCoupon {
272 pub fn new(code: String) -> Self {
280 Self {
281 code,
282 name: None,
283 coupon_type: None,
284 amount_cents: None,
285 amount_currency: None,
286 percentage_rate: None,
287 frequency_duration: None,
288 }
289 }
290
291 pub fn with_name(mut self, name: String) -> Self {
292 self.name = Some(name);
293 self
294 }
295
296 pub fn with_fixed_amount(mut self, amount_cents: i64, currency: String) -> Self {
297 self.coupon_type = Some(InvoicePreviewCouponType::FixedAmount);
298 self.amount_cents = Some(amount_cents);
299 self.amount_currency = Some(currency);
300 self
301 }
302
303 pub fn with_percentage(mut self, percentage_rate: String) -> Self {
304 self.coupon_type = Some(InvoicePreviewCouponType::Percentage);
305 self.percentage_rate = Some(percentage_rate);
306 self
307 }
308
309 pub fn with_frequency_duration(mut self, duration: i32) -> Self {
310 self.frequency_duration = Some(duration);
311 self
312 }
313}
314
315#[derive(Debug, Clone, Serialize, Deserialize)]
317#[serde(rename_all = "snake_case")]
318pub enum InvoicePreviewCouponType {
319 FixedAmount,
320 Percentage,
321}
322
323#[derive(Debug, Clone, Serialize, Deserialize)]
328pub struct InvoicePreviewSubscriptions {
329 pub external_ids: Vec<String>,
330 #[serde(skip_serializing_if = "Option::is_none")]
331 pub plan_code: Option<String>,
332 #[serde(skip_serializing_if = "Option::is_none")]
333 pub terminated_at: Option<String>,
334}
335
336impl InvoicePreviewSubscriptions {
337 pub fn new(external_ids: Vec<String>) -> Self {
345 Self {
346 external_ids,
347 plan_code: None,
348 terminated_at: None,
349 }
350 }
351
352 pub fn with_plan_code(mut self, plan_code: String) -> Self {
353 self.plan_code = Some(plan_code);
354 self
355 }
356
357 pub fn with_terminated_at(mut self, terminated_at: String) -> Self {
358 self.terminated_at = Some(terminated_at);
359 self
360 }
361}
362
363#[derive(Debug, Clone, Default, Serialize, Deserialize)]
368pub struct InvoicePreviewInput {
369 pub customer: InvoicePreviewCustomer,
370 #[serde(skip_serializing_if = "Option::is_none")]
371 pub plan_code: Option<String>,
372 #[serde(skip_serializing_if = "Option::is_none")]
373 pub subscription_at: Option<String>,
374 #[serde(skip_serializing_if = "Option::is_none")]
375 pub billing_time: Option<BillingTime>,
376 #[serde(skip_serializing_if = "Option::is_none")]
377 pub coupons: Option<Vec<InvoicePreviewCoupon>>,
378 #[serde(skip_serializing_if = "Option::is_none")]
379 pub subscriptions: Option<InvoicePreviewSubscriptions>,
380 #[serde(skip_serializing_if = "Option::is_none")]
381 pub billing_entity_code: Option<String>,
382}
383
384impl InvoicePreviewInput {
385 pub fn new(customer: InvoicePreviewCustomer) -> Self {
393 Self {
394 customer,
395 ..Default::default()
396 }
397 }
398
399 pub fn for_customer(external_id: String) -> Self {
407 Self::new(InvoicePreviewCustomer::with_external_id(external_id))
408 }
409
410 pub fn with_plan_code(mut self, plan_code: String) -> Self {
411 self.plan_code = Some(plan_code);
412 self
413 }
414
415 pub fn with_subscription_at(mut self, subscription_at: String) -> Self {
416 self.subscription_at = Some(subscription_at);
417 self
418 }
419
420 pub fn with_billing_time(mut self, billing_time: BillingTime) -> Self {
421 self.billing_time = Some(billing_time);
422 self
423 }
424
425 pub fn with_coupons(mut self, coupons: Vec<InvoicePreviewCoupon>) -> Self {
426 self.coupons = Some(coupons);
427 self
428 }
429
430 pub fn with_subscriptions(mut self, subscriptions: InvoicePreviewSubscriptions) -> Self {
431 self.subscriptions = Some(subscriptions);
432 self
433 }
434
435 pub fn with_billing_entity_code(mut self, code: String) -> Self {
436 self.billing_entity_code = Some(code);
437 self
438 }
439}
440
441#[derive(Debug, Clone, Serialize, Deserialize)]
445pub struct InvoicePreviewRequest {
446 #[serde(flatten)]
447 pub input: InvoicePreviewInput,
448}
449
450impl InvoicePreviewRequest {
451 pub fn new(input: InvoicePreviewInput) -> Self {
459 Self { input }
460 }
461}
462
463#[derive(Debug, Clone, Serialize, Deserialize)]
468pub struct CreateInvoiceFeeInput {
469 pub add_on_code: String,
471 pub units: f64,
473 #[serde(skip_serializing_if = "Option::is_none")]
475 pub unit_amount_cents: Option<i64>,
476 #[serde(skip_serializing_if = "Option::is_none")]
478 pub description: Option<String>,
479 #[serde(skip_serializing_if = "Option::is_none")]
481 pub tax_codes: Option<Vec<String>>,
482}
483
484impl CreateInvoiceFeeInput {
485 pub fn new(add_on_code: String, units: f64) -> Self {
494 Self {
495 add_on_code,
496 units,
497 unit_amount_cents: None,
498 description: None,
499 tax_codes: None,
500 }
501 }
502
503 pub fn with_unit_amount_cents(mut self, unit_amount_cents: i64) -> Self {
505 self.unit_amount_cents = Some(unit_amount_cents);
506 self
507 }
508
509 pub fn with_description(mut self, description: String) -> Self {
511 self.description = Some(description);
512 self
513 }
514
515 pub fn with_tax_codes(mut self, tax_codes: Vec<String>) -> Self {
517 self.tax_codes = Some(tax_codes);
518 self
519 }
520}
521
522#[derive(Debug, Clone, Serialize, Deserialize)]
527pub struct CreateInvoiceInput {
528 pub external_customer_id: String,
530 pub currency: String,
532 pub fees: Vec<CreateInvoiceFeeInput>,
534}
535
536impl CreateInvoiceInput {
537 pub fn new(
547 external_customer_id: String,
548 currency: String,
549 fees: Vec<CreateInvoiceFeeInput>,
550 ) -> Self {
551 Self {
552 external_customer_id,
553 currency,
554 fees,
555 }
556 }
557}
558
559#[derive(Debug, Clone, Serialize, Deserialize)]
561pub struct CreateInvoiceRequest {
562 pub invoice: CreateInvoiceInput,
564}
565
566impl CreateInvoiceRequest {
567 pub fn new(input: CreateInvoiceInput) -> Self {
575 Self { invoice: input }
576 }
577}
578
579#[derive(Debug, Clone, Serialize, Deserialize)]
581pub struct UpdateInvoiceMetadataInput {
582 #[serde(skip_serializing_if = "Option::is_none")]
584 pub id: Option<String>,
585 pub key: String,
587 pub value: String,
589}
590
591impl UpdateInvoiceMetadataInput {
592 pub fn new(key: String, value: String) -> Self {
601 Self {
602 id: None,
603 key,
604 value,
605 }
606 }
607
608 pub fn with_id(id: String, key: String, value: String) -> Self {
618 Self {
619 id: Some(id),
620 key,
621 value,
622 }
623 }
624}
625
626#[derive(Debug, Clone, Default, Serialize, Deserialize)]
630pub struct UpdateInvoiceInput {
631 #[serde(skip_serializing_if = "Option::is_none")]
633 pub payment_status: Option<String>,
634 #[serde(skip_serializing_if = "Option::is_none")]
636 pub metadata: Option<Vec<UpdateInvoiceMetadataInput>>,
637}
638
639impl UpdateInvoiceInput {
640 pub fn new() -> Self {
642 Self::default()
643 }
644
645 pub fn with_payment_status(mut self, payment_status: String) -> Self {
650 self.payment_status = Some(payment_status);
651 self
652 }
653
654 pub fn with_metadata(mut self, metadata: Vec<UpdateInvoiceMetadataInput>) -> Self {
656 self.metadata = Some(metadata);
657 self
658 }
659}
660
661#[derive(Debug, Clone, Serialize, Deserialize)]
663pub struct UpdateInvoiceRequest {
664 #[serde(skip)]
666 pub lago_id: String,
667 pub invoice: UpdateInvoiceInput,
669}
670
671impl UpdateInvoiceRequest {
672 pub fn new(lago_id: String, input: UpdateInvoiceInput) -> Self {
681 Self {
682 lago_id,
683 invoice: input,
684 }
685 }
686}
687
688#[derive(Debug, Clone)]
693pub struct ListCustomerInvoicesRequest {
694 pub external_customer_id: String,
696 pub pagination: PaginationParams,
698 pub filters: InvoiceFilters,
700 pub search_term: Option<String>,
702}
703
704impl ListCustomerInvoicesRequest {
705 pub fn new(external_customer_id: String) -> Self {
713 Self {
714 external_customer_id,
715 pagination: PaginationParams::default(),
716 filters: InvoiceFilters::default(),
717 search_term: None,
718 }
719 }
720
721 pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
723 self.pagination = pagination;
724 self
725 }
726
727 pub fn with_filters(mut self, filters: InvoiceFilters) -> Self {
729 self.filters = filters;
730 self
731 }
732
733 pub fn with_search_term(mut self, term: String) -> Self {
737 self.search_term = Some(term);
738 self
739 }
740
741 pub fn to_query_params(&self) -> Vec<(&str, String)> {
743 let mut params = self.pagination.to_query_params();
744 params.extend(self.filters.to_query_params());
745
746 if let Some(ref term) = self.search_term {
747 params.push(("search_term", term.clone()));
748 }
749
750 params
751 }
752}
753
754#[derive(Debug, Clone)]
758pub struct RefreshInvoiceRequest {
759 pub lago_id: String,
761}
762
763impl RefreshInvoiceRequest {
764 pub fn new(lago_id: String) -> Self {
772 Self { lago_id }
773 }
774}
775
776#[derive(Debug, Clone)]
780pub struct DownloadInvoiceRequest {
781 pub lago_id: String,
783}
784
785impl DownloadInvoiceRequest {
786 pub fn new(lago_id: String) -> Self {
794 Self { lago_id }
795 }
796}
797
798#[derive(Debug, Clone)]
802pub struct RetryInvoiceRequest {
803 pub lago_id: String,
805}
806
807impl RetryInvoiceRequest {
808 pub fn new(lago_id: String) -> Self {
816 Self { lago_id }
817 }
818}
819
820#[derive(Debug, Clone)]
824pub struct RetryInvoicePaymentRequest {
825 pub lago_id: String,
827}
828
829impl RetryInvoicePaymentRequest {
830 pub fn new(lago_id: String) -> Self {
838 Self { lago_id }
839 }
840}
841
842#[derive(Debug, Clone)]
847pub struct VoidInvoiceRequest {
848 pub lago_id: String,
850}
851
852impl VoidInvoiceRequest {
853 pub fn new(lago_id: String) -> Self {
861 Self { lago_id }
862 }
863}