Skip to main content

fattureincloud_rs/apis/
receipts_api.rs

1/*
2 * Fatture in Cloud API v2 - API Reference
3 *
4 * Connect your software with Fatture in Cloud, the invoicing platform chosen by more than 500.000 businesses in Italy.   The Fatture in Cloud API is based on REST, and makes possible to interact with the user related data prior authorization via OAuth2 protocol.
5 *
6 * The version of the OpenAPI document: 2.0.32
7 * Contact: info@fattureincloud.it
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_receipt`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateReceiptError {
22    Status401(),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_receipt`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteReceiptError {
30    Status401(),
31    Status404(),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`get_receipt`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetReceiptError {
39    Status401(),
40    Status404(),
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`get_receipt_pre_create_info`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum GetReceiptPreCreateInfoError {
48    Status401(),
49    Status404(),
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_receipts_monthly_totals`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetReceiptsMonthlyTotalsError {
57    Status401(),
58    Status404(),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`list_receipts`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum ListReceiptsError {
66    Status401(),
67    UnknownValue(serde_json::Value),
68}
69
70/// struct for typed errors of method [`modify_receipt`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum ModifyReceiptError {
74    Status401(),
75    Status404(),
76    UnknownValue(serde_json::Value),
77}
78
79
80/// Creates a new receipt.
81pub async fn create_receipt(configuration: &configuration::Configuration, company_id: i32, create_receipt_request: Option<models::CreateReceiptRequest>) -> Result<models::CreateReceiptResponse, Error<CreateReceiptError>> {
82    let local_var_configuration = configuration;
83
84    let local_var_client = &local_var_configuration.client;
85
86    let local_var_uri_str = format!("{}/c/{company_id}/receipts", local_var_configuration.base_path, company_id=company_id);
87    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
88
89    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
90        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
91    }
92    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
93        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
94    };
95    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
96        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
97    };
98    local_var_req_builder = local_var_req_builder.json(&create_receipt_request);
99
100    let local_var_req = local_var_req_builder.build()?;
101    let local_var_resp = local_var_client.execute(local_var_req).await?;
102
103    let local_var_status = local_var_resp.status();
104    let local_var_content = local_var_resp.text().await?;
105
106    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
107        serde_json::from_str(&local_var_content).map_err(Error::from)
108    } else {
109        let local_var_entity: Option<CreateReceiptError> = serde_json::from_str(&local_var_content).ok();
110        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
111        Err(Error::ResponseError(local_var_error))
112    }
113}
114
115/// Deletes the specified receipt.
116pub async fn delete_receipt(configuration: &configuration::Configuration, company_id: i32, document_id: i32) -> Result<(), Error<DeleteReceiptError>> {
117    let local_var_configuration = configuration;
118
119    let local_var_client = &local_var_configuration.client;
120
121    let local_var_uri_str = format!("{}/c/{company_id}/receipts/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
122    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
123
124    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
125        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
126    }
127    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
128        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
129    };
130    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
131        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
132    };
133
134    let local_var_req = local_var_req_builder.build()?;
135    let local_var_resp = local_var_client.execute(local_var_req).await?;
136
137    let local_var_status = local_var_resp.status();
138    let local_var_content = local_var_resp.text().await?;
139
140    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
141        Ok(())
142    } else {
143        let local_var_entity: Option<DeleteReceiptError> = serde_json::from_str(&local_var_content).ok();
144        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
145        Err(Error::ResponseError(local_var_error))
146    }
147}
148
149/// Gets the specified receipt.
150pub async fn get_receipt(configuration: &configuration::Configuration, company_id: i32, document_id: i32, fields: Option<&str>, fieldset: Option<&str>) -> Result<models::GetReceiptResponse, Error<GetReceiptError>> {
151    let local_var_configuration = configuration;
152
153    let local_var_client = &local_var_configuration.client;
154
155    let local_var_uri_str = format!("{}/c/{company_id}/receipts/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
156    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
157
158    if let Some(ref local_var_str) = fields {
159        local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
160    }
161    if let Some(ref local_var_str) = fieldset {
162        local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
163    }
164    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
165        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
166    }
167    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
168        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
169    };
170    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
171        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
172    };
173
174    let local_var_req = local_var_req_builder.build()?;
175    let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177    let local_var_status = local_var_resp.status();
178    let local_var_content = local_var_resp.text().await?;
179
180    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
181        serde_json::from_str(&local_var_content).map_err(Error::from)
182    } else {
183        let local_var_entity: Option<GetReceiptError> = serde_json::from_str(&local_var_content).ok();
184        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
185        Err(Error::ResponseError(local_var_error))
186    }
187}
188
189/// Retrieves the information useful while creating a new receipt.
190pub async fn get_receipt_pre_create_info(configuration: &configuration::Configuration, company_id: i32) -> Result<models::GetReceiptPreCreateInfoResponse, Error<GetReceiptPreCreateInfoError>> {
191    let local_var_configuration = configuration;
192
193    let local_var_client = &local_var_configuration.client;
194
195    let local_var_uri_str = format!("{}/c/{company_id}/receipts/info", local_var_configuration.base_path, company_id=company_id);
196    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
197
198    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
199        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
200    }
201    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
202        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
203    };
204    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
205        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
206    };
207
208    let local_var_req = local_var_req_builder.build()?;
209    let local_var_resp = local_var_client.execute(local_var_req).await?;
210
211    let local_var_status = local_var_resp.status();
212    let local_var_content = local_var_resp.text().await?;
213
214    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
215        serde_json::from_str(&local_var_content).map_err(Error::from)
216    } else {
217        let local_var_entity: Option<GetReceiptPreCreateInfoError> = serde_json::from_str(&local_var_content).ok();
218        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
219        Err(Error::ResponseError(local_var_error))
220    }
221}
222
223/// Returns the monthly totals by year and receipt type.
224pub async fn get_receipts_monthly_totals(configuration: &configuration::Configuration, company_id: i32, r#type: &str, year: &str) -> Result<models::GetReceiptsMonthlyTotalsResponse, Error<GetReceiptsMonthlyTotalsError>> {
225    let local_var_configuration = configuration;
226
227    let local_var_client = &local_var_configuration.client;
228
229    let local_var_uri_str = format!("{}/c/{company_id}/receipts/monthly_totals", local_var_configuration.base_path, company_id=company_id);
230    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
231
232    local_var_req_builder = local_var_req_builder.query(&[("type", &r#type.to_string())]);
233    local_var_req_builder = local_var_req_builder.query(&[("year", &year.to_string())]);
234    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
235        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
236    }
237    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
238        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
239    };
240    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
241        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
242    };
243
244    let local_var_req = local_var_req_builder.build()?;
245    let local_var_resp = local_var_client.execute(local_var_req).await?;
246
247    let local_var_status = local_var_resp.status();
248    let local_var_content = local_var_resp.text().await?;
249
250    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
251        serde_json::from_str(&local_var_content).map_err(Error::from)
252    } else {
253        let local_var_entity: Option<GetReceiptsMonthlyTotalsError> = serde_json::from_str(&local_var_content).ok();
254        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
255        Err(Error::ResponseError(local_var_error))
256    }
257}
258
259/// Lists the receipts.
260pub async fn list_receipts(configuration: &configuration::Configuration, company_id: i32, fields: Option<&str>, fieldset: Option<&str>, page: Option<i32>, per_page: Option<u8>, sort: Option<&str>, q: Option<&str>) -> Result<models::ListReceiptsResponse, Error<ListReceiptsError>> {
261    let local_var_configuration = configuration;
262
263    let local_var_client = &local_var_configuration.client;
264
265    let local_var_uri_str = format!("{}/c/{company_id}/receipts", local_var_configuration.base_path, company_id=company_id);
266    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
267
268    if let Some(ref local_var_str) = fields {
269        local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
270    }
271    if let Some(ref local_var_str) = fieldset {
272        local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
273    }
274    if let Some(ref local_var_str) = page {
275        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
276    }
277    if let Some(ref local_var_str) = per_page {
278        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
279    }
280    if let Some(ref local_var_str) = sort {
281        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
282    }
283    if let Some(ref local_var_str) = q {
284        local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
285    }
286    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
287        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
288    }
289    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
290        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
291    };
292    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
293        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
294    };
295
296    let local_var_req = local_var_req_builder.build()?;
297    let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299    let local_var_status = local_var_resp.status();
300    let local_var_content = local_var_resp.text().await?;
301
302    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
303        serde_json::from_str(&local_var_content).map_err(Error::from)
304    } else {
305        let local_var_entity: Option<ListReceiptsError> = serde_json::from_str(&local_var_content).ok();
306        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
307        Err(Error::ResponseError(local_var_error))
308    }
309}
310
311/// Modifies the specified receipt.
312pub async fn modify_receipt(configuration: &configuration::Configuration, company_id: i32, document_id: i32, modify_receipt_request: Option<models::ModifyReceiptRequest>) -> Result<models::ModifyReceiptResponse, Error<ModifyReceiptError>> {
313    let local_var_configuration = configuration;
314
315    let local_var_client = &local_var_configuration.client;
316
317    let local_var_uri_str = format!("{}/c/{company_id}/receipts/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
318    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
319
320    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
321        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
322    }
323    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
324        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
325    };
326    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
327        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
328    };
329    local_var_req_builder = local_var_req_builder.json(&modify_receipt_request);
330
331    let local_var_req = local_var_req_builder.build()?;
332    let local_var_resp = local_var_client.execute(local_var_req).await?;
333
334    let local_var_status = local_var_resp.status();
335    let local_var_content = local_var_resp.text().await?;
336
337    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
338        serde_json::from_str(&local_var_content).map_err(Error::from)
339    } else {
340        let local_var_entity: Option<ModifyReceiptError> = serde_json::from_str(&local_var_content).ok();
341        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
342        Err(Error::ResponseError(local_var_error))
343    }
344}
345