rust_woocommerce/controllers/
customers.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::{Billing, MetaData, Shipping};
5
6#[skip_serializing_none]
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8pub struct CreateCustomer {
9    /// The email address for the customer
10    email: String,
11    /// Customer first name.    
12    first_name: Option<String>,
13    /// Customer last name.
14    last_name: Option<String>,
15    /// Customer login name.
16    username: Option<String>,
17    // Customer password.
18    password: Option<String>,
19    /// List of billing address data.    
20    billing: Option<Billing>,
21    /// List of shipping address data.
22    shipping: Option<Shipping>,
23    /// Meta data.
24    meta_data: Option<Vec<MetaData>>,
25}
26
27impl CreateCustomer {
28    /// The email address for the customer
29    pub fn new<T: ToString>(email: T) -> Self {
30        CreateCustomer {
31            email: email.to_string(),
32            ..Default::default()
33        }
34    }
35    /// Customer first name.    
36    pub fn first_name(mut self, first_name: impl Into<String>) -> Self {
37        let _ = self.first_name.insert(first_name.into());
38        self
39    }
40    /// Customer last name.
41    pub fn last_name(mut self, last_name: impl Into<String>) -> Self {
42        let _ = self.last_name.insert(last_name.into());
43        self
44    }
45    /// Customer login name.
46    pub fn username(mut self, username: impl Into<String>) -> Self {
47        let _ = self.username.insert(username.into());
48        self
49    }
50    // Customer password.
51    pub fn password(mut self, password: impl Into<String>) -> Self {
52        let _ = self.password.insert(password.into());
53        self
54    }
55    /// billing first name.
56    pub fn billing_first_name(mut self, first_name: impl Into<String>) -> Self {
57        self.billing.get_or_insert(Billing::default()).first_name = first_name.into();
58        self
59    }
60    /// billing last name.
61    pub fn billing_last_name(mut self, last_name: impl Into<String>) -> Self {
62        self.billing.get_or_insert(Billing::default()).last_name = last_name.into();
63        self
64    }
65    /// billing company name.
66    pub fn billing_company(mut self, company: impl Into<String>) -> Self {
67        self.billing.get_or_insert(Billing::default()).company = company.into();
68        self
69    }
70    /// billing address line 1
71    pub fn billing_address_1(mut self, address_1: impl Into<String>) -> Self {
72        self.billing.get_or_insert(Billing::default()).address_1 = address_1.into();
73        self
74    }
75    /// billing address line 2
76    pub fn billing_address_2(mut self, address_2: impl Into<String>) -> Self {
77        self.billing.get_or_insert(Billing::default()).address_2 = address_2.into();
78        self
79    }
80    /// billing city name.
81    pub fn billing_city(mut self, city: impl Into<String>) -> Self {
82        self.billing.get_or_insert(Billing::default()).city = city.into();
83        self
84    }
85    /// billing ISO code or name of the state, province or district.
86    pub fn billing_state(mut self, state: impl Into<String>) -> Self {
87        self.billing.get_or_insert(Billing::default()).state = state.into();
88        self
89    }
90    /// billing postal code.
91    pub fn billing_postcode(mut self, postcode: impl Into<String>) -> Self {
92        self.billing.get_or_insert(Billing::default()).postcode = postcode.into();
93        self
94    }
95    /// billing ISO code of the country.
96    pub fn billing_country(mut self, country: impl Into<String>) -> Self {
97        self.billing.get_or_insert(Billing::default()).country = country.into();
98        self
99    }
100    /// billing email address.
101    pub fn billing_email(mut self, email: impl Into<String>) -> Self {
102        self.billing.get_or_insert(Billing::default()).email = email.into();
103        self
104    }
105    /// billing phone number.
106    pub fn billing_phone(mut self, phone: impl Into<String>) -> Self {
107        self.billing.get_or_insert(Billing::default()).phone = phone.into();
108        self
109    }
110    /// shipping first name.
111    pub fn shipping_first_name(mut self, first_name: impl Into<String>) -> Self {
112        self.shipping.get_or_insert(Shipping::default()).first_name = first_name.into();
113        self
114    }
115    /// shipping last name.
116    pub fn shipping_last_name(mut self, last_name: impl Into<String>) -> Self {
117        self.shipping.get_or_insert(Shipping::default()).last_name = last_name.into();
118        self
119    }
120    /// shipping company name.
121    pub fn shipping_company(mut self, company: impl Into<String>) -> Self {
122        self.shipping.get_or_insert(Shipping::default()).company = company.into();
123        self
124    }
125    /// shipping address line 1
126    pub fn shipping_address_1(mut self, address_1: impl Into<String>) -> Self {
127        self.shipping.get_or_insert(Shipping::default()).address_1 = address_1.into();
128        self
129    }
130    /// shipping address line 2
131    pub fn shipping_address_2(mut self, address_2: impl Into<String>) -> Self {
132        self.shipping.get_or_insert(Shipping::default()).address_2 = address_2.into();
133        self
134    }
135    /// shipping city name.
136    pub fn shipping_city(mut self, city: impl Into<String>) -> Self {
137        self.shipping.get_or_insert(Shipping::default()).city = city.into();
138        self
139    }
140    /// shipping ISO code or name of the state, province or district.
141    pub fn shipping_state(mut self, state: impl Into<String>) -> Self {
142        self.shipping.get_or_insert(Shipping::default()).state = state.into();
143        self
144    }
145    /// shipping postal code.
146    pub fn shipping_postcode(mut self, postcode: impl Into<String>) -> Self {
147        self.shipping.get_or_insert(Shipping::default()).postcode = postcode.into();
148        self
149    }
150    /// shipping ISO code of the country.
151    pub fn shipping_country(mut self, country: impl Into<String>) -> Self {
152        self.shipping.get_or_insert(Shipping::default()).country = country.into();
153        self
154    }
155    /// Meta data.
156    pub fn meta_data(mut self, key: impl Into<String>, value: impl serde::Serialize) -> Self {
157        self.meta_data.get_or_insert(vec![]).push(MetaData {
158            id: None,
159            key: key.into(),
160            value: serde_json::json!(value),
161        });
162        self
163    }
164}
165#[skip_serializing_none]
166#[derive(Debug, Clone, Serialize, Deserialize, Default)]
167pub struct UpdateCustomer {
168    /// Unique identifier for the resource
169    id: Option<i32>,
170    /// The email address for the customer
171    email: Option<String>,
172    /// Customer first name.    
173    first_name: Option<String>,
174    /// Customer last name.
175    last_name: Option<String>,
176    /// Customer login name.
177    username: Option<String>,
178    // Customer password.
179    password: Option<String>,
180    /// List of billing address data.    
181    billing: Option<Billing>,
182    /// List of shipping address data.
183    shipping: Option<Shipping>,
184    /// Meta data.
185    meta_data: Option<Vec<MetaData>>,
186}
187impl UpdateCustomer {
188    /// Unique identifier for the resource
189    pub fn id(mut self, id: i32) -> Self {
190        let _ = self.id.insert(id);
191        self
192    }
193    /// The email address for the customer
194    pub fn email(mut self, email: impl Into<String>) -> Self {
195        let _ = self.email.insert(email.into());
196        self
197    }
198    /// Customer first name.    
199    pub fn first_name(mut self, first_name: impl Into<String>) -> Self {
200        let _ = self.first_name.insert(first_name.into());
201        self
202    }
203    /// Customer last name.
204    pub fn last_name(mut self, last_name: impl Into<String>) -> Self {
205        let _ = self.last_name.insert(last_name.into());
206        self
207    }
208    /// Customer login name.
209    pub fn username(mut self, username: impl Into<String>) -> Self {
210        let _ = self.username.insert(username.into());
211        self
212    }
213    // Customer password.
214    pub fn password(mut self, password: impl Into<String>) -> Self {
215        let _ = self.password.insert(password.into());
216        self
217    }
218    /// billing first name.
219    pub fn billing_first_name(mut self, first_name: impl Into<String>) -> Self {
220        self.billing.get_or_insert(Billing::default()).first_name = first_name.into();
221        self
222    }
223    /// billing last name.
224    pub fn billing_last_name(mut self, last_name: impl Into<String>) -> Self {
225        self.billing.get_or_insert(Billing::default()).last_name = last_name.into();
226        self
227    }
228    /// billing company name.
229    pub fn billing_company(mut self, company: impl Into<String>) -> Self {
230        self.billing.get_or_insert(Billing::default()).company = company.into();
231        self
232    }
233    /// billing address line 1
234    pub fn billing_address_1(mut self, address_1: impl Into<String>) -> Self {
235        self.billing.get_or_insert(Billing::default()).address_1 = address_1.into();
236        self
237    }
238    /// billing address line 2
239    pub fn billing_address_2(mut self, address_2: impl Into<String>) -> Self {
240        self.billing.get_or_insert(Billing::default()).address_2 = address_2.into();
241        self
242    }
243    /// billing city name.
244    pub fn billing_city(mut self, city: impl Into<String>) -> Self {
245        self.billing.get_or_insert(Billing::default()).city = city.into();
246        self
247    }
248    /// billing ISO code or name of the state, province or district.
249    pub fn billing_state(mut self, state: impl Into<String>) -> Self {
250        self.billing.get_or_insert(Billing::default()).state = state.into();
251        self
252    }
253    /// billing postal code.
254    pub fn billing_postcode(mut self, postcode: impl Into<String>) -> Self {
255        self.billing.get_or_insert(Billing::default()).postcode = postcode.into();
256        self
257    }
258    /// billing ISO code of the country.
259    pub fn billing_country(mut self, country: impl Into<String>) -> Self {
260        self.billing.get_or_insert(Billing::default()).country = country.into();
261        self
262    }
263    /// billing email address.
264    pub fn billing_email(mut self, email: impl Into<String>) -> Self {
265        self.billing.get_or_insert(Billing::default()).email = email.into();
266        self
267    }
268    /// billing phone number.
269    pub fn billing_phone(mut self, phone: impl Into<String>) -> Self {
270        self.billing.get_or_insert(Billing::default()).phone = phone.into();
271        self
272    }
273    /// shipping first name.
274    pub fn shipping_first_name(mut self, first_name: impl Into<String>) -> Self {
275        self.shipping.get_or_insert(Shipping::default()).first_name = first_name.into();
276        self
277    }
278    /// shipping last name.
279    pub fn shipping_last_name(mut self, last_name: impl Into<String>) -> Self {
280        self.shipping.get_or_insert(Shipping::default()).last_name = last_name.into();
281        self
282    }
283    /// shipping company name.
284    pub fn shipping_company(mut self, company: impl Into<String>) -> Self {
285        self.shipping.get_or_insert(Shipping::default()).company = company.into();
286        self
287    }
288    /// shipping address line 1
289    pub fn shipping_address_1(mut self, address_1: impl Into<String>) -> Self {
290        self.shipping.get_or_insert(Shipping::default()).address_1 = address_1.into();
291        self
292    }
293    /// shipping address line 2
294    pub fn shipping_address_2(mut self, address_2: impl Into<String>) -> Self {
295        self.shipping.get_or_insert(Shipping::default()).address_2 = address_2.into();
296        self
297    }
298    /// shipping city name.
299    pub fn shipping_city(mut self, city: impl Into<String>) -> Self {
300        self.shipping.get_or_insert(Shipping::default()).city = city.into();
301        self
302    }
303    /// shipping ISO code or name of the state, province or district.
304    pub fn shipping_state(mut self, state: impl Into<String>) -> Self {
305        self.shipping.get_or_insert(Shipping::default()).state = state.into();
306        self
307    }
308    /// shipping postal code.
309    pub fn shipping_postcode(mut self, postcode: impl Into<String>) -> Self {
310        self.shipping.get_or_insert(Shipping::default()).postcode = postcode.into();
311        self
312    }
313    /// shipping ISO code of the country.
314    pub fn shipping_country(mut self, country: impl Into<String>) -> Self {
315        self.shipping.get_or_insert(Shipping::default()).country = country.into();
316        self
317    }
318    /// Meta data.
319    pub fn meta_data(mut self, key: impl Into<String>, value: impl serde::Serialize) -> Self {
320        self.meta_data.get_or_insert(vec![]).push(MetaData {
321            id: None,
322            key: key.into(),
323            value: serde_json::json!(value),
324        });
325        self
326    }
327}