stripe_misc/financial_connections_session/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct RetrieveFinancialConnectionsSessionBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    expand: Option<Vec<String>>,
9}
10impl RetrieveFinancialConnectionsSessionBuilder {
11    fn new() -> Self {
12        Self { expand: None }
13    }
14}
15/// Retrieves the details of a Financial Connections `Session`
16#[derive(Clone, Debug, serde::Serialize)]
17pub struct RetrieveFinancialConnectionsSession {
18    inner: RetrieveFinancialConnectionsSessionBuilder,
19    session: stripe_misc::FinancialConnectionsSessionId,
20}
21impl RetrieveFinancialConnectionsSession {
22    /// Construct a new `RetrieveFinancialConnectionsSession`.
23    pub fn new(session: impl Into<stripe_misc::FinancialConnectionsSessionId>) -> Self {
24        Self { session: session.into(), inner: RetrieveFinancialConnectionsSessionBuilder::new() }
25    }
26    /// Specifies which fields in the response should be expanded.
27    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
28        self.inner.expand = Some(expand.into());
29        self
30    }
31}
32impl RetrieveFinancialConnectionsSession {
33    /// Send the request and return the deserialized response.
34    pub async fn send<C: StripeClient>(
35        &self,
36        client: &C,
37    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
38        self.customize().send(client).await
39    }
40
41    /// Send the request and return the deserialized response, blocking until completion.
42    pub fn send_blocking<C: StripeBlockingClient>(
43        &self,
44        client: &C,
45    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
46        self.customize().send_blocking(client)
47    }
48}
49
50impl StripeRequest for RetrieveFinancialConnectionsSession {
51    type Output = stripe_misc::FinancialConnectionsSession;
52
53    fn build(&self) -> RequestBuilder {
54        let session = &self.session;
55        RequestBuilder::new(StripeMethod::Get, format!("/financial_connections/sessions/{session}"))
56            .query(&self.inner)
57    }
58}
59#[derive(Clone, Debug, serde::Serialize)]
60struct CreateFinancialConnectionsSessionBuilder {
61    account_holder: CreateFinancialConnectionsSessionAccountHolder,
62    #[serde(skip_serializing_if = "Option::is_none")]
63    expand: Option<Vec<String>>,
64    #[serde(skip_serializing_if = "Option::is_none")]
65    filters: Option<CreateFinancialConnectionsSessionFilters>,
66    permissions: Vec<stripe_misc::FinancialConnectionsSessionPermissions>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    prefetch: Option<Vec<stripe_misc::FinancialConnectionsSessionPrefetch>>,
69    #[serde(skip_serializing_if = "Option::is_none")]
70    return_url: Option<String>,
71}
72impl CreateFinancialConnectionsSessionBuilder {
73    fn new(
74        account_holder: impl Into<CreateFinancialConnectionsSessionAccountHolder>,
75        permissions: impl Into<Vec<stripe_misc::FinancialConnectionsSessionPermissions>>,
76    ) -> Self {
77        Self {
78            account_holder: account_holder.into(),
79            expand: None,
80            filters: None,
81            permissions: permissions.into(),
82            prefetch: None,
83            return_url: None,
84        }
85    }
86}
87/// The account holder to link accounts for.
88#[derive(Clone, Debug, serde::Serialize)]
89pub struct CreateFinancialConnectionsSessionAccountHolder {
90    /// The ID of the Stripe account whose accounts will be retrieved.
91    /// Should only be present if `type` is `account`.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub account: Option<String>,
94    /// The ID of the Stripe customer whose accounts will be retrieved.
95    /// Should only be present if `type` is `customer`.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub customer: Option<String>,
98    /// Type of account holder to collect accounts for.
99    #[serde(rename = "type")]
100    pub type_: CreateFinancialConnectionsSessionAccountHolderType,
101}
102impl CreateFinancialConnectionsSessionAccountHolder {
103    pub fn new(type_: impl Into<CreateFinancialConnectionsSessionAccountHolderType>) -> Self {
104        Self { account: None, customer: None, type_: type_.into() }
105    }
106}
107/// Type of account holder to collect accounts for.
108#[derive(Clone, Eq, PartialEq)]
109#[non_exhaustive]
110pub enum CreateFinancialConnectionsSessionAccountHolderType {
111    Account,
112    Customer,
113    /// An unrecognized value from Stripe. Should not be used as a request parameter.
114    Unknown(String),
115}
116impl CreateFinancialConnectionsSessionAccountHolderType {
117    pub fn as_str(&self) -> &str {
118        use CreateFinancialConnectionsSessionAccountHolderType::*;
119        match self {
120            Account => "account",
121            Customer => "customer",
122            Unknown(v) => v,
123        }
124    }
125}
126
127impl std::str::FromStr for CreateFinancialConnectionsSessionAccountHolderType {
128    type Err = std::convert::Infallible;
129    fn from_str(s: &str) -> Result<Self, Self::Err> {
130        use CreateFinancialConnectionsSessionAccountHolderType::*;
131        match s {
132            "account" => Ok(Account),
133            "customer" => Ok(Customer),
134            v => {
135                tracing::warn!(
136                    "Unknown value '{}' for enum '{}'",
137                    v,
138                    "CreateFinancialConnectionsSessionAccountHolderType"
139                );
140                Ok(Unknown(v.to_owned()))
141            }
142        }
143    }
144}
145impl std::fmt::Display for CreateFinancialConnectionsSessionAccountHolderType {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150
151impl std::fmt::Debug for CreateFinancialConnectionsSessionAccountHolderType {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156impl serde::Serialize for CreateFinancialConnectionsSessionAccountHolderType {
157    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
158    where
159        S: serde::Serializer,
160    {
161        serializer.serialize_str(self.as_str())
162    }
163}
164#[cfg(feature = "deserialize")]
165impl<'de> serde::Deserialize<'de> for CreateFinancialConnectionsSessionAccountHolderType {
166    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
167        use std::str::FromStr;
168        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
169        Ok(Self::from_str(&s).expect("infallible"))
170    }
171}
172/// Filters to restrict the kinds of accounts to collect.
173#[derive(Clone, Debug, serde::Serialize)]
174pub struct CreateFinancialConnectionsSessionFilters {
175    /// Restricts the Session to subcategories of accounts that can be linked.
176    /// Valid subcategories are: `checking`, `savings`, `mortgage`, `line_of_credit`, `credit_card`.
177    #[serde(skip_serializing_if = "Option::is_none")]
178    pub account_subcategories:
179        Option<Vec<CreateFinancialConnectionsSessionFiltersAccountSubcategories>>,
180    /// List of countries from which to collect accounts.
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub countries: Option<Vec<String>>,
183}
184impl CreateFinancialConnectionsSessionFilters {
185    pub fn new() -> Self {
186        Self { account_subcategories: None, countries: None }
187    }
188}
189impl Default for CreateFinancialConnectionsSessionFilters {
190    fn default() -> Self {
191        Self::new()
192    }
193}
194/// Restricts the Session to subcategories of accounts that can be linked.
195/// Valid subcategories are: `checking`, `savings`, `mortgage`, `line_of_credit`, `credit_card`.
196#[derive(Clone, Eq, PartialEq)]
197#[non_exhaustive]
198pub enum CreateFinancialConnectionsSessionFiltersAccountSubcategories {
199    Checking,
200    CreditCard,
201    LineOfCredit,
202    Mortgage,
203    Savings,
204    /// An unrecognized value from Stripe. Should not be used as a request parameter.
205    Unknown(String),
206}
207impl CreateFinancialConnectionsSessionFiltersAccountSubcategories {
208    pub fn as_str(&self) -> &str {
209        use CreateFinancialConnectionsSessionFiltersAccountSubcategories::*;
210        match self {
211            Checking => "checking",
212            CreditCard => "credit_card",
213            LineOfCredit => "line_of_credit",
214            Mortgage => "mortgage",
215            Savings => "savings",
216            Unknown(v) => v,
217        }
218    }
219}
220
221impl std::str::FromStr for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
222    type Err = std::convert::Infallible;
223    fn from_str(s: &str) -> Result<Self, Self::Err> {
224        use CreateFinancialConnectionsSessionFiltersAccountSubcategories::*;
225        match s {
226            "checking" => Ok(Checking),
227            "credit_card" => Ok(CreditCard),
228            "line_of_credit" => Ok(LineOfCredit),
229            "mortgage" => Ok(Mortgage),
230            "savings" => Ok(Savings),
231            v => {
232                tracing::warn!(
233                    "Unknown value '{}' for enum '{}'",
234                    v,
235                    "CreateFinancialConnectionsSessionFiltersAccountSubcategories"
236                );
237                Ok(Unknown(v.to_owned()))
238            }
239        }
240    }
241}
242impl std::fmt::Display for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
243    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
244        f.write_str(self.as_str())
245    }
246}
247
248impl std::fmt::Debug for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
249    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250        f.write_str(self.as_str())
251    }
252}
253impl serde::Serialize for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
254    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
255    where
256        S: serde::Serializer,
257    {
258        serializer.serialize_str(self.as_str())
259    }
260}
261#[cfg(feature = "deserialize")]
262impl<'de> serde::Deserialize<'de> for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
263    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
264        use std::str::FromStr;
265        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
266        Ok(Self::from_str(&s).expect("infallible"))
267    }
268}
269/// To launch the Financial Connections authorization flow, create a `Session`.
270/// The session’s `client_secret` can be used to launch the flow using Stripe.js.
271#[derive(Clone, Debug, serde::Serialize)]
272pub struct CreateFinancialConnectionsSession {
273    inner: CreateFinancialConnectionsSessionBuilder,
274}
275impl CreateFinancialConnectionsSession {
276    /// Construct a new `CreateFinancialConnectionsSession`.
277    pub fn new(
278        account_holder: impl Into<CreateFinancialConnectionsSessionAccountHolder>,
279        permissions: impl Into<Vec<stripe_misc::FinancialConnectionsSessionPermissions>>,
280    ) -> Self {
281        Self {
282            inner: CreateFinancialConnectionsSessionBuilder::new(
283                account_holder.into(),
284                permissions.into(),
285            ),
286        }
287    }
288    /// Specifies which fields in the response should be expanded.
289    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
290        self.inner.expand = Some(expand.into());
291        self
292    }
293    /// Filters to restrict the kinds of accounts to collect.
294    pub fn filters(mut self, filters: impl Into<CreateFinancialConnectionsSessionFilters>) -> Self {
295        self.inner.filters = Some(filters.into());
296        self
297    }
298    /// List of data features that you would like to retrieve upon account creation.
299    pub fn prefetch(
300        mut self,
301        prefetch: impl Into<Vec<stripe_misc::FinancialConnectionsSessionPrefetch>>,
302    ) -> Self {
303        self.inner.prefetch = Some(prefetch.into());
304        self
305    }
306    /// For webview integrations only.
307    /// Upon completing OAuth login in the native browser, the user will be redirected to this URL to return to your app.
308    pub fn return_url(mut self, return_url: impl Into<String>) -> Self {
309        self.inner.return_url = Some(return_url.into());
310        self
311    }
312}
313impl CreateFinancialConnectionsSession {
314    /// Send the request and return the deserialized response.
315    pub async fn send<C: StripeClient>(
316        &self,
317        client: &C,
318    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
319        self.customize().send(client).await
320    }
321
322    /// Send the request and return the deserialized response, blocking until completion.
323    pub fn send_blocking<C: StripeBlockingClient>(
324        &self,
325        client: &C,
326    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
327        self.customize().send_blocking(client)
328    }
329}
330
331impl StripeRequest for CreateFinancialConnectionsSession {
332    type Output = stripe_misc::FinancialConnectionsSession;
333
334    fn build(&self) -> RequestBuilder {
335        RequestBuilder::new(StripeMethod::Post, "/financial_connections/sessions").form(&self.inner)
336    }
337}