stripe_shared/
account.rs

1/// This is an object representing a Stripe account. You can retrieve it to see
2/// properties on the account like its current requirements or if the account is
3/// enabled to make live charges or receive payouts.
4///
5/// For accounts where [controller.requirement_collection](/api/accounts/object#account_object-controller-requirement_collection).
6/// is `application`, which includes Custom accounts, the properties below are always
7/// returned.
8///
9/// For accounts where [controller.requirement_collection](/api/accounts/object#account_object-controller-requirement_collection).
10/// is `stripe`, which includes Standard and Express accounts, some properties are only returned
11/// until you create an [Account Link](/api/account_links) or [Account Session](/api/account_sessions)
12/// to start Connect Onboarding. Learn about the [differences between accounts](/connect/accounts).
13///
14/// For more details see <<https://stripe.com/docs/api/accounts/object>>.
15#[derive(Clone, Debug)]
16#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
17pub struct Account {
18    /// Business information about the account.
19    pub business_profile: Option<stripe_shared::AccountBusinessProfile>,
20    /// The business type.
21    pub business_type: Option<stripe_shared::AccountBusinessType>,
22    pub capabilities: Option<stripe_shared::AccountCapabilities>,
23    /// Whether the account can process charges.
24    pub charges_enabled: Option<bool>,
25    pub company: Option<stripe_shared::LegalEntityCompany>,
26    pub controller: Option<stripe_shared::AccountUnificationAccountController>,
27    /// The account's country.
28    pub country: Option<String>,
29    /// Time at which the account was connected. Measured in seconds since the Unix epoch.
30    pub created: Option<stripe_types::Timestamp>,
31    /// Three-letter ISO currency code representing the default currency for the account.
32    /// This must be a currency that [Stripe supports in the account's country](https://stripe.com/docs/payouts).
33    pub default_currency: Option<stripe_types::Currency>,
34    /// Whether account details have been submitted.
35    /// Accounts with Stripe Dashboard access, which includes Standard accounts, cannot receive payouts before this is true.
36    /// Accounts where this is false should be directed to [an onboarding flow](/connect/onboarding) to finish submitting account details.
37    pub details_submitted: Option<bool>,
38    /// An email address associated with the account.
39    /// It's not used for authentication and Stripe doesn't market to this field without explicit approval from the platform.
40    pub email: Option<String>,
41    /// External accounts (bank accounts and debit cards) currently attached to this account.
42    /// External accounts are only returned for requests where `controller[is_controller]` is true.
43    pub external_accounts: Option<stripe_types::List<stripe_shared::ExternalAccount>>,
44    pub future_requirements: Option<stripe_shared::AccountFutureRequirements>,
45    /// The groups associated with the account.
46    pub groups: Option<stripe_shared::AccountGroupMembership>,
47    /// Unique identifier for the object.
48    pub id: stripe_shared::AccountId,
49    pub individual: Option<stripe_shared::Person>,
50    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
51    /// This can be useful for storing additional information about the object in a structured format.
52    pub metadata: Option<std::collections::HashMap<String, String>>,
53    /// Whether the funds in this account can be paid out.
54    pub payouts_enabled: Option<bool>,
55    pub requirements: Option<stripe_shared::AccountRequirements>,
56    /// Options for customizing how the account functions within Stripe.
57    pub settings: Option<stripe_shared::AccountSettings>,
58    pub tos_acceptance: Option<stripe_shared::AccountTosAcceptance>,
59    /// The Stripe account type. Can be `standard`, `express`, `custom`, or `none`.
60    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
61    pub type_: Option<AccountType>,
62}
63#[doc(hidden)]
64pub struct AccountBuilder {
65    business_profile: Option<Option<stripe_shared::AccountBusinessProfile>>,
66    business_type: Option<Option<stripe_shared::AccountBusinessType>>,
67    capabilities: Option<Option<stripe_shared::AccountCapabilities>>,
68    charges_enabled: Option<Option<bool>>,
69    company: Option<Option<stripe_shared::LegalEntityCompany>>,
70    controller: Option<Option<stripe_shared::AccountUnificationAccountController>>,
71    country: Option<Option<String>>,
72    created: Option<Option<stripe_types::Timestamp>>,
73    default_currency: Option<Option<stripe_types::Currency>>,
74    details_submitted: Option<Option<bool>>,
75    email: Option<Option<String>>,
76    external_accounts: Option<Option<stripe_types::List<stripe_shared::ExternalAccount>>>,
77    future_requirements: Option<Option<stripe_shared::AccountFutureRequirements>>,
78    groups: Option<Option<stripe_shared::AccountGroupMembership>>,
79    id: Option<stripe_shared::AccountId>,
80    individual: Option<Option<stripe_shared::Person>>,
81    metadata: Option<Option<std::collections::HashMap<String, String>>>,
82    payouts_enabled: Option<Option<bool>>,
83    requirements: Option<Option<stripe_shared::AccountRequirements>>,
84    settings: Option<Option<stripe_shared::AccountSettings>>,
85    tos_acceptance: Option<Option<stripe_shared::AccountTosAcceptance>>,
86    type_: Option<Option<AccountType>>,
87}
88
89#[allow(
90    unused_variables,
91    irrefutable_let_patterns,
92    clippy::let_unit_value,
93    clippy::match_single_binding,
94    clippy::single_match
95)]
96const _: () = {
97    use miniserde::de::{Map, Visitor};
98    use miniserde::json::Value;
99    use miniserde::{Deserialize, Result, make_place};
100    use stripe_types::miniserde_helpers::FromValueOpt;
101    use stripe_types::{MapBuilder, ObjectDeser};
102
103    make_place!(Place);
104
105    impl Deserialize for Account {
106        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
107            Place::new(out)
108        }
109    }
110
111    struct Builder<'a> {
112        out: &'a mut Option<Account>,
113        builder: AccountBuilder,
114    }
115
116    impl Visitor for Place<Account> {
117        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
118            Ok(Box::new(Builder { out: &mut self.out, builder: AccountBuilder::deser_default() }))
119        }
120    }
121
122    impl MapBuilder for AccountBuilder {
123        type Out = Account;
124        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
125            Ok(match k {
126                "business_profile" => Deserialize::begin(&mut self.business_profile),
127                "business_type" => Deserialize::begin(&mut self.business_type),
128                "capabilities" => Deserialize::begin(&mut self.capabilities),
129                "charges_enabled" => Deserialize::begin(&mut self.charges_enabled),
130                "company" => Deserialize::begin(&mut self.company),
131                "controller" => Deserialize::begin(&mut self.controller),
132                "country" => Deserialize::begin(&mut self.country),
133                "created" => Deserialize::begin(&mut self.created),
134                "default_currency" => Deserialize::begin(&mut self.default_currency),
135                "details_submitted" => Deserialize::begin(&mut self.details_submitted),
136                "email" => Deserialize::begin(&mut self.email),
137                "external_accounts" => Deserialize::begin(&mut self.external_accounts),
138                "future_requirements" => Deserialize::begin(&mut self.future_requirements),
139                "groups" => Deserialize::begin(&mut self.groups),
140                "id" => Deserialize::begin(&mut self.id),
141                "individual" => Deserialize::begin(&mut self.individual),
142                "metadata" => Deserialize::begin(&mut self.metadata),
143                "payouts_enabled" => Deserialize::begin(&mut self.payouts_enabled),
144                "requirements" => Deserialize::begin(&mut self.requirements),
145                "settings" => Deserialize::begin(&mut self.settings),
146                "tos_acceptance" => Deserialize::begin(&mut self.tos_acceptance),
147                "type" => Deserialize::begin(&mut self.type_),
148                _ => <dyn Visitor>::ignore(),
149            })
150        }
151
152        fn deser_default() -> Self {
153            Self {
154                business_profile: Deserialize::default(),
155                business_type: Deserialize::default(),
156                capabilities: Deserialize::default(),
157                charges_enabled: Deserialize::default(),
158                company: Deserialize::default(),
159                controller: Deserialize::default(),
160                country: Deserialize::default(),
161                created: Deserialize::default(),
162                default_currency: Deserialize::default(),
163                details_submitted: Deserialize::default(),
164                email: Deserialize::default(),
165                external_accounts: Deserialize::default(),
166                future_requirements: Deserialize::default(),
167                groups: Deserialize::default(),
168                id: Deserialize::default(),
169                individual: Deserialize::default(),
170                metadata: Deserialize::default(),
171                payouts_enabled: Deserialize::default(),
172                requirements: Deserialize::default(),
173                settings: Deserialize::default(),
174                tos_acceptance: Deserialize::default(),
175                type_: Deserialize::default(),
176            }
177        }
178
179        fn take_out(&mut self) -> Option<Self::Out> {
180            let (
181                Some(business_profile),
182                Some(business_type),
183                Some(capabilities),
184                Some(charges_enabled),
185                Some(company),
186                Some(controller),
187                Some(country),
188                Some(created),
189                Some(default_currency),
190                Some(details_submitted),
191                Some(email),
192                Some(external_accounts),
193                Some(future_requirements),
194                Some(groups),
195                Some(id),
196                Some(individual),
197                Some(metadata),
198                Some(payouts_enabled),
199                Some(requirements),
200                Some(settings),
201                Some(tos_acceptance),
202                Some(type_),
203            ) = (
204                self.business_profile.take(),
205                self.business_type,
206                self.capabilities,
207                self.charges_enabled,
208                self.company.take(),
209                self.controller,
210                self.country.take(),
211                self.created,
212                self.default_currency.take(),
213                self.details_submitted,
214                self.email.take(),
215                self.external_accounts.take(),
216                self.future_requirements.take(),
217                self.groups.take(),
218                self.id.take(),
219                self.individual.take(),
220                self.metadata.take(),
221                self.payouts_enabled,
222                self.requirements.take(),
223                self.settings.take(),
224                self.tos_acceptance.take(),
225                self.type_,
226            )
227            else {
228                return None;
229            };
230            Some(Self::Out {
231                business_profile,
232                business_type,
233                capabilities,
234                charges_enabled,
235                company,
236                controller,
237                country,
238                created,
239                default_currency,
240                details_submitted,
241                email,
242                external_accounts,
243                future_requirements,
244                groups,
245                id,
246                individual,
247                metadata,
248                payouts_enabled,
249                requirements,
250                settings,
251                tos_acceptance,
252                type_,
253            })
254        }
255    }
256
257    impl Map for Builder<'_> {
258        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
259            self.builder.key(k)
260        }
261
262        fn finish(&mut self) -> Result<()> {
263            *self.out = self.builder.take_out();
264            Ok(())
265        }
266    }
267
268    impl ObjectDeser for Account {
269        type Builder = AccountBuilder;
270    }
271
272    impl FromValueOpt for Account {
273        fn from_value(v: Value) -> Option<Self> {
274            let Value::Object(obj) = v else {
275                return None;
276            };
277            let mut b = AccountBuilder::deser_default();
278            for (k, v) in obj {
279                match k.as_str() {
280                    "business_profile" => b.business_profile = FromValueOpt::from_value(v),
281                    "business_type" => b.business_type = FromValueOpt::from_value(v),
282                    "capabilities" => b.capabilities = FromValueOpt::from_value(v),
283                    "charges_enabled" => b.charges_enabled = FromValueOpt::from_value(v),
284                    "company" => b.company = FromValueOpt::from_value(v),
285                    "controller" => b.controller = FromValueOpt::from_value(v),
286                    "country" => b.country = FromValueOpt::from_value(v),
287                    "created" => b.created = FromValueOpt::from_value(v),
288                    "default_currency" => b.default_currency = FromValueOpt::from_value(v),
289                    "details_submitted" => b.details_submitted = FromValueOpt::from_value(v),
290                    "email" => b.email = FromValueOpt::from_value(v),
291                    "external_accounts" => b.external_accounts = FromValueOpt::from_value(v),
292                    "future_requirements" => b.future_requirements = FromValueOpt::from_value(v),
293                    "groups" => b.groups = FromValueOpt::from_value(v),
294                    "id" => b.id = FromValueOpt::from_value(v),
295                    "individual" => b.individual = FromValueOpt::from_value(v),
296                    "metadata" => b.metadata = FromValueOpt::from_value(v),
297                    "payouts_enabled" => b.payouts_enabled = FromValueOpt::from_value(v),
298                    "requirements" => b.requirements = FromValueOpt::from_value(v),
299                    "settings" => b.settings = FromValueOpt::from_value(v),
300                    "tos_acceptance" => b.tos_acceptance = FromValueOpt::from_value(v),
301                    "type" => b.type_ = FromValueOpt::from_value(v),
302                    _ => {}
303                }
304            }
305            b.take_out()
306        }
307    }
308};
309#[cfg(feature = "serialize")]
310impl serde::Serialize for Account {
311    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
312        use serde::ser::SerializeStruct;
313        let mut s = s.serialize_struct("Account", 23)?;
314        s.serialize_field("business_profile", &self.business_profile)?;
315        s.serialize_field("business_type", &self.business_type)?;
316        s.serialize_field("capabilities", &self.capabilities)?;
317        s.serialize_field("charges_enabled", &self.charges_enabled)?;
318        s.serialize_field("company", &self.company)?;
319        s.serialize_field("controller", &self.controller)?;
320        s.serialize_field("country", &self.country)?;
321        s.serialize_field("created", &self.created)?;
322        s.serialize_field("default_currency", &self.default_currency)?;
323        s.serialize_field("details_submitted", &self.details_submitted)?;
324        s.serialize_field("email", &self.email)?;
325        s.serialize_field("external_accounts", &self.external_accounts)?;
326        s.serialize_field("future_requirements", &self.future_requirements)?;
327        s.serialize_field("groups", &self.groups)?;
328        s.serialize_field("id", &self.id)?;
329        s.serialize_field("individual", &self.individual)?;
330        s.serialize_field("metadata", &self.metadata)?;
331        s.serialize_field("payouts_enabled", &self.payouts_enabled)?;
332        s.serialize_field("requirements", &self.requirements)?;
333        s.serialize_field("settings", &self.settings)?;
334        s.serialize_field("tos_acceptance", &self.tos_acceptance)?;
335        s.serialize_field("type", &self.type_)?;
336
337        s.serialize_field("object", "account")?;
338        s.end()
339    }
340}
341/// The Stripe account type. Can be `standard`, `express`, `custom`, or `none`.
342#[derive(Copy, Clone, Eq, PartialEq)]
343pub enum AccountType {
344    Custom,
345    Express,
346    None,
347    Standard,
348}
349impl AccountType {
350    pub fn as_str(self) -> &'static str {
351        use AccountType::*;
352        match self {
353            Custom => "custom",
354            Express => "express",
355            None => "none",
356            Standard => "standard",
357        }
358    }
359}
360
361impl std::str::FromStr for AccountType {
362    type Err = stripe_types::StripeParseError;
363    fn from_str(s: &str) -> Result<Self, Self::Err> {
364        use AccountType::*;
365        match s {
366            "custom" => Ok(Custom),
367            "express" => Ok(Express),
368            "none" => Ok(None),
369            "standard" => Ok(Standard),
370            _ => Err(stripe_types::StripeParseError),
371        }
372    }
373}
374impl std::fmt::Display for AccountType {
375    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
376        f.write_str(self.as_str())
377    }
378}
379
380impl std::fmt::Debug for AccountType {
381    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
382        f.write_str(self.as_str())
383    }
384}
385#[cfg(feature = "serialize")]
386impl serde::Serialize for AccountType {
387    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
388    where
389        S: serde::Serializer,
390    {
391        serializer.serialize_str(self.as_str())
392    }
393}
394impl miniserde::Deserialize for AccountType {
395    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
396        crate::Place::new(out)
397    }
398}
399
400impl miniserde::de::Visitor for crate::Place<AccountType> {
401    fn string(&mut self, s: &str) -> miniserde::Result<()> {
402        use std::str::FromStr;
403        self.out = Some(AccountType::from_str(s).map_err(|_| miniserde::Error)?);
404        Ok(())
405    }
406}
407
408stripe_types::impl_from_val_with_from_str!(AccountType);
409#[cfg(feature = "deserialize")]
410impl<'de> serde::Deserialize<'de> for AccountType {
411    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
412        use std::str::FromStr;
413        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
414        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for AccountType"))
415    }
416}
417impl stripe_types::Object for Account {
418    type Id = stripe_shared::AccountId;
419    fn id(&self) -> &Self::Id {
420        &self.id
421    }
422
423    fn into_id(self) -> Self::Id {
424        self.id
425    }
426}
427stripe_types::def_id!(AccountId);
428#[derive(Copy, Clone, Eq, PartialEq)]
429pub enum AccountBusinessType {
430    Company,
431    GovernmentEntity,
432    Individual,
433    NonProfit,
434}
435impl AccountBusinessType {
436    pub fn as_str(self) -> &'static str {
437        use AccountBusinessType::*;
438        match self {
439            Company => "company",
440            GovernmentEntity => "government_entity",
441            Individual => "individual",
442            NonProfit => "non_profit",
443        }
444    }
445}
446
447impl std::str::FromStr for AccountBusinessType {
448    type Err = stripe_types::StripeParseError;
449    fn from_str(s: &str) -> Result<Self, Self::Err> {
450        use AccountBusinessType::*;
451        match s {
452            "company" => Ok(Company),
453            "government_entity" => Ok(GovernmentEntity),
454            "individual" => Ok(Individual),
455            "non_profit" => Ok(NonProfit),
456            _ => Err(stripe_types::StripeParseError),
457        }
458    }
459}
460impl std::fmt::Display for AccountBusinessType {
461    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
462        f.write_str(self.as_str())
463    }
464}
465
466impl std::fmt::Debug for AccountBusinessType {
467    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
468        f.write_str(self.as_str())
469    }
470}
471impl serde::Serialize for AccountBusinessType {
472    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
473    where
474        S: serde::Serializer,
475    {
476        serializer.serialize_str(self.as_str())
477    }
478}
479impl miniserde::Deserialize for AccountBusinessType {
480    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
481        crate::Place::new(out)
482    }
483}
484
485impl miniserde::de::Visitor for crate::Place<AccountBusinessType> {
486    fn string(&mut self, s: &str) -> miniserde::Result<()> {
487        use std::str::FromStr;
488        self.out = Some(AccountBusinessType::from_str(s).map_err(|_| miniserde::Error)?);
489        Ok(())
490    }
491}
492
493stripe_types::impl_from_val_with_from_str!(AccountBusinessType);
494#[cfg(feature = "deserialize")]
495impl<'de> serde::Deserialize<'de> for AccountBusinessType {
496    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
497        use std::str::FromStr;
498        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
499        Self::from_str(&s)
500            .map_err(|_| serde::de::Error::custom("Unknown value for AccountBusinessType"))
501    }
502}