Skip to main content

lago_types/requests/
invoice.rs

1use serde::{Deserialize, Serialize};
2
3use crate::models::PaginationParams;
4
5use crate::filters::{common::ListFilters, invoice::InvoiceFilters};
6
7/// Request parameters for listing invoices.
8///
9/// This struct combines pagination parameters and invoice-specific filters
10/// to build a comprehensive request for retrieving invoice lists.
11#[derive(Debug, Clone)]
12pub struct ListInvoicesRequest {
13    pub pagination: PaginationParams,
14    pub filters: InvoiceFilters,
15    /// Search by id, number, customer name, external_id or email.
16    pub search_term: Option<String>,
17}
18
19impl ListInvoicesRequest {
20    /// Creates a new empty list invoices request.
21    ///
22    /// # Returns
23    /// A new `ListInvoicesRequest` instance with default pagination and no filters.
24    pub fn new() -> Self {
25        Self {
26            pagination: PaginationParams::default(),
27            filters: InvoiceFilters::default(),
28            search_term: None,
29        }
30    }
31
32    /// Sets the pagination parameters for the request.
33    ///
34    /// # Arguments
35    /// * `pagination` - The pagination parameters to use
36    ///
37    /// # Returns
38    /// The modified request instance for method chaining.
39    pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
40        self.pagination = pagination;
41        self
42    }
43
44    /// Sets the invoice filters for the request.
45    ///
46    /// # Arguments
47    /// * `filters` - The invoice filters to apply
48    ///
49    /// # Returns
50    /// The modified request instance for method chaining.
51    pub fn with_filters(mut self, filters: InvoiceFilters) -> Self {
52        self.filters = filters;
53        self
54    }
55
56    /// Sets the search term for the request.
57    ///
58    /// Search by id, number, customer name, external_id or email.
59    ///
60    /// # Arguments
61    /// * `term` - The search term
62    ///
63    /// # Returns
64    /// The modified request instance for method chaining.
65    pub fn with_search_term(mut self, term: String) -> Self {
66        self.search_term = Some(term);
67        self
68    }
69
70    /// Converts the request parameters into HTTP query parameters.
71    ///
72    /// # Returns
73    /// A vector of query parameter tuples containing both pagination and filter criteria.
74    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/// Request parameters for retrieving a specific invoice.
93///
94/// This struct contains the identifier needed to fetch a single invoice
95/// from the API.
96#[derive(Debug, Clone)]
97pub struct GetInvoiceRequest {
98    pub invoice_id: String,
99}
100
101impl GetInvoiceRequest {
102    /// Creates a new get invoice request.
103    ///
104    /// # Arguments
105    /// * `invoice_id` - The unique identifier of the invoice to retrieve
106    ///
107    /// # Returns
108    /// A new `GetInvoiceRequest` instance with the specified invoice ID.
109    pub fn new(invoice_id: String) -> Self {
110        Self { invoice_id }
111    }
112}
113
114/// Billing time determines when recurring billing cycles occur.
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(rename_all = "snake_case")]
117pub enum BillingTime {
118    /// Billing cycle based on the specific date the subscription started (billed fully).
119    Anniversary,
120    /// Billing cycle at the first day of the week/month/year (billed with proration).
121    Calendar,
122}
123
124/// Customer information for invoice preview.
125///
126/// This struct contains customer data used when generating an invoice preview.
127/// It can reference an existing customer via external_id or provide inline customer details.
128#[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    /// Creates a new invoice preview customer with an external ID.
158    ///
159    /// # Arguments
160    /// * `external_id` - The unique external identifier for the customer
161    ///
162    /// # Returns
163    /// A new `InvoicePreviewCustomer` instance
164    pub fn with_external_id(external_id: String) -> Self {
165        Self {
166            external_id: Some(external_id),
167            ..Default::default()
168        }
169    }
170
171    /// Creates a new empty invoice preview customer for inline definition.
172    ///
173    /// # Returns
174    /// A new empty `InvoicePreviewCustomer` instance
175    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/// Address information for invoice preview.
230#[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/// Integration customer for tax providers like Anrok.
247#[derive(Debug, Clone, Serialize, Deserialize)]
248pub struct InvoicePreviewIntegrationCustomer {
249    pub integration_type: String,
250    pub integration_code: String,
251}
252
253/// Coupon information for invoice preview.
254#[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    /// Creates a new coupon with the required code.
273    ///
274    /// # Arguments
275    /// * `code` - The unique code for the coupon
276    ///
277    /// # Returns
278    /// A new `InvoicePreviewCoupon` instance
279    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/// Type of coupon discount.
316#[derive(Debug, Clone, Serialize, Deserialize)]
317#[serde(rename_all = "snake_case")]
318pub enum InvoicePreviewCouponType {
319    FixedAmount,
320    Percentage,
321}
322
323/// Subscription information for invoice preview.
324///
325/// Used to specify existing subscriptions to include in the preview,
326/// with optional plan changes or termination.
327#[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    /// Creates a new subscriptions object with the required external IDs.
338    ///
339    /// # Arguments
340    /// * `external_ids` - The external identifiers of the subscriptions
341    ///
342    /// # Returns
343    /// A new `InvoicePreviewSubscriptions` instance
344    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/// Input parameters for previewing an invoice.
364///
365/// This struct contains all the information needed to generate an invoice preview
366/// without actually creating the invoice.
367#[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    /// Creates a new invoice preview input with a customer reference.
386    ///
387    /// # Arguments
388    /// * `customer` - The customer information for the preview
389    ///
390    /// # Returns
391    /// A new `InvoicePreviewInput` instance
392    pub fn new(customer: InvoicePreviewCustomer) -> Self {
393        Self {
394            customer,
395            ..Default::default()
396        }
397    }
398
399    /// Creates an invoice preview for an existing customer.
400    ///
401    /// # Arguments
402    /// * `external_id` - The external ID of the existing customer
403    ///
404    /// # Returns
405    /// A new `InvoicePreviewInput` instance
406    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/// Request parameters for previewing an invoice.
442///
443/// This struct wraps the invoice preview input in the expected API format.
444#[derive(Debug, Clone, Serialize, Deserialize)]
445pub struct InvoicePreviewRequest {
446    #[serde(flatten)]
447    pub input: InvoicePreviewInput,
448}
449
450impl InvoicePreviewRequest {
451    /// Creates a new preview invoice request.
452    ///
453    /// # Arguments
454    /// * `input` - The invoice preview input data
455    ///
456    /// # Returns
457    /// A new `InvoicePreviewRequest` instance
458    pub fn new(input: InvoicePreviewInput) -> Self {
459        Self { input }
460    }
461}
462
463/// Fee input for creating a one-off invoice.
464///
465/// This struct contains the details for a single fee line item
466/// to be included in a one-off invoice.
467#[derive(Debug, Clone, Serialize, Deserialize)]
468pub struct CreateInvoiceFeeInput {
469    /// The code of the add-on to charge.
470    pub add_on_code: String,
471    /// The number of units to charge.
472    pub units: f64,
473    /// The price per unit in cents (optional, uses add-on default if not specified).
474    #[serde(skip_serializing_if = "Option::is_none")]
475    pub unit_amount_cents: Option<i64>,
476    /// Optional description for the fee.
477    #[serde(skip_serializing_if = "Option::is_none")]
478    pub description: Option<String>,
479    /// Optional tax codes to apply to this fee.
480    #[serde(skip_serializing_if = "Option::is_none")]
481    pub tax_codes: Option<Vec<String>>,
482}
483
484impl CreateInvoiceFeeInput {
485    /// Creates a new fee input with the required fields.
486    ///
487    /// # Arguments
488    /// * `add_on_code` - The code of the add-on to charge
489    /// * `units` - The number of units to charge
490    ///
491    /// # Returns
492    /// A new `CreateInvoiceFeeInput` instance
493    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    /// Sets a custom unit amount in cents.
504    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    /// Sets a description for the fee.
510    pub fn with_description(mut self, description: String) -> Self {
511        self.description = Some(description);
512        self
513    }
514
515    /// Sets the tax codes to apply to this fee.
516    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/// Input for creating a one-off invoice.
523///
524/// This struct contains all the information needed to create a one-off invoice
525/// for a customer with add-on charges.
526#[derive(Debug, Clone, Serialize, Deserialize)]
527pub struct CreateInvoiceInput {
528    /// The external customer ID to create the invoice for.
529    pub external_customer_id: String,
530    /// The currency for the invoice (ISO 4217 code).
531    pub currency: String,
532    /// The list of fees to include in the invoice.
533    pub fees: Vec<CreateInvoiceFeeInput>,
534}
535
536impl CreateInvoiceInput {
537    /// Creates a new invoice input with the required fields.
538    ///
539    /// # Arguments
540    /// * `external_customer_id` - The external ID of the customer
541    /// * `currency` - The currency code (e.g., "USD")
542    /// * `fees` - The list of fees to include
543    ///
544    /// # Returns
545    /// A new `CreateInvoiceInput` instance
546    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/// Request for creating a one-off invoice.
560#[derive(Debug, Clone, Serialize, Deserialize)]
561pub struct CreateInvoiceRequest {
562    /// The invoice input data.
563    pub invoice: CreateInvoiceInput,
564}
565
566impl CreateInvoiceRequest {
567    /// Creates a new create invoice request.
568    ///
569    /// # Arguments
570    /// * `input` - The invoice input data
571    ///
572    /// # Returns
573    /// A new `CreateInvoiceRequest` instance
574    pub fn new(input: CreateInvoiceInput) -> Self {
575        Self { invoice: input }
576    }
577}
578
579/// Metadata input for updating an invoice.
580#[derive(Debug, Clone, Serialize, Deserialize)]
581pub struct UpdateInvoiceMetadataInput {
582    /// The ID of an existing metadata entry to update (optional for new entries).
583    #[serde(skip_serializing_if = "Option::is_none")]
584    pub id: Option<String>,
585    /// The metadata key.
586    pub key: String,
587    /// The metadata value.
588    pub value: String,
589}
590
591impl UpdateInvoiceMetadataInput {
592    /// Creates a new metadata input.
593    ///
594    /// # Arguments
595    /// * `key` - The metadata key
596    /// * `value` - The metadata value
597    ///
598    /// # Returns
599    /// A new `UpdateInvoiceMetadataInput` instance
600    pub fn new(key: String, value: String) -> Self {
601        Self {
602            id: None,
603            key,
604            value,
605        }
606    }
607
608    /// Creates a metadata input for updating an existing entry.
609    ///
610    /// # Arguments
611    /// * `id` - The ID of the existing metadata entry
612    /// * `key` - The metadata key
613    /// * `value` - The metadata value
614    ///
615    /// # Returns
616    /// A new `UpdateInvoiceMetadataInput` instance
617    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/// Input for updating an invoice.
627///
628/// This struct contains the fields that can be updated on an existing invoice.
629#[derive(Debug, Clone, Default, Serialize, Deserialize)]
630pub struct UpdateInvoiceInput {
631    /// The payment status of the invoice.
632    #[serde(skip_serializing_if = "Option::is_none")]
633    pub payment_status: Option<String>,
634    /// Custom metadata for the invoice.
635    #[serde(skip_serializing_if = "Option::is_none")]
636    pub metadata: Option<Vec<UpdateInvoiceMetadataInput>>,
637}
638
639impl UpdateInvoiceInput {
640    /// Creates a new empty update invoice input.
641    pub fn new() -> Self {
642        Self::default()
643    }
644
645    /// Sets the payment status.
646    ///
647    /// # Arguments
648    /// * `payment_status` - The payment status (e.g., "succeeded", "failed", "pending")
649    pub fn with_payment_status(mut self, payment_status: String) -> Self {
650        self.payment_status = Some(payment_status);
651        self
652    }
653
654    /// Sets the metadata entries.
655    pub fn with_metadata(mut self, metadata: Vec<UpdateInvoiceMetadataInput>) -> Self {
656        self.metadata = Some(metadata);
657        self
658    }
659}
660
661/// Request for updating an invoice.
662#[derive(Debug, Clone, Serialize, Deserialize)]
663pub struct UpdateInvoiceRequest {
664    /// The Lago ID of the invoice to update.
665    #[serde(skip)]
666    pub lago_id: String,
667    /// The invoice update data.
668    pub invoice: UpdateInvoiceInput,
669}
670
671impl UpdateInvoiceRequest {
672    /// Creates a new update invoice request.
673    ///
674    /// # Arguments
675    /// * `lago_id` - The Lago ID of the invoice to update
676    /// * `input` - The update input data
677    ///
678    /// # Returns
679    /// A new `UpdateInvoiceRequest` instance
680    pub fn new(lago_id: String, input: UpdateInvoiceInput) -> Self {
681        Self {
682            lago_id,
683            invoice: input,
684        }
685    }
686}
687
688/// Request parameters for listing a customer's invoices.
689///
690/// This struct combines the customer identifier with pagination and filters
691/// to retrieve invoices for a specific customer.
692#[derive(Debug, Clone)]
693pub struct ListCustomerInvoicesRequest {
694    /// The external customer ID.
695    pub external_customer_id: String,
696    /// Pagination parameters.
697    pub pagination: PaginationParams,
698    /// Invoice filters.
699    pub filters: InvoiceFilters,
700    /// Search by id, number, customer name, external_id or email.
701    pub search_term: Option<String>,
702}
703
704impl ListCustomerInvoicesRequest {
705    /// Creates a new list customer invoices request.
706    ///
707    /// # Arguments
708    /// * `external_customer_id` - The external customer ID
709    ///
710    /// # Returns
711    /// A new `ListCustomerInvoicesRequest` instance
712    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    /// Sets the pagination parameters.
722    pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
723        self.pagination = pagination;
724        self
725    }
726
727    /// Sets the invoice filters.
728    pub fn with_filters(mut self, filters: InvoiceFilters) -> Self {
729        self.filters = filters;
730        self
731    }
732
733    /// Sets the search term for the request.
734    ///
735    /// Search by id, number, customer name, external_id or email.
736    pub fn with_search_term(mut self, term: String) -> Self {
737        self.search_term = Some(term);
738        self
739    }
740
741    /// Converts the request parameters into HTTP query parameters.
742    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/// Request for refreshing a draft invoice.
755///
756/// Refreshing re-fetches the customer information and recomputes the taxes.
757#[derive(Debug, Clone)]
758pub struct RefreshInvoiceRequest {
759    /// The Lago ID of the invoice to refresh.
760    pub lago_id: String,
761}
762
763impl RefreshInvoiceRequest {
764    /// Creates a new refresh invoice request.
765    ///
766    /// # Arguments
767    /// * `lago_id` - The Lago ID of the invoice to refresh
768    ///
769    /// # Returns
770    /// A new `RefreshInvoiceRequest` instance
771    pub fn new(lago_id: String) -> Self {
772        Self { lago_id }
773    }
774}
775
776/// Request for downloading an invoice PDF.
777///
778/// This triggers the generation of the invoice PDF if not already generated.
779#[derive(Debug, Clone)]
780pub struct DownloadInvoiceRequest {
781    /// The Lago ID of the invoice to download.
782    pub lago_id: String,
783}
784
785impl DownloadInvoiceRequest {
786    /// Creates a new download invoice request.
787    ///
788    /// # Arguments
789    /// * `lago_id` - The Lago ID of the invoice to download
790    ///
791    /// # Returns
792    /// A new `DownloadInvoiceRequest` instance
793    pub fn new(lago_id: String) -> Self {
794        Self { lago_id }
795    }
796}
797
798/// Request for retrying a failed invoice finalization.
799///
800/// This retries the finalization process for invoices that failed during generation.
801#[derive(Debug, Clone)]
802pub struct RetryInvoiceRequest {
803    /// The Lago ID of the invoice to retry.
804    pub lago_id: String,
805}
806
807impl RetryInvoiceRequest {
808    /// Creates a new retry invoice request.
809    ///
810    /// # Arguments
811    /// * `lago_id` - The Lago ID of the invoice to retry
812    ///
813    /// # Returns
814    /// A new `RetryInvoiceRequest` instance
815    pub fn new(lago_id: String) -> Self {
816        Self { lago_id }
817    }
818}
819
820/// Request for retrying a failed invoice payment.
821///
822/// This resends the invoice for collection and retries the payment with the payment provider.
823#[derive(Debug, Clone)]
824pub struct RetryInvoicePaymentRequest {
825    /// The Lago ID of the invoice to retry payment for.
826    pub lago_id: String,
827}
828
829impl RetryInvoicePaymentRequest {
830    /// Creates a new retry invoice payment request.
831    ///
832    /// # Arguments
833    /// * `lago_id` - The Lago ID of the invoice to retry payment for
834    ///
835    /// # Returns
836    /// A new `RetryInvoicePaymentRequest` instance
837    pub fn new(lago_id: String) -> Self {
838        Self { lago_id }
839    }
840}
841
842/// Request for voiding a finalized invoice.
843///
844/// This voids a finalized invoice, changing its status to "voided".
845/// Only finalized invoices can be voided.
846#[derive(Debug, Clone)]
847pub struct VoidInvoiceRequest {
848    /// The Lago ID of the invoice to void.
849    pub lago_id: String,
850}
851
852impl VoidInvoiceRequest {
853    /// Creates a new void invoice request.
854    ///
855    /// # Arguments
856    /// * `lago_id` - The Lago ID of the invoice to void
857    ///
858    /// # Returns
859    /// A new `VoidInvoiceRequest` instance
860    pub fn new(lago_id: String) -> Self {
861        Self { lago_id }
862    }
863}