Skip to main content

bitwarden_api_api/apis/
user_subscriptions_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 UserSubscriptionsApi: Send + Sync {
29    /// GET /account/billing/subscription/preview
30    /// Previews the account's upcoming subscription renewal.
31    async fn get_account_subscription_preview(&self) -> Result<models::SubscriptionPreview, Error>;
32
33    /// GET /account/billing/subscription/purchase/preview
34    /// Previews the invoice for purchasing a Premium subscription.
35    async fn get_account_subscription_purchase_preview<'a>(
36        &self,
37        additional_storage: Option<i32>,
38        coupons: Option<Vec<String>>,
39        country: Option<&'a str>,
40        postal_code: Option<&'a str>,
41    ) -> Result<models::InvoicePreview, Error>;
42
43    /// GET /account/billing/subscription/upgrade/preview
44    /// Previews the invoice for upgrading the user's Premium subscription to an organization plan.
45    async fn get_account_subscription_upgrade_preview<'a>(
46        &self,
47        target_product_tier_type: models::ProductTierType,
48        country: Option<&'a str>,
49        postal_code: Option<&'a str>,
50    ) -> Result<models::InvoicePreview, Error>;
51}
52
53pub struct UserSubscriptionsApiClient {
54    configuration: Arc<configuration::Configuration>,
55}
56
57impl UserSubscriptionsApiClient {
58    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
59        Self { configuration }
60    }
61}
62
63#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
64#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
65impl UserSubscriptionsApi for UserSubscriptionsApiClient {
66    /// Previews the account's upcoming subscription renewal.
67    async fn get_account_subscription_preview(&self) -> Result<models::SubscriptionPreview, Error> {
68        let local_var_configuration = &self.configuration;
69
70        let local_var_client = &local_var_configuration.client;
71
72        let local_var_uri_str = format!(
73            "{}/account/billing/subscription/preview",
74            local_var_configuration.base_path
75        );
76        let mut local_var_req_builder =
77            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
78
79        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
80
81        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
82    }
83
84    /// Previews the invoice for purchasing a Premium subscription.
85    async fn get_account_subscription_purchase_preview<'a>(
86        &self,
87        additional_storage: Option<i32>,
88        coupons: Option<Vec<String>>,
89        country: Option<&'a str>,
90        postal_code: Option<&'a str>,
91    ) -> Result<models::InvoicePreview, Error> {
92        let local_var_configuration = &self.configuration;
93
94        let local_var_client = &local_var_configuration.client;
95
96        let local_var_uri_str = format!(
97            "{}/account/billing/subscription/purchase/preview",
98            local_var_configuration.base_path
99        );
100        let mut local_var_req_builder =
101            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
102
103        if let Some(ref param_value) = additional_storage {
104            local_var_req_builder =
105                local_var_req_builder.query(&[("additionalStorage", &param_value.to_string())]);
106        }
107        if let Some(ref param_value) = coupons {
108            local_var_req_builder = match "multi" {
109                "multi" => local_var_req_builder.query(
110                    &param_value
111                        .into_iter()
112                        .map(|p| ("coupons".to_owned(), p.to_string()))
113                        .collect::<Vec<(std::string::String, std::string::String)>>(),
114                ),
115                _ => local_var_req_builder.query(&[(
116                    "coupons",
117                    &param_value
118                        .into_iter()
119                        .map(|p| p.to_string())
120                        .collect::<Vec<String>>()
121                        .join(",")
122                        .to_string(),
123                )]),
124            };
125        }
126        if let Some(ref param_value) = country {
127            local_var_req_builder =
128                local_var_req_builder.query(&[("country", &param_value.to_string())]);
129        }
130        if let Some(ref param_value) = postal_code {
131            local_var_req_builder =
132                local_var_req_builder.query(&[("postalCode", &param_value.to_string())]);
133        }
134        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
135
136        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
137    }
138
139    /// Previews the invoice for upgrading the user's Premium subscription to an organization plan.
140    async fn get_account_subscription_upgrade_preview<'a>(
141        &self,
142        target_product_tier_type: models::ProductTierType,
143        country: Option<&'a str>,
144        postal_code: Option<&'a str>,
145    ) -> Result<models::InvoicePreview, Error> {
146        let local_var_configuration = &self.configuration;
147
148        let local_var_client = &local_var_configuration.client;
149
150        let local_var_uri_str = format!(
151            "{}/account/billing/subscription/upgrade/preview",
152            local_var_configuration.base_path
153        );
154        let mut local_var_req_builder =
155            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
156
157        local_var_req_builder = local_var_req_builder.query(&[(
158            "targetProductTierType",
159            &target_product_tier_type.to_string(),
160        )]);
161        if let Some(ref param_value) = country {
162            local_var_req_builder =
163                local_var_req_builder.query(&[("country", &param_value.to_string())]);
164        }
165        if let Some(ref param_value) = postal_code {
166            local_var_req_builder =
167                local_var_req_builder.query(&[("postalCode", &param_value.to_string())]);
168        }
169        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
170
171        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
172    }
173}