1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateInvoicesExportError {
22 Status400(models::invoices_2024_06_19::ErrorList),
23 Status401(models::invoices_2024_06_19::ErrorList),
24 Status403(models::invoices_2024_06_19::ErrorList),
25 Status404(models::invoices_2024_06_19::ErrorList),
26 Status413(models::invoices_2024_06_19::ErrorList),
27 Status415(models::invoices_2024_06_19::ErrorList),
28 Status429(models::invoices_2024_06_19::ErrorList),
29 Status500(models::invoices_2024_06_19::ErrorList),
30 Status503(models::invoices_2024_06_19::ErrorList),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetInvoiceError {
38 Status400(models::invoices_2024_06_19::ErrorList),
39 Status401(models::invoices_2024_06_19::ErrorList),
40 Status403(models::invoices_2024_06_19::ErrorList),
41 Status404(models::invoices_2024_06_19::ErrorList),
42 Status413(models::invoices_2024_06_19::ErrorList),
43 Status415(models::invoices_2024_06_19::ErrorList),
44 Status429(models::invoices_2024_06_19::ErrorList),
45 Status500(models::invoices_2024_06_19::ErrorList),
46 Status503(models::invoices_2024_06_19::ErrorList),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetInvoicesError {
54 Status400(models::invoices_2024_06_19::ErrorList),
55 Status401(models::invoices_2024_06_19::ErrorList),
56 Status403(models::invoices_2024_06_19::ErrorList),
57 Status404(models::invoices_2024_06_19::ErrorList),
58 Status413(models::invoices_2024_06_19::ErrorList),
59 Status415(models::invoices_2024_06_19::ErrorList),
60 Status429(models::invoices_2024_06_19::ErrorList),
61 Status500(models::invoices_2024_06_19::ErrorList),
62 Status503(models::invoices_2024_06_19::ErrorList),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetInvoicesAttributesError {
70 Status400(models::invoices_2024_06_19::ErrorList),
71 Status401(models::invoices_2024_06_19::ErrorList),
72 Status403(models::invoices_2024_06_19::ErrorList),
73 Status404(models::invoices_2024_06_19::ErrorList),
74 Status413(models::invoices_2024_06_19::ErrorList),
75 Status415(models::invoices_2024_06_19::ErrorList),
76 Status429(models::invoices_2024_06_19::ErrorList),
77 Status500(models::invoices_2024_06_19::ErrorList),
78 Status503(models::invoices_2024_06_19::ErrorList),
79 UnknownValue(serde_json::Value),
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum GetInvoicesDocumentError {
86 Status400(models::invoices_2024_06_19::ErrorList),
87 Status401(models::invoices_2024_06_19::ErrorList),
88 Status403(models::invoices_2024_06_19::ErrorList),
89 Status404(models::invoices_2024_06_19::ErrorList),
90 Status413(models::invoices_2024_06_19::ErrorList),
91 Status415(models::invoices_2024_06_19::ErrorList),
92 Status429(models::invoices_2024_06_19::ErrorList),
93 Status500(models::invoices_2024_06_19::ErrorList),
94 Status503(models::invoices_2024_06_19::ErrorList),
95 UnknownValue(serde_json::Value),
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum GetInvoicesExportError {
102 Status400(models::invoices_2024_06_19::ErrorList),
103 Status401(models::invoices_2024_06_19::ErrorList),
104 Status403(models::invoices_2024_06_19::ErrorList),
105 Status404(models::invoices_2024_06_19::ErrorList),
106 Status413(models::invoices_2024_06_19::ErrorList),
107 Status415(models::invoices_2024_06_19::ErrorList),
108 Status429(models::invoices_2024_06_19::ErrorList),
109 Status500(models::invoices_2024_06_19::ErrorList),
110 Status503(models::invoices_2024_06_19::ErrorList),
111 UnknownValue(serde_json::Value),
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum GetInvoicesExportsError {
118 Status400(models::invoices_2024_06_19::ErrorList),
119 Status401(models::invoices_2024_06_19::ErrorList),
120 Status403(models::invoices_2024_06_19::ErrorList),
121 Status404(models::invoices_2024_06_19::ErrorList),
122 Status413(models::invoices_2024_06_19::ErrorList),
123 Status415(models::invoices_2024_06_19::ErrorList),
124 Status429(models::invoices_2024_06_19::ErrorList),
125 Status500(models::invoices_2024_06_19::ErrorList),
126 Status503(models::invoices_2024_06_19::ErrorList),
127 UnknownValue(serde_json::Value),
128}
129
130
131pub async fn create_invoices_export(configuration: &configuration::Configuration, body: models::invoices_2024_06_19::ExportInvoicesRequest) -> Result<models::invoices_2024_06_19::ExportInvoicesResponse, Error<CreateInvoicesExportError>> {
133 let p_body = body;
135
136 let uri_str = format!("{}/tax/invoices/2024-06-19/exports", configuration.base_path);
137 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
138
139 if let Some(ref user_agent) = configuration.user_agent {
140 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
141 }
142 req_builder = req_builder.json(&p_body);
143
144 let req = req_builder.build()?;
145 let resp = configuration.client.execute(req).await?;
146
147 let status = resp.status();
148 let content_type = resp
149 .headers()
150 .get("content-type")
151 .and_then(|v| v.to_str().ok())
152 .unwrap_or("application/octet-stream");
153 let content_type = super::ContentType::from(content_type);
154
155 if !status.is_client_error() && !status.is_server_error() {
156 let content = resp.text().await?;
157 match content_type {
158 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::ExportInvoicesResponse`"))),
160 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::ExportInvoicesResponse`")))),
161 }
162 } else {
163 let content = resp.text().await?;
164 let entity: Option<CreateInvoicesExportError> = serde_json::from_str(&content).ok();
165 Err(Error::ResponseError(ResponseContent { status, content, entity }))
166 }
167}
168
169pub async fn get_invoice(configuration: &configuration::Configuration, marketplace_id: &str, invoice_id: &str) -> Result<models::invoices_2024_06_19::GetInvoiceResponse, Error<GetInvoiceError>> {
171 let p_marketplace_id = marketplace_id;
173 let p_invoice_id = invoice_id;
174
175 let uri_str = format!("{}/tax/invoices/2024-06-19/invoices/{invoiceId}", configuration.base_path, invoiceId=crate::apis::urlencode(p_invoice_id));
176 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
177
178 req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
179 if let Some(ref user_agent) = configuration.user_agent {
180 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181 }
182
183 let req = req_builder.build()?;
184 let resp = configuration.client.execute(req).await?;
185
186 let status = resp.status();
187 let content_type = resp
188 .headers()
189 .get("content-type")
190 .and_then(|v| v.to_str().ok())
191 .unwrap_or("application/octet-stream");
192 let content_type = super::ContentType::from(content_type);
193
194 if !status.is_client_error() && !status.is_server_error() {
195 let content = resp.text().await?;
196 match content_type {
197 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
198 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoiceResponse`"))),
199 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoiceResponse`")))),
200 }
201 } else {
202 let content = resp.text().await?;
203 let entity: Option<GetInvoiceError> = serde_json::from_str(&content).ok();
204 Err(Error::ResponseError(ResponseContent { status, content, entity }))
205 }
206}
207
208pub async fn get_invoices(configuration: &configuration::Configuration, marketplace_id: &str, transaction_identifier_name: Option<&str>, page_size: Option<i32>, date_end: Option<String>, transaction_type: Option<&str>, transaction_identifier_id: Option<&str>, date_start: Option<String>, series: Option<&str>, next_token: Option<&str>, sort_order: Option<&str>, invoice_type: Option<&str>, statuses: Option<Vec<String>>, external_invoice_id: Option<&str>, sort_by: Option<&str>) -> Result<models::invoices_2024_06_19::GetInvoicesResponse, Error<GetInvoicesError>> {
210 let p_marketplace_id = marketplace_id;
212 let p_transaction_identifier_name = transaction_identifier_name;
213 let p_page_size = page_size;
214 let p_date_end = date_end;
215 let p_transaction_type = transaction_type;
216 let p_transaction_identifier_id = transaction_identifier_id;
217 let p_date_start = date_start;
218 let p_series = series;
219 let p_next_token = next_token;
220 let p_sort_order = sort_order;
221 let p_invoice_type = invoice_type;
222 let p_statuses = statuses;
223 let p_external_invoice_id = external_invoice_id;
224 let p_sort_by = sort_by;
225
226 let uri_str = format!("{}/tax/invoices/2024-06-19/invoices", configuration.base_path);
227 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
228
229 if let Some(ref param_value) = p_transaction_identifier_name {
230 req_builder = req_builder.query(&[("transactionIdentifierName", ¶m_value.to_string())]);
231 }
232 if let Some(ref param_value) = p_page_size {
233 req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
234 }
235 if let Some(ref param_value) = p_date_end {
236 req_builder = req_builder.query(&[("dateEnd", ¶m_value.to_string())]);
237 }
238 req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
239 if let Some(ref param_value) = p_transaction_type {
240 req_builder = req_builder.query(&[("transactionType", ¶m_value.to_string())]);
241 }
242 if let Some(ref param_value) = p_transaction_identifier_id {
243 req_builder = req_builder.query(&[("transactionIdentifierId", ¶m_value.to_string())]);
244 }
245 if let Some(ref param_value) = p_date_start {
246 req_builder = req_builder.query(&[("dateStart", ¶m_value.to_string())]);
247 }
248 if let Some(ref param_value) = p_series {
249 req_builder = req_builder.query(&[("series", ¶m_value.to_string())]);
250 }
251 if let Some(ref param_value) = p_next_token {
252 req_builder = req_builder.query(&[("nextToken", ¶m_value.to_string())]);
253 }
254 if let Some(ref param_value) = p_sort_order {
255 req_builder = req_builder.query(&[("sortOrder", ¶m_value.to_string())]);
256 }
257 if let Some(ref param_value) = p_invoice_type {
258 req_builder = req_builder.query(&[("invoiceType", ¶m_value.to_string())]);
259 }
260 if let Some(ref param_value) = p_statuses {
261 req_builder = match "csv" {
262 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("statuses".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
263 _ => req_builder.query(&[("statuses", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
264 };
265 }
266 if let Some(ref param_value) = p_external_invoice_id {
267 req_builder = req_builder.query(&[("externalInvoiceId", ¶m_value.to_string())]);
268 }
269 if let Some(ref param_value) = p_sort_by {
270 req_builder = req_builder.query(&[("sortBy", ¶m_value.to_string())]);
271 }
272 if let Some(ref user_agent) = configuration.user_agent {
273 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
274 }
275
276 let req = req_builder.build()?;
277 let resp = configuration.client.execute(req).await?;
278
279 let status = resp.status();
280 let content_type = resp
281 .headers()
282 .get("content-type")
283 .and_then(|v| v.to_str().ok())
284 .unwrap_or("application/octet-stream");
285 let content_type = super::ContentType::from(content_type);
286
287 if !status.is_client_error() && !status.is_server_error() {
288 let content = resp.text().await?;
289 match content_type {
290 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
291 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesResponse`"))),
292 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesResponse`")))),
293 }
294 } else {
295 let content = resp.text().await?;
296 let entity: Option<GetInvoicesError> = serde_json::from_str(&content).ok();
297 Err(Error::ResponseError(ResponseContent { status, content, entity }))
298 }
299}
300
301pub async fn get_invoices_attributes(configuration: &configuration::Configuration, marketplace_id: &str) -> Result<models::invoices_2024_06_19::GetInvoicesAttributesResponse, Error<GetInvoicesAttributesError>> {
303 let p_marketplace_id = marketplace_id;
305
306 let uri_str = format!("{}/tax/invoices/2024-06-19/attributes", configuration.base_path);
307 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
308
309 req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
310 if let Some(ref user_agent) = configuration.user_agent {
311 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
312 }
313
314 let req = req_builder.build()?;
315 let resp = configuration.client.execute(req).await?;
316
317 let status = resp.status();
318 let content_type = resp
319 .headers()
320 .get("content-type")
321 .and_then(|v| v.to_str().ok())
322 .unwrap_or("application/octet-stream");
323 let content_type = super::ContentType::from(content_type);
324
325 if !status.is_client_error() && !status.is_server_error() {
326 let content = resp.text().await?;
327 match content_type {
328 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
329 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesAttributesResponse`"))),
330 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesAttributesResponse`")))),
331 }
332 } else {
333 let content = resp.text().await?;
334 let entity: Option<GetInvoicesAttributesError> = serde_json::from_str(&content).ok();
335 Err(Error::ResponseError(ResponseContent { status, content, entity }))
336 }
337}
338
339pub async fn get_invoices_document(configuration: &configuration::Configuration, invoices_document_id: &str) -> Result<models::invoices_2024_06_19::GetInvoicesDocumentResponse, Error<GetInvoicesDocumentError>> {
341 let p_invoices_document_id = invoices_document_id;
343
344 let uri_str = format!("{}/tax/invoices/2024-06-19/documents/{invoicesDocumentId}", configuration.base_path, invoicesDocumentId=crate::apis::urlencode(p_invoices_document_id));
345 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
346
347 if let Some(ref user_agent) = configuration.user_agent {
348 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
349 }
350
351 let req = req_builder.build()?;
352 let resp = configuration.client.execute(req).await?;
353
354 let status = resp.status();
355 let content_type = resp
356 .headers()
357 .get("content-type")
358 .and_then(|v| v.to_str().ok())
359 .unwrap_or("application/octet-stream");
360 let content_type = super::ContentType::from(content_type);
361
362 if !status.is_client_error() && !status.is_server_error() {
363 let content = resp.text().await?;
364 match content_type {
365 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
366 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesDocumentResponse`"))),
367 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesDocumentResponse`")))),
368 }
369 } else {
370 let content = resp.text().await?;
371 let entity: Option<GetInvoicesDocumentError> = serde_json::from_str(&content).ok();
372 Err(Error::ResponseError(ResponseContent { status, content, entity }))
373 }
374}
375
376pub async fn get_invoices_export(configuration: &configuration::Configuration, export_id: &str) -> Result<models::invoices_2024_06_19::GetInvoicesExportResponse, Error<GetInvoicesExportError>> {
378 let p_export_id = export_id;
380
381 let uri_str = format!("{}/tax/invoices/2024-06-19/exports/{exportId}", configuration.base_path, exportId=crate::apis::urlencode(p_export_id));
382 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
383
384 if let Some(ref user_agent) = configuration.user_agent {
385 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
386 }
387
388 let req = req_builder.build()?;
389 let resp = configuration.client.execute(req).await?;
390
391 let status = resp.status();
392 let content_type = resp
393 .headers()
394 .get("content-type")
395 .and_then(|v| v.to_str().ok())
396 .unwrap_or("application/octet-stream");
397 let content_type = super::ContentType::from(content_type);
398
399 if !status.is_client_error() && !status.is_server_error() {
400 let content = resp.text().await?;
401 match content_type {
402 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
403 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesExportResponse`"))),
404 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesExportResponse`")))),
405 }
406 } else {
407 let content = resp.text().await?;
408 let entity: Option<GetInvoicesExportError> = serde_json::from_str(&content).ok();
409 Err(Error::ResponseError(ResponseContent { status, content, entity }))
410 }
411}
412
413pub async fn get_invoices_exports(configuration: &configuration::Configuration, marketplace_id: &str, date_start: Option<String>, next_token: Option<&str>, page_size: Option<i32>, date_end: Option<String>, status: Option<&str>) -> Result<models::invoices_2024_06_19::GetInvoicesExportsResponse, Error<GetInvoicesExportsError>> {
415 let p_marketplace_id = marketplace_id;
417 let p_date_start = date_start;
418 let p_next_token = next_token;
419 let p_page_size = page_size;
420 let p_date_end = date_end;
421 let p_status = status;
422
423 let uri_str = format!("{}/tax/invoices/2024-06-19/exports", configuration.base_path);
424 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
425
426 req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
427 if let Some(ref param_value) = p_date_start {
428 req_builder = req_builder.query(&[("dateStart", ¶m_value.to_string())]);
429 }
430 if let Some(ref param_value) = p_next_token {
431 req_builder = req_builder.query(&[("nextToken", ¶m_value.to_string())]);
432 }
433 if let Some(ref param_value) = p_page_size {
434 req_builder = req_builder.query(&[("pageSize", ¶m_value.to_string())]);
435 }
436 if let Some(ref param_value) = p_date_end {
437 req_builder = req_builder.query(&[("dateEnd", ¶m_value.to_string())]);
438 }
439 if let Some(ref param_value) = p_status {
440 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
441 }
442 if let Some(ref user_agent) = configuration.user_agent {
443 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
444 }
445
446 let req = req_builder.build()?;
447 let resp = configuration.client.execute(req).await?;
448
449 let status = resp.status();
450 let content_type = resp
451 .headers()
452 .get("content-type")
453 .and_then(|v| v.to_str().ok())
454 .unwrap_or("application/octet-stream");
455 let content_type = super::ContentType::from(content_type);
456
457 if !status.is_client_error() && !status.is_server_error() {
458 let content = resp.text().await?;
459 match content_type {
460 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
461 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesExportsResponse`"))),
462 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::invoices_api_model_2024_06_19::GetInvoicesExportsResponse`")))),
463 }
464 } else {
465 let content = resp.text().await?;
466 let entity: Option<GetInvoicesExportsError> = serde_json::from_str(&content).ok();
467 Err(Error::ResponseError(ResponseContent { status, content, entity }))
468 }
469}
470