lago_types/requests/
customer.rs

1use serde::{Deserialize, Serialize};
2
3use crate::filters::{common::ListFilters, customer::CustomerFilter};
4use crate::models::{
5    CustomerFinalizeZeroAmountInvoice, CustomerPaymentProvider, CustomerType, PaginationParams,
6};
7
8#[derive(Debug, Clone)]
9pub struct ListCustomersRequest {
10    pub pagination: PaginationParams,
11    pub filters: CustomerFilter,
12}
13
14impl ListCustomersRequest {
15    /// Creates a new empty list customers request.
16    ///
17    /// # Returns
18    /// A new `ListCustomersRequest` instance with default pagination and no filters.
19    pub fn new() -> Self {
20        Self {
21            pagination: PaginationParams::default(),
22            filters: CustomerFilter::default(),
23        }
24    }
25
26    /// Sets the pagination parameters for the request.
27    ///
28    /// # Arguments
29    /// * `pagination` - The pagination parameters to use
30    ///
31    /// # Returns
32    /// The modified request instance for method chaining.
33    pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
34        self.pagination = pagination;
35        self
36    }
37
38    /// Sets the customer filters for the request.
39    ///
40    /// # Arguments
41    /// * `filters` - The customer filters to apply
42    ///
43    /// # Returns
44    /// The modified request instance for method chaining.
45    pub fn with_filters(mut self, filters: CustomerFilter) -> Self {
46        self.filters = filters;
47        self
48    }
49
50    /// Converts the request parameters into HTTP query parameters.
51    ///
52    /// # Returns
53    /// A vector of query parameter tuples containing both pagination and filter criteria.
54    pub fn to_query_params(&self) -> Vec<(&str, String)> {
55        let mut params = self.pagination.to_query_params();
56        params.extend(self.filters.to_query_params());
57        params
58    }
59}
60
61impl Default for ListCustomersRequest {
62    fn default() -> Self {
63        Self::new()
64    }
65}
66
67#[derive(Debug, Clone)]
68pub struct GetCustomerRequest {
69    pub external_id: String,
70}
71
72impl GetCustomerRequest {
73    /// Creates a new get customer request.
74    ///
75    /// # Arguments
76    /// * `external_id` - The external ID of the customer to retrieve
77    ///
78    /// # Returns
79    /// A new `GetCustomerRequest` instance
80    pub fn new(external_id: String) -> Self {
81        Self { external_id }
82    }
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct CreateCustomerInput {
87    pub external_id: String,
88    pub name: Option<String>,
89    pub firstname: Option<String>,
90    pub lastname: Option<String>,
91    pub email: Option<String>,
92    pub address_line1: Option<String>,
93    pub address_line2: Option<String>,
94    pub city: Option<String>,
95    pub country: Option<String>,
96    pub state: Option<String>,
97    pub zipcode: Option<String>,
98    pub phone: Option<String>,
99    pub url: Option<String>,
100    pub legal_name: Option<String>,
101    pub legal_number: Option<String>,
102    pub logo_url: Option<String>,
103    pub tax_identification_number: Option<String>,
104    pub timezone: Option<String>,
105    pub currency: Option<String>,
106    pub net_payment_term: Option<i32>,
107    pub customer_type: Option<CustomerType>,
108    pub finalize_zero_amount_invoice: Option<CustomerFinalizeZeroAmountInvoice>,
109    pub billing_configuration: Option<CreateCustomerBillingConfiguration>,
110    pub shipping_address: Option<CreateCustomerShippingAddress>,
111    pub metadata: Option<Vec<CreateCustomerMetadata>>,
112}
113
114impl CreateCustomerInput {
115    /// Creates a new customer input with the required external ID.
116    ///
117    /// # Arguments
118    /// * `external_id` - The unique external identifier for the customer
119    ///
120    /// # Returns
121    /// A new `CreateCustomerInput` instance
122    pub fn new(external_id: String) -> Self {
123        Self {
124            external_id,
125            name: None,
126            firstname: None,
127            lastname: None,
128            email: None,
129            address_line1: None,
130            address_line2: None,
131            city: None,
132            country: None,
133            state: None,
134            zipcode: None,
135            phone: None,
136            url: None,
137            legal_name: None,
138            legal_number: None,
139            logo_url: None,
140            tax_identification_number: None,
141            timezone: None,
142            currency: None,
143            net_payment_term: None,
144            customer_type: None,
145            finalize_zero_amount_invoice: None,
146            billing_configuration: None,
147            shipping_address: None,
148            metadata: None,
149        }
150    }
151
152    pub fn with_name(mut self, name: String) -> Self {
153        self.name = Some(name);
154        self
155    }
156
157    pub fn with_firstname(mut self, firstname: String) -> Self {
158        self.firstname = Some(firstname);
159        self
160    }
161
162    pub fn with_lastname(mut self, lastname: String) -> Self {
163        self.lastname = Some(lastname);
164        self
165    }
166
167    pub fn with_email(mut self, email: String) -> Self {
168        self.email = Some(email);
169        self
170    }
171
172    pub fn with_address(
173        mut self,
174        address_line1: String,
175        address_line2: Option<String>,
176        city: Option<String>,
177        country: Option<String>,
178        state: Option<String>,
179        zipcode: Option<String>,
180    ) -> Self {
181        self.address_line1 = Some(address_line1);
182        self.address_line2 = address_line2;
183        self.city = city;
184        self.country = country;
185        self.state = state;
186        self.zipcode = zipcode;
187        self
188    }
189
190    pub fn with_phone(mut self, phone: String) -> Self {
191        self.phone = Some(phone);
192        self
193    }
194
195    pub fn with_url(mut self, url: String) -> Self {
196        self.url = Some(url);
197        self
198    }
199
200    pub fn with_legal_info(mut self, legal_name: String, legal_number: Option<String>) -> Self {
201        self.legal_name = Some(legal_name);
202        self.legal_number = legal_number;
203        self
204    }
205
206    pub fn with_tax_identification_number(mut self, tax_id: String) -> Self {
207        self.tax_identification_number = Some(tax_id);
208        self
209    }
210
211    pub fn with_timezone(mut self, timezone: String) -> Self {
212        self.timezone = Some(timezone);
213        self
214    }
215
216    pub fn with_currency(mut self, currency: String) -> Self {
217        self.currency = Some(currency);
218        self
219    }
220
221    pub fn with_net_payment_term(mut self, days: i32) -> Self {
222        self.net_payment_term = Some(days);
223        self
224    }
225
226    pub fn with_customer_type(mut self, customer_type: CustomerType) -> Self {
227        self.customer_type = Some(customer_type);
228        self
229    }
230
231    pub fn with_finalize_zero_amount_invoice(
232        mut self,
233        setting: CustomerFinalizeZeroAmountInvoice,
234    ) -> Self {
235        self.finalize_zero_amount_invoice = Some(setting);
236        self
237    }
238
239    pub fn with_billing_configuration(
240        mut self,
241        config: CreateCustomerBillingConfiguration,
242    ) -> Self {
243        self.billing_configuration = Some(config);
244        self
245    }
246
247    pub fn with_shipping_address(mut self, address: CreateCustomerShippingAddress) -> Self {
248        self.shipping_address = Some(address);
249        self
250    }
251
252    pub fn with_metadata(mut self, metadata: Vec<CreateCustomerMetadata>) -> Self {
253        self.metadata = Some(metadata);
254        self
255    }
256}
257
258#[derive(Debug, Clone, Serialize, Deserialize)]
259pub struct CreateCustomerBillingConfiguration {
260    pub invoice_grace_period: Option<i32>,
261    pub payment_provider: Option<CustomerPaymentProvider>,
262    pub payment_provider_code: Option<String>,
263    pub provider_customer_id: Option<String>,
264    pub sync: Option<bool>,
265    pub sync_with_provider: Option<bool>,
266    pub document_locale: Option<String>,
267    pub provider_payment_methods: Option<Vec<String>>,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize)]
271pub struct CreateCustomerShippingAddress {
272    pub address_line1: Option<String>,
273    pub address_line2: Option<String>,
274    pub city: Option<String>,
275    pub country: Option<String>,
276    pub state: Option<String>,
277    pub zipcode: Option<String>,
278}
279
280#[derive(Debug, Clone, Serialize, Deserialize)]
281pub struct CreateCustomerMetadata {
282    pub key: String,
283    pub value: String,
284    pub display_in_invoice: bool,
285}
286
287#[derive(Debug, Clone, Serialize, Deserialize)]
288pub struct CreateCustomerRequest {
289    pub customer: CreateCustomerInput,
290}
291
292impl CreateCustomerRequest {
293    /// Creates a new create customer request.
294    ///
295    /// # Arguments
296    /// * `customer` - The customer input data
297    ///
298    /// # Returns
299    /// A new `CreateCustomerRequest` instance
300    pub fn new(customer: CreateCustomerInput) -> Self {
301        Self { customer }
302    }
303}