bitwarden_api_api/apis/
provider_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::{AuthRequired, 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 ProviderBillingApi: Send + Sync {
29    /// GET /providers/{providerId}/billing/invoices/{invoiceId}
30    async fn generate_client_invoice_report<'a>(
31        &self,
32        provider_id: uuid::Uuid,
33        invoice_id: &'a str,
34    ) -> Result<(), Error<GenerateClientInvoiceReportError>>;
35
36    /// GET /providers/{providerId}/billing/invoices
37    async fn get_invoices<'a>(
38        &self,
39        provider_id: uuid::Uuid,
40    ) -> Result<(), Error<GetInvoicesError>>;
41
42    /// GET /providers/{providerId}/billing/subscription
43    async fn get_subscription<'a>(
44        &self,
45        provider_id: uuid::Uuid,
46    ) -> Result<(), Error<GetSubscriptionError>>;
47}
48
49pub struct ProviderBillingApiClient {
50    configuration: Arc<configuration::Configuration>,
51}
52
53impl ProviderBillingApiClient {
54    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
55        Self { configuration }
56    }
57}
58
59#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
60#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
61impl ProviderBillingApi for ProviderBillingApiClient {
62    async fn generate_client_invoice_report<'a>(
63        &self,
64        provider_id: uuid::Uuid,
65        invoice_id: &'a str,
66    ) -> Result<(), Error<GenerateClientInvoiceReportError>> {
67        let local_var_configuration = &self.configuration;
68
69        let local_var_client = &local_var_configuration.client;
70
71        let local_var_uri_str = format!(
72            "{}/providers/{providerId}/billing/invoices/{invoiceId}",
73            local_var_configuration.base_path,
74            providerId = provider_id,
75            invoiceId = crate::apis::urlencode(invoice_id)
76        );
77        let mut local_var_req_builder =
78            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
79
80        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
81            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82        };
83        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
84
85        let local_var_req = local_var_req_builder.build()?;
86        let local_var_resp = local_var_client.execute(local_var_req).await?;
87
88        let local_var_status = local_var_resp.status();
89        let local_var_content = local_var_resp.text().await?;
90
91        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
92            Ok(())
93        } else {
94            let local_var_entity: Option<GenerateClientInvoiceReportError> =
95                serde_json::from_str(&local_var_content).ok();
96            let local_var_error = ResponseContent {
97                status: local_var_status,
98                content: local_var_content,
99                entity: local_var_entity,
100            };
101            Err(Error::ResponseError(local_var_error))
102        }
103    }
104
105    async fn get_invoices<'a>(
106        &self,
107        provider_id: uuid::Uuid,
108    ) -> Result<(), Error<GetInvoicesError>> {
109        let local_var_configuration = &self.configuration;
110
111        let local_var_client = &local_var_configuration.client;
112
113        let local_var_uri_str = format!(
114            "{}/providers/{providerId}/billing/invoices",
115            local_var_configuration.base_path,
116            providerId = provider_id
117        );
118        let mut local_var_req_builder =
119            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
120
121        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
122            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
123        };
124        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
125
126        let local_var_req = local_var_req_builder.build()?;
127        let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129        let local_var_status = local_var_resp.status();
130        let local_var_content = local_var_resp.text().await?;
131
132        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
133            Ok(())
134        } else {
135            let local_var_entity: Option<GetInvoicesError> =
136                serde_json::from_str(&local_var_content).ok();
137            let local_var_error = ResponseContent {
138                status: local_var_status,
139                content: local_var_content,
140                entity: local_var_entity,
141            };
142            Err(Error::ResponseError(local_var_error))
143        }
144    }
145
146    async fn get_subscription<'a>(
147        &self,
148        provider_id: uuid::Uuid,
149    ) -> Result<(), Error<GetSubscriptionError>> {
150        let local_var_configuration = &self.configuration;
151
152        let local_var_client = &local_var_configuration.client;
153
154        let local_var_uri_str = format!(
155            "{}/providers/{providerId}/billing/subscription",
156            local_var_configuration.base_path,
157            providerId = provider_id
158        );
159        let mut local_var_req_builder =
160            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
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        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
166
167        let local_var_req = local_var_req_builder.build()?;
168        let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170        let local_var_status = local_var_resp.status();
171        let local_var_content = local_var_resp.text().await?;
172
173        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174            Ok(())
175        } else {
176            let local_var_entity: Option<GetSubscriptionError> =
177                serde_json::from_str(&local_var_content).ok();
178            let local_var_error = ResponseContent {
179                status: local_var_status,
180                content: local_var_content,
181                entity: local_var_entity,
182            };
183            Err(Error::ResponseError(local_var_error))
184        }
185    }
186}
187
188/// struct for typed errors of method [`ProviderBillingApi::generate_client_invoice_report`]
189#[derive(Debug, Clone, Serialize, Deserialize)]
190#[serde(untagged)]
191pub enum GenerateClientInvoiceReportError {
192    UnknownValue(serde_json::Value),
193}
194/// struct for typed errors of method [`ProviderBillingApi::get_invoices`]
195#[derive(Debug, Clone, Serialize, Deserialize)]
196#[serde(untagged)]
197pub enum GetInvoicesError {
198    UnknownValue(serde_json::Value),
199}
200/// struct for typed errors of method [`ProviderBillingApi::get_subscription`]
201#[derive(Debug, Clone, Serialize, Deserialize)]
202#[serde(untagged)]
203pub enum GetSubscriptionError {
204    UnknownValue(serde_json::Value),
205}