bitwarden_api_api/apis/
provider_billing_api.rs1use 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 ProviderBillingApi: Send + Sync {
29 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 async fn get_invoices<'a>(
38 &self,
39 provider_id: uuid::Uuid,
40 ) -> Result<(), Error<GetInvoicesError>>;
41
42 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_user_agent) = local_var_configuration.user_agent {
81 local_var_req_builder = local_var_req_builder
82 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83 }
84 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
85 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
86 };
87
88 let local_var_req = local_var_req_builder.build()?;
89 let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91 let local_var_status = local_var_resp.status();
92 let local_var_content = local_var_resp.text().await?;
93
94 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95 Ok(())
96 } else {
97 let local_var_entity: Option<GenerateClientInvoiceReportError> =
98 serde_json::from_str(&local_var_content).ok();
99 let local_var_error = ResponseContent {
100 status: local_var_status,
101 content: local_var_content,
102 entity: local_var_entity,
103 };
104 Err(Error::ResponseError(local_var_error))
105 }
106 }
107
108 async fn get_invoices<'a>(
109 &self,
110 provider_id: uuid::Uuid,
111 ) -> Result<(), Error<GetInvoicesError>> {
112 let local_var_configuration = &self.configuration;
113
114 let local_var_client = &local_var_configuration.client;
115
116 let local_var_uri_str = format!(
117 "{}/providers/{providerId}/billing/invoices",
118 local_var_configuration.base_path,
119 providerId = provider_id
120 );
121 let mut local_var_req_builder =
122 local_var_client.request(reqwest::Method::GET, 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
126 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
127 }
128 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
129 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
130 };
131
132 let local_var_req = local_var_req_builder.build()?;
133 let local_var_resp = local_var_client.execute(local_var_req).await?;
134
135 let local_var_status = local_var_resp.status();
136 let local_var_content = local_var_resp.text().await?;
137
138 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139 Ok(())
140 } else {
141 let local_var_entity: Option<GetInvoicesError> =
142 serde_json::from_str(&local_var_content).ok();
143 let local_var_error = ResponseContent {
144 status: local_var_status,
145 content: local_var_content,
146 entity: local_var_entity,
147 };
148 Err(Error::ResponseError(local_var_error))
149 }
150 }
151
152 async fn get_subscription<'a>(
153 &self,
154 provider_id: uuid::Uuid,
155 ) -> Result<(), Error<GetSubscriptionError>> {
156 let local_var_configuration = &self.configuration;
157
158 let local_var_client = &local_var_configuration.client;
159
160 let local_var_uri_str = format!(
161 "{}/providers/{providerId}/billing/subscription",
162 local_var_configuration.base_path,
163 providerId = provider_id
164 );
165 let mut local_var_req_builder =
166 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
167
168 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
169 local_var_req_builder = local_var_req_builder
170 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
171 }
172 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
173 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
174 };
175
176 let local_var_req = local_var_req_builder.build()?;
177 let local_var_resp = local_var_client.execute(local_var_req).await?;
178
179 let local_var_status = local_var_resp.status();
180 let local_var_content = local_var_resp.text().await?;
181
182 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
183 Ok(())
184 } else {
185 let local_var_entity: Option<GetSubscriptionError> =
186 serde_json::from_str(&local_var_content).ok();
187 let local_var_error = ResponseContent {
188 status: local_var_status,
189 content: local_var_content,
190 entity: local_var_entity,
191 };
192 Err(Error::ResponseError(local_var_error))
193 }
194 }
195}
196
197#[derive(Debug, Clone, Serialize, Deserialize)]
199#[serde(untagged)]
200pub enum GenerateClientInvoiceReportError {
201 UnknownValue(serde_json::Value),
202}
203#[derive(Debug, Clone, Serialize, Deserialize)]
205#[serde(untagged)]
206pub enum GetInvoicesError {
207 UnknownValue(serde_json::Value),
208}
209#[derive(Debug, Clone, Serialize, Deserialize)]
211#[serde(untagged)]
212pub enum GetSubscriptionError {
213 UnknownValue(serde_json::Value),
214}