bitwarden_api_api/apis/
accounts_billing_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait AccountsBillingApi: Send + Sync {
29    /// GET /accounts/billing/history
30    async fn get_billing_history(
31        &self,
32    ) -> Result<models::BillingHistoryResponseModel, Error<GetBillingHistoryError>>;
33
34    /// GET /accounts/billing/invoices
35    async fn get_invoices<'a>(
36        &self,
37        status: Option<&'a str>,
38        start_after: Option<&'a str>,
39    ) -> Result<(), Error<GetInvoicesError>>;
40
41    /// GET /accounts/billing/payment-method
42    async fn get_payment_method(
43        &self,
44    ) -> Result<models::BillingPaymentResponseModel, Error<GetPaymentMethodError>>;
45
46    /// GET /accounts/billing/transactions
47    async fn get_transactions<'a>(
48        &self,
49        start_after: Option<String>,
50    ) -> Result<(), Error<GetTransactionsError>>;
51
52    /// POST /accounts/billing/preview-invoice
53    async fn preview_invoice<'a>(
54        &self,
55        preview_individual_invoice_request_body: Option<
56            models::PreviewIndividualInvoiceRequestBody,
57        >,
58    ) -> Result<(), Error<PreviewInvoiceError>>;
59}
60
61pub struct AccountsBillingApiClient {
62    configuration: Arc<configuration::Configuration>,
63}
64
65impl AccountsBillingApiClient {
66    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
67        Self { configuration }
68    }
69}
70
71#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
72#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
73impl AccountsBillingApi for AccountsBillingApiClient {
74    async fn get_billing_history(
75        &self,
76    ) -> Result<models::BillingHistoryResponseModel, Error<GetBillingHistoryError>> {
77        let local_var_configuration = &self.configuration;
78
79        let local_var_client = &local_var_configuration.client;
80
81        let local_var_uri_str = format!(
82            "{}/accounts/billing/history",
83            local_var_configuration.base_path
84        );
85        let mut local_var_req_builder =
86            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
87
88        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
89            local_var_req_builder = local_var_req_builder
90                .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
96        let local_var_req = local_var_req_builder.build()?;
97        let local_var_resp = local_var_client.execute(local_var_req).await?;
98
99        let local_var_status = local_var_resp.status();
100        let local_var_content_type = local_var_resp
101            .headers()
102            .get("content-type")
103            .and_then(|v| v.to_str().ok())
104            .unwrap_or("application/octet-stream");
105        let local_var_content_type = super::ContentType::from(local_var_content_type);
106        let local_var_content = local_var_resp.text().await?;
107
108        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
109            match local_var_content_type {
110                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
111                ContentType::Text => {
112                    return Err(Error::from(serde_json::Error::custom(
113                        "Received `text/plain` content type response that cannot be converted to `models::BillingHistoryResponseModel`",
114                    )));
115                }
116                ContentType::Unsupported(local_var_unknown_type) => {
117                    return Err(Error::from(serde_json::Error::custom(format!(
118                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BillingHistoryResponseModel`"
119                    ))));
120                }
121            }
122        } else {
123            let local_var_entity: Option<GetBillingHistoryError> =
124                serde_json::from_str(&local_var_content).ok();
125            let local_var_error = ResponseContent {
126                status: local_var_status,
127                content: local_var_content,
128                entity: local_var_entity,
129            };
130            Err(Error::ResponseError(local_var_error))
131        }
132    }
133
134    async fn get_invoices<'a>(
135        &self,
136        status: Option<&'a str>,
137        start_after: Option<&'a str>,
138    ) -> Result<(), Error<GetInvoicesError>> {
139        let local_var_configuration = &self.configuration;
140
141        let local_var_client = &local_var_configuration.client;
142
143        let local_var_uri_str = format!(
144            "{}/accounts/billing/invoices",
145            local_var_configuration.base_path
146        );
147        let mut local_var_req_builder =
148            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
149
150        if let Some(ref param_value) = status {
151            local_var_req_builder =
152                local_var_req_builder.query(&[("status", &param_value.to_string())]);
153        }
154        if let Some(ref param_value) = start_after {
155            local_var_req_builder =
156                local_var_req_builder.query(&[("startAfter", &param_value.to_string())]);
157        }
158        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
159            local_var_req_builder = local_var_req_builder
160                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
161        }
162        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
163            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
164        };
165
166        let local_var_req = local_var_req_builder.build()?;
167        let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169        let local_var_status = local_var_resp.status();
170        let local_var_content = local_var_resp.text().await?;
171
172        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173            Ok(())
174        } else {
175            let local_var_entity: Option<GetInvoicesError> =
176                serde_json::from_str(&local_var_content).ok();
177            let local_var_error = ResponseContent {
178                status: local_var_status,
179                content: local_var_content,
180                entity: local_var_entity,
181            };
182            Err(Error::ResponseError(local_var_error))
183        }
184    }
185
186    async fn get_payment_method(
187        &self,
188    ) -> Result<models::BillingPaymentResponseModel, Error<GetPaymentMethodError>> {
189        let local_var_configuration = &self.configuration;
190
191        let local_var_client = &local_var_configuration.client;
192
193        let local_var_uri_str = format!(
194            "{}/accounts/billing/payment-method",
195            local_var_configuration.base_path
196        );
197        let mut local_var_req_builder =
198            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
199
200        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
201            local_var_req_builder = local_var_req_builder
202                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
203        }
204        if let Some(ref local_var_token) = local_var_configuration.oauth_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_type = local_var_resp
213            .headers()
214            .get("content-type")
215            .and_then(|v| v.to_str().ok())
216            .unwrap_or("application/octet-stream");
217        let local_var_content_type = super::ContentType::from(local_var_content_type);
218        let local_var_content = local_var_resp.text().await?;
219
220        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
221            match local_var_content_type {
222                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
223                ContentType::Text => {
224                    return Err(Error::from(serde_json::Error::custom(
225                        "Received `text/plain` content type response that cannot be converted to `models::BillingPaymentResponseModel`",
226                    )));
227                }
228                ContentType::Unsupported(local_var_unknown_type) => {
229                    return Err(Error::from(serde_json::Error::custom(format!(
230                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BillingPaymentResponseModel`"
231                    ))));
232                }
233            }
234        } else {
235            let local_var_entity: Option<GetPaymentMethodError> =
236                serde_json::from_str(&local_var_content).ok();
237            let local_var_error = ResponseContent {
238                status: local_var_status,
239                content: local_var_content,
240                entity: local_var_entity,
241            };
242            Err(Error::ResponseError(local_var_error))
243        }
244    }
245
246    async fn get_transactions<'a>(
247        &self,
248        start_after: Option<String>,
249    ) -> Result<(), Error<GetTransactionsError>> {
250        let local_var_configuration = &self.configuration;
251
252        let local_var_client = &local_var_configuration.client;
253
254        let local_var_uri_str = format!(
255            "{}/accounts/billing/transactions",
256            local_var_configuration.base_path
257        );
258        let mut local_var_req_builder =
259            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
260
261        if let Some(ref param_value) = start_after {
262            local_var_req_builder =
263                local_var_req_builder.query(&[("startAfter", &param_value.to_string())]);
264        }
265        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
266            local_var_req_builder = local_var_req_builder
267                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268        }
269        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
270            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
271        };
272
273        let local_var_req = local_var_req_builder.build()?;
274        let local_var_resp = local_var_client.execute(local_var_req).await?;
275
276        let local_var_status = local_var_resp.status();
277        let local_var_content = local_var_resp.text().await?;
278
279        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
280            Ok(())
281        } else {
282            let local_var_entity: Option<GetTransactionsError> =
283                serde_json::from_str(&local_var_content).ok();
284            let local_var_error = ResponseContent {
285                status: local_var_status,
286                content: local_var_content,
287                entity: local_var_entity,
288            };
289            Err(Error::ResponseError(local_var_error))
290        }
291    }
292
293    async fn preview_invoice<'a>(
294        &self,
295        preview_individual_invoice_request_body: Option<
296            models::PreviewIndividualInvoiceRequestBody,
297        >,
298    ) -> Result<(), Error<PreviewInvoiceError>> {
299        let local_var_configuration = &self.configuration;
300
301        let local_var_client = &local_var_configuration.client;
302
303        let local_var_uri_str = format!(
304            "{}/accounts/billing/preview-invoice",
305            local_var_configuration.base_path
306        );
307        let mut local_var_req_builder =
308            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
309
310        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
311            local_var_req_builder = local_var_req_builder
312                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
313        }
314        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
315            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
316        };
317        local_var_req_builder =
318            local_var_req_builder.json(&preview_individual_invoice_request_body);
319
320        let local_var_req = local_var_req_builder.build()?;
321        let local_var_resp = local_var_client.execute(local_var_req).await?;
322
323        let local_var_status = local_var_resp.status();
324        let local_var_content = local_var_resp.text().await?;
325
326        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
327            Ok(())
328        } else {
329            let local_var_entity: Option<PreviewInvoiceError> =
330                serde_json::from_str(&local_var_content).ok();
331            let local_var_error = ResponseContent {
332                status: local_var_status,
333                content: local_var_content,
334                entity: local_var_entity,
335            };
336            Err(Error::ResponseError(local_var_error))
337        }
338    }
339}
340
341/// struct for typed errors of method [`AccountsBillingApi::get_billing_history`]
342#[derive(Debug, Clone, Serialize, Deserialize)]
343#[serde(untagged)]
344pub enum GetBillingHistoryError {
345    UnknownValue(serde_json::Value),
346}
347/// struct for typed errors of method [`AccountsBillingApi::get_invoices`]
348#[derive(Debug, Clone, Serialize, Deserialize)]
349#[serde(untagged)]
350pub enum GetInvoicesError {
351    UnknownValue(serde_json::Value),
352}
353/// struct for typed errors of method [`AccountsBillingApi::get_payment_method`]
354#[derive(Debug, Clone, Serialize, Deserialize)]
355#[serde(untagged)]
356pub enum GetPaymentMethodError {
357    UnknownValue(serde_json::Value),
358}
359/// struct for typed errors of method [`AccountsBillingApi::get_transactions`]
360#[derive(Debug, Clone, Serialize, Deserialize)]
361#[serde(untagged)]
362pub enum GetTransactionsError {
363    UnknownValue(serde_json::Value),
364}
365/// struct for typed errors of method [`AccountsBillingApi::preview_invoice`]
366#[derive(Debug, Clone, Serialize, Deserialize)]
367#[serde(untagged)]
368pub enum PreviewInvoiceError {
369    UnknownValue(serde_json::Value),
370}