Skip to main content

bitwarden_api_api/apis/
stripe_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 StripeApi: Send + Sync {
29    /// POST /setup-intent/bank-account
30    async fn create_setup_intent_for_bank_account(
31        &self,
32    ) -> Result<(), Error<CreateSetupIntentForBankAccountError>>;
33
34    /// POST /setup-intent/card
35    async fn create_setup_intent_for_card(
36        &self,
37    ) -> Result<(), Error<CreateSetupIntentForCardError>>;
38
39    /// GET /tax/is-country-supported
40    async fn is_country_supported<'a>(
41        &self,
42        country: Option<&'a str>,
43    ) -> Result<(), Error<IsCountrySupportedError>>;
44}
45
46pub struct StripeApiClient {
47    configuration: Arc<configuration::Configuration>,
48}
49
50impl StripeApiClient {
51    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
52        Self { configuration }
53    }
54}
55
56#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
57#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
58impl StripeApi for StripeApiClient {
59    async fn create_setup_intent_for_bank_account(
60        &self,
61    ) -> Result<(), Error<CreateSetupIntentForBankAccountError>> {
62        let local_var_configuration = &self.configuration;
63
64        let local_var_client = &local_var_configuration.client;
65
66        let local_var_uri_str = format!(
67            "{}/setup-intent/bank-account",
68            local_var_configuration.base_path
69        );
70        let mut local_var_req_builder =
71            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
72
73        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
74
75        let local_var_resp = local_var_req_builder.send().await?;
76
77        let local_var_status = local_var_resp.status();
78        let local_var_content = local_var_resp.text().await?;
79
80        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
81            Ok(())
82        } else {
83            let local_var_entity: Option<CreateSetupIntentForBankAccountError> =
84                serde_json::from_str(&local_var_content).ok();
85            let local_var_error = ResponseContent {
86                status: local_var_status,
87                content: local_var_content,
88                entity: local_var_entity,
89            };
90            Err(Error::ResponseError(local_var_error))
91        }
92    }
93
94    async fn create_setup_intent_for_card(
95        &self,
96    ) -> Result<(), Error<CreateSetupIntentForCardError>> {
97        let local_var_configuration = &self.configuration;
98
99        let local_var_client = &local_var_configuration.client;
100
101        let local_var_uri_str = format!("{}/setup-intent/card", local_var_configuration.base_path);
102        let mut local_var_req_builder =
103            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
104
105        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
106
107        let local_var_resp = local_var_req_builder.send().await?;
108
109        let local_var_status = local_var_resp.status();
110        let local_var_content = local_var_resp.text().await?;
111
112        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113            Ok(())
114        } else {
115            let local_var_entity: Option<CreateSetupIntentForCardError> =
116                serde_json::from_str(&local_var_content).ok();
117            let local_var_error = ResponseContent {
118                status: local_var_status,
119                content: local_var_content,
120                entity: local_var_entity,
121            };
122            Err(Error::ResponseError(local_var_error))
123        }
124    }
125
126    async fn is_country_supported<'a>(
127        &self,
128        country: Option<&'a str>,
129    ) -> Result<(), Error<IsCountrySupportedError>> {
130        let local_var_configuration = &self.configuration;
131
132        let local_var_client = &local_var_configuration.client;
133
134        let local_var_uri_str = format!(
135            "{}/tax/is-country-supported",
136            local_var_configuration.base_path
137        );
138        let mut local_var_req_builder =
139            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
140
141        if let Some(ref param_value) = country {
142            local_var_req_builder =
143                local_var_req_builder.query(&[("country", &param_value.to_string())]);
144        }
145        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
146
147        let local_var_resp = local_var_req_builder.send().await?;
148
149        let local_var_status = local_var_resp.status();
150        let local_var_content = local_var_resp.text().await?;
151
152        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
153            Ok(())
154        } else {
155            let local_var_entity: Option<IsCountrySupportedError> =
156                serde_json::from_str(&local_var_content).ok();
157            let local_var_error = ResponseContent {
158                status: local_var_status,
159                content: local_var_content,
160                entity: local_var_entity,
161            };
162            Err(Error::ResponseError(local_var_error))
163        }
164    }
165}
166
167/// struct for typed errors of method [`StripeApi::create_setup_intent_for_bank_account`]
168#[derive(Debug, Clone, Serialize, Deserialize)]
169#[serde(untagged)]
170pub enum CreateSetupIntentForBankAccountError {
171    UnknownValue(serde_json::Value),
172}
173/// struct for typed errors of method [`StripeApi::create_setup_intent_for_card`]
174#[derive(Debug, Clone, Serialize, Deserialize)]
175#[serde(untagged)]
176pub enum CreateSetupIntentForCardError {
177    UnknownValue(serde_json::Value),
178}
179/// struct for typed errors of method [`StripeApi::is_country_supported`]
180#[derive(Debug, Clone, Serialize, Deserialize)]
181#[serde(untagged)]
182pub enum IsCountrySupportedError {
183    UnknownValue(serde_json::Value),
184}