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(Copy, Clone, Eq, PartialEq)]
109pub enum CreateFinancialConnectionsSessionAccountHolderType {
110    Account,
111    Customer,
112}
113impl CreateFinancialConnectionsSessionAccountHolderType {
114    pub fn as_str(self) -> &'static str {
115        use CreateFinancialConnectionsSessionAccountHolderType::*;
116        match self {
117            Account => "account",
118            Customer => "customer",
119        }
120    }
121}
122
123impl std::str::FromStr for CreateFinancialConnectionsSessionAccountHolderType {
124    type Err = stripe_types::StripeParseError;
125    fn from_str(s: &str) -> Result<Self, Self::Err> {
126        use CreateFinancialConnectionsSessionAccountHolderType::*;
127        match s {
128            "account" => Ok(Account),
129            "customer" => Ok(Customer),
130            _ => Err(stripe_types::StripeParseError),
131        }
132    }
133}
134impl std::fmt::Display for CreateFinancialConnectionsSessionAccountHolderType {
135    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
136        f.write_str(self.as_str())
137    }
138}
139
140impl std::fmt::Debug for CreateFinancialConnectionsSessionAccountHolderType {
141    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
142        f.write_str(self.as_str())
143    }
144}
145impl serde::Serialize for CreateFinancialConnectionsSessionAccountHolderType {
146    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
147    where
148        S: serde::Serializer,
149    {
150        serializer.serialize_str(self.as_str())
151    }
152}
153#[cfg(feature = "deserialize")]
154impl<'de> serde::Deserialize<'de> for CreateFinancialConnectionsSessionAccountHolderType {
155    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
156        use std::str::FromStr;
157        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
158        Self::from_str(&s).map_err(|_| {
159            serde::de::Error::custom(
160                "Unknown value for CreateFinancialConnectionsSessionAccountHolderType",
161            )
162        })
163    }
164}
165/// Filters to restrict the kinds of accounts to collect.
166#[derive(Clone, Debug, serde::Serialize)]
167pub struct CreateFinancialConnectionsSessionFilters {
168    /// Restricts the Session to subcategories of accounts that can be linked.
169    /// Valid subcategories are: `checking`, `savings`, `mortgage`, `line_of_credit`, `credit_card`.
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub account_subcategories:
172        Option<Vec<CreateFinancialConnectionsSessionFiltersAccountSubcategories>>,
173    /// List of countries from which to collect accounts.
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub countries: Option<Vec<String>>,
176}
177impl CreateFinancialConnectionsSessionFilters {
178    pub fn new() -> Self {
179        Self { account_subcategories: None, countries: None }
180    }
181}
182impl Default for CreateFinancialConnectionsSessionFilters {
183    fn default() -> Self {
184        Self::new()
185    }
186}
187/// Restricts the Session to subcategories of accounts that can be linked.
188/// Valid subcategories are: `checking`, `savings`, `mortgage`, `line_of_credit`, `credit_card`.
189#[derive(Copy, Clone, Eq, PartialEq)]
190pub enum CreateFinancialConnectionsSessionFiltersAccountSubcategories {
191    Checking,
192    CreditCard,
193    LineOfCredit,
194    Mortgage,
195    Savings,
196}
197impl CreateFinancialConnectionsSessionFiltersAccountSubcategories {
198    pub fn as_str(self) -> &'static str {
199        use CreateFinancialConnectionsSessionFiltersAccountSubcategories::*;
200        match self {
201            Checking => "checking",
202            CreditCard => "credit_card",
203            LineOfCredit => "line_of_credit",
204            Mortgage => "mortgage",
205            Savings => "savings",
206        }
207    }
208}
209
210impl std::str::FromStr for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
211    type Err = stripe_types::StripeParseError;
212    fn from_str(s: &str) -> Result<Self, Self::Err> {
213        use CreateFinancialConnectionsSessionFiltersAccountSubcategories::*;
214        match s {
215            "checking" => Ok(Checking),
216            "credit_card" => Ok(CreditCard),
217            "line_of_credit" => Ok(LineOfCredit),
218            "mortgage" => Ok(Mortgage),
219            "savings" => Ok(Savings),
220            _ => Err(stripe_types::StripeParseError),
221        }
222    }
223}
224impl std::fmt::Display for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
225    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
226        f.write_str(self.as_str())
227    }
228}
229
230impl std::fmt::Debug for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
231    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232        f.write_str(self.as_str())
233    }
234}
235impl serde::Serialize for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
236    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
237    where
238        S: serde::Serializer,
239    {
240        serializer.serialize_str(self.as_str())
241    }
242}
243#[cfg(feature = "deserialize")]
244impl<'de> serde::Deserialize<'de> for CreateFinancialConnectionsSessionFiltersAccountSubcategories {
245    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
246        use std::str::FromStr;
247        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
248        Self::from_str(&s).map_err(|_| {
249            serde::de::Error::custom(
250                "Unknown value for CreateFinancialConnectionsSessionFiltersAccountSubcategories",
251            )
252        })
253    }
254}
255/// To launch the Financial Connections authorization flow, create a `Session`.
256/// The session’s `client_secret` can be used to launch the flow using Stripe.js.
257#[derive(Clone, Debug, serde::Serialize)]
258pub struct CreateFinancialConnectionsSession {
259    inner: CreateFinancialConnectionsSessionBuilder,
260}
261impl CreateFinancialConnectionsSession {
262    /// Construct a new `CreateFinancialConnectionsSession`.
263    pub fn new(
264        account_holder: impl Into<CreateFinancialConnectionsSessionAccountHolder>,
265        permissions: impl Into<Vec<stripe_misc::FinancialConnectionsSessionPermissions>>,
266    ) -> Self {
267        Self {
268            inner: CreateFinancialConnectionsSessionBuilder::new(
269                account_holder.into(),
270                permissions.into(),
271            ),
272        }
273    }
274    /// Specifies which fields in the response should be expanded.
275    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
276        self.inner.expand = Some(expand.into());
277        self
278    }
279    /// Filters to restrict the kinds of accounts to collect.
280    pub fn filters(mut self, filters: impl Into<CreateFinancialConnectionsSessionFilters>) -> Self {
281        self.inner.filters = Some(filters.into());
282        self
283    }
284    /// List of data features that you would like to retrieve upon account creation.
285    pub fn prefetch(
286        mut self,
287        prefetch: impl Into<Vec<stripe_misc::FinancialConnectionsSessionPrefetch>>,
288    ) -> Self {
289        self.inner.prefetch = Some(prefetch.into());
290        self
291    }
292    /// For webview integrations only.
293    /// Upon completing OAuth login in the native browser, the user will be redirected to this URL to return to your app.
294    pub fn return_url(mut self, return_url: impl Into<String>) -> Self {
295        self.inner.return_url = Some(return_url.into());
296        self
297    }
298}
299impl CreateFinancialConnectionsSession {
300    /// Send the request and return the deserialized response.
301    pub async fn send<C: StripeClient>(
302        &self,
303        client: &C,
304    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
305        self.customize().send(client).await
306    }
307
308    /// Send the request and return the deserialized response, blocking until completion.
309    pub fn send_blocking<C: StripeBlockingClient>(
310        &self,
311        client: &C,
312    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
313        self.customize().send_blocking(client)
314    }
315}
316
317impl StripeRequest for CreateFinancialConnectionsSession {
318    type Output = stripe_misc::FinancialConnectionsSession;
319
320    fn build(&self) -> RequestBuilder {
321        RequestBuilder::new(StripeMethod::Post, "/financial_connections/sessions").form(&self.inner)
322    }
323}