1use 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 AccountBillingVNextApi: Send + Sync {
29 async fn add_credit_via_bit_pay<'a>(
31 &self,
32 bit_pay_credit_request: Option<models::BitPayCreditRequest>,
33 ) -> Result<(), Error>;
34
35 async fn create_portal_session(&self) -> Result<(), Error>;
37
38 async fn create_premium_checkout_session<'a>(
40 &self,
41 create_premium_checkout_session_request: Option<
42 models::CreatePremiumCheckoutSessionRequest,
43 >,
44 ) -> Result<(), Error>;
45
46 async fn create_subscription<'a>(
48 &self,
49 premium_cloud_hosted_subscription_request: Option<
50 models::PremiumCloudHostedSubscriptionRequest,
51 >,
52 ) -> Result<(), Error>;
53
54 async fn get_applicable_discounts(&self) -> Result<(), Error>;
56
57 async fn get_credit(&self) -> Result<(), Error>;
59
60 async fn get_license(&self) -> Result<(), Error>;
62
63 async fn get_payment_method(&self) -> Result<(), Error>;
65
66 async fn get_subscription(&self) -> Result<(), Error>;
68
69 async fn reinstate_subscription(&self) -> Result<(), Error>;
71
72 async fn update_payment_method<'a>(
74 &self,
75 tokenized_payment_method_request: Option<models::TokenizedPaymentMethodRequest>,
76 ) -> Result<(), Error>;
77
78 async fn update_subscription_storage<'a>(
80 &self,
81 storage_update_request: Option<models::StorageUpdateRequest>,
82 ) -> Result<(), Error>;
83
84 async fn upgrade_premium_to_organization<'a>(
86 &self,
87 upgrade_premium_to_organization_request: Option<
88 models::UpgradePremiumToOrganizationRequest,
89 >,
90 ) -> Result<(), Error>;
91}
92
93pub struct AccountBillingVNextApiClient {
94 configuration: Arc<configuration::Configuration>,
95}
96
97impl AccountBillingVNextApiClient {
98 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
99 Self { configuration }
100 }
101}
102
103#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
104#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
105impl AccountBillingVNextApi for AccountBillingVNextApiClient {
106 async fn add_credit_via_bit_pay<'a>(
107 &self,
108 bit_pay_credit_request: Option<models::BitPayCreditRequest>,
109 ) -> Result<(), Error> {
110 let local_var_configuration = &self.configuration;
111
112 let local_var_client = &local_var_configuration.client;
113
114 let local_var_uri_str = format!(
115 "{}/account/billing/vnext/credit/bitpay",
116 local_var_configuration.base_path
117 );
118 let mut local_var_req_builder =
119 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
120
121 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
122 local_var_req_builder = local_var_req_builder.json(&bit_pay_credit_request);
123
124 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
125 }
126
127 async fn create_portal_session(&self) -> Result<(), Error> {
128 let local_var_configuration = &self.configuration;
129
130 let local_var_client = &local_var_configuration.client;
131
132 let local_var_uri_str = format!(
133 "{}/account/billing/vnext/portal-session",
134 local_var_configuration.base_path
135 );
136 let mut local_var_req_builder =
137 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
138
139 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
140
141 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
142 }
143
144 async fn create_premium_checkout_session<'a>(
145 &self,
146 create_premium_checkout_session_request: Option<
147 models::CreatePremiumCheckoutSessionRequest,
148 >,
149 ) -> Result<(), Error> {
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 "{}/account/billing/vnext/premium/checkout",
156 local_var_configuration.base_path
157 );
158 let mut local_var_req_builder =
159 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
160
161 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
162 local_var_req_builder =
163 local_var_req_builder.json(&create_premium_checkout_session_request);
164
165 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
166 }
167
168 async fn create_subscription<'a>(
169 &self,
170 premium_cloud_hosted_subscription_request: Option<
171 models::PremiumCloudHostedSubscriptionRequest,
172 >,
173 ) -> Result<(), Error> {
174 let local_var_configuration = &self.configuration;
175
176 let local_var_client = &local_var_configuration.client;
177
178 let local_var_uri_str = format!(
179 "{}/account/billing/vnext/subscription",
180 local_var_configuration.base_path
181 );
182 let mut local_var_req_builder =
183 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
184
185 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
186 local_var_req_builder =
187 local_var_req_builder.json(&premium_cloud_hosted_subscription_request);
188
189 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
190 }
191
192 async fn get_applicable_discounts(&self) -> Result<(), Error> {
193 let local_var_configuration = &self.configuration;
194
195 let local_var_client = &local_var_configuration.client;
196
197 let local_var_uri_str = format!(
198 "{}/account/billing/vnext/discounts",
199 local_var_configuration.base_path
200 );
201 let mut local_var_req_builder =
202 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
203
204 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
205
206 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
207 }
208
209 async fn get_credit(&self) -> Result<(), Error> {
210 let local_var_configuration = &self.configuration;
211
212 let local_var_client = &local_var_configuration.client;
213
214 let local_var_uri_str = format!(
215 "{}/account/billing/vnext/credit",
216 local_var_configuration.base_path
217 );
218 let mut local_var_req_builder =
219 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
220
221 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
222
223 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
224 }
225
226 async fn get_license(&self) -> Result<(), Error> {
227 let local_var_configuration = &self.configuration;
228
229 let local_var_client = &local_var_configuration.client;
230
231 let local_var_uri_str = format!(
232 "{}/account/billing/vnext/license",
233 local_var_configuration.base_path
234 );
235 let mut local_var_req_builder =
236 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
237
238 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
239
240 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
241 }
242
243 async fn get_payment_method(&self) -> Result<(), Error> {
244 let local_var_configuration = &self.configuration;
245
246 let local_var_client = &local_var_configuration.client;
247
248 let local_var_uri_str = format!(
249 "{}/account/billing/vnext/payment-method",
250 local_var_configuration.base_path
251 );
252 let mut local_var_req_builder =
253 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
254
255 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
256
257 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
258 }
259
260 async fn get_subscription(&self) -> Result<(), Error> {
261 let local_var_configuration = &self.configuration;
262
263 let local_var_client = &local_var_configuration.client;
264
265 let local_var_uri_str = format!(
266 "{}/account/billing/vnext/subscription",
267 local_var_configuration.base_path
268 );
269 let mut local_var_req_builder =
270 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
271
272 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
273
274 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
275 }
276
277 async fn reinstate_subscription(&self) -> Result<(), Error> {
278 let local_var_configuration = &self.configuration;
279
280 let local_var_client = &local_var_configuration.client;
281
282 let local_var_uri_str = format!(
283 "{}/account/billing/vnext/subscription/reinstate",
284 local_var_configuration.base_path
285 );
286 let mut local_var_req_builder =
287 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
288
289 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
290
291 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
292 }
293
294 async fn update_payment_method<'a>(
295 &self,
296 tokenized_payment_method_request: Option<models::TokenizedPaymentMethodRequest>,
297 ) -> Result<(), Error> {
298 let local_var_configuration = &self.configuration;
299
300 let local_var_client = &local_var_configuration.client;
301
302 let local_var_uri_str = format!(
303 "{}/account/billing/vnext/payment-method",
304 local_var_configuration.base_path
305 );
306 let mut local_var_req_builder =
307 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
308
309 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
310 local_var_req_builder = local_var_req_builder.json(&tokenized_payment_method_request);
311
312 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
313 }
314
315 async fn update_subscription_storage<'a>(
316 &self,
317 storage_update_request: Option<models::StorageUpdateRequest>,
318 ) -> Result<(), Error> {
319 let local_var_configuration = &self.configuration;
320
321 let local_var_client = &local_var_configuration.client;
322
323 let local_var_uri_str = format!(
324 "{}/account/billing/vnext/subscription/storage",
325 local_var_configuration.base_path
326 );
327 let mut local_var_req_builder =
328 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
329
330 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
331 local_var_req_builder = local_var_req_builder.json(&storage_update_request);
332
333 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
334 }
335
336 async fn upgrade_premium_to_organization<'a>(
337 &self,
338 upgrade_premium_to_organization_request: Option<
339 models::UpgradePremiumToOrganizationRequest,
340 >,
341 ) -> Result<(), Error> {
342 let local_var_configuration = &self.configuration;
343
344 let local_var_client = &local_var_configuration.client;
345
346 let local_var_uri_str = format!(
347 "{}/account/billing/vnext/upgrade",
348 local_var_configuration.base_path
349 );
350 let mut local_var_req_builder =
351 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
352
353 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
354 local_var_req_builder =
355 local_var_req_builder.json(&upgrade_premium_to_organization_request);
356
357 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
358 }
359}