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::{make_place, Deserialize, Result};
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
149                _ => <dyn Visitor>::ignore(),
150            })
151        }
152
153        fn deser_default() -> Self {
154            Self {
155                business_profile: Deserialize::default(),
156                business_type: Deserialize::default(),
157                capabilities: Deserialize::default(),
158                charges_enabled: Deserialize::default(),
159                company: Deserialize::default(),
160                controller: Deserialize::default(),
161                country: Deserialize::default(),
162                created: Deserialize::default(),
163                default_currency: Deserialize::default(),
164                details_submitted: Deserialize::default(),
165                email: Deserialize::default(),
166                external_accounts: Deserialize::default(),
167                future_requirements: Deserialize::default(),
168                groups: Deserialize::default(),
169                id: Deserialize::default(),
170                individual: Deserialize::default(),
171                metadata: Deserialize::default(),
172                payouts_enabled: Deserialize::default(),
173                requirements: Deserialize::default(),
174                settings: Deserialize::default(),
175                tos_acceptance: Deserialize::default(),
176                type_: Deserialize::default(),
177            }
178        }
179
180        fn take_out(&mut self) -> Option<Self::Out> {
181            let (
182                Some(business_profile),
183                Some(business_type),
184                Some(capabilities),
185                Some(charges_enabled),
186                Some(company),
187                Some(controller),
188                Some(country),
189                Some(created),
190                Some(default_currency),
191                Some(details_submitted),
192                Some(email),
193                Some(external_accounts),
194                Some(future_requirements),
195                Some(groups),
196                Some(id),
197                Some(individual),
198                Some(metadata),
199                Some(payouts_enabled),
200                Some(requirements),
201                Some(settings),
202                Some(tos_acceptance),
203                Some(type_),
204            ) = (
205                self.business_profile.take(),
206                self.business_type,
207                self.capabilities,
208                self.charges_enabled,
209                self.company.take(),
210                self.controller,
211                self.country.take(),
212                self.created,
213                self.default_currency,
214                self.details_submitted,
215                self.email.take(),
216                self.external_accounts.take(),
217                self.future_requirements.take(),
218                self.groups.take(),
219                self.id.take(),
220                self.individual.take(),
221                self.metadata.take(),
222                self.payouts_enabled,
223                self.requirements.take(),
224                self.settings.take(),
225                self.tos_acceptance.take(),
226                self.type_,
227            )
228            else {
229                return None;
230            };
231            Some(Self::Out {
232                business_profile,
233                business_type,
234                capabilities,
235                charges_enabled,
236                company,
237                controller,
238                country,
239                created,
240                default_currency,
241                details_submitted,
242                email,
243                external_accounts,
244                future_requirements,
245                groups,
246                id,
247                individual,
248                metadata,
249                payouts_enabled,
250                requirements,
251                settings,
252                tos_acceptance,
253                type_,
254            })
255        }
256    }
257
258    impl<'a> Map for Builder<'a> {
259        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
260            self.builder.key(k)
261        }
262
263        fn finish(&mut self) -> Result<()> {
264            *self.out = self.builder.take_out();
265            Ok(())
266        }
267    }
268
269    impl ObjectDeser for Account {
270        type Builder = AccountBuilder;
271    }
272
273    impl FromValueOpt for Account {
274        fn from_value(v: Value) -> Option<Self> {
275            let Value::Object(obj) = v else {
276                return None;
277            };
278            let mut b = AccountBuilder::deser_default();
279            for (k, v) in obj {
280                match k.as_str() {
281                    "business_profile" => b.business_profile = FromValueOpt::from_value(v),
282                    "business_type" => b.business_type = FromValueOpt::from_value(v),
283                    "capabilities" => b.capabilities = FromValueOpt::from_value(v),
284                    "charges_enabled" => b.charges_enabled = FromValueOpt::from_value(v),
285                    "company" => b.company = FromValueOpt::from_value(v),
286                    "controller" => b.controller = FromValueOpt::from_value(v),
287                    "country" => b.country = FromValueOpt::from_value(v),
288                    "created" => b.created = FromValueOpt::from_value(v),
289                    "default_currency" => b.default_currency = FromValueOpt::from_value(v),
290                    "details_submitted" => b.details_submitted = FromValueOpt::from_value(v),
291                    "email" => b.email = FromValueOpt::from_value(v),
292                    "external_accounts" => b.external_accounts = FromValueOpt::from_value(v),
293                    "future_requirements" => b.future_requirements = FromValueOpt::from_value(v),
294                    "groups" => b.groups = FromValueOpt::from_value(v),
295                    "id" => b.id = FromValueOpt::from_value(v),
296                    "individual" => b.individual = FromValueOpt::from_value(v),
297                    "metadata" => b.metadata = FromValueOpt::from_value(v),
298                    "payouts_enabled" => b.payouts_enabled = FromValueOpt::from_value(v),
299                    "requirements" => b.requirements = FromValueOpt::from_value(v),
300                    "settings" => b.settings = FromValueOpt::from_value(v),
301                    "tos_acceptance" => b.tos_acceptance = FromValueOpt::from_value(v),
302                    "type" => b.type_ = FromValueOpt::from_value(v),
303
304                    _ => {}
305                }
306            }
307            b.take_out()
308        }
309    }
310};
311#[cfg(feature = "serialize")]
312impl serde::Serialize for Account {
313    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
314        use serde::ser::SerializeStruct;
315        let mut s = s.serialize_struct("Account", 23)?;
316        s.serialize_field("business_profile", &self.business_profile)?;
317        s.serialize_field("business_type", &self.business_type)?;
318        s.serialize_field("capabilities", &self.capabilities)?;
319        s.serialize_field("charges_enabled", &self.charges_enabled)?;
320        s.serialize_field("company", &self.company)?;
321        s.serialize_field("controller", &self.controller)?;
322        s.serialize_field("country", &self.country)?;
323        s.serialize_field("created", &self.created)?;
324        s.serialize_field("default_currency", &self.default_currency)?;
325        s.serialize_field("details_submitted", &self.details_submitted)?;
326        s.serialize_field("email", &self.email)?;
327        s.serialize_field("external_accounts", &self.external_accounts)?;
328        s.serialize_field("future_requirements", &self.future_requirements)?;
329        s.serialize_field("groups", &self.groups)?;
330        s.serialize_field("id", &self.id)?;
331        s.serialize_field("individual", &self.individual)?;
332        s.serialize_field("metadata", &self.metadata)?;
333        s.serialize_field("payouts_enabled", &self.payouts_enabled)?;
334        s.serialize_field("requirements", &self.requirements)?;
335        s.serialize_field("settings", &self.settings)?;
336        s.serialize_field("tos_acceptance", &self.tos_acceptance)?;
337        s.serialize_field("type", &self.type_)?;
338
339        s.serialize_field("object", "account")?;
340        s.end()
341    }
342}
343/// The Stripe account type. Can be `standard`, `express`, `custom`, or `none`.
344#[derive(Copy, Clone, Eq, PartialEq)]
345pub enum AccountType {
346    Custom,
347    Express,
348    None,
349    Standard,
350}
351impl AccountType {
352    pub fn as_str(self) -> &'static str {
353        use AccountType::*;
354        match self {
355            Custom => "custom",
356            Express => "express",
357            None => "none",
358            Standard => "standard",
359        }
360    }
361}
362
363impl std::str::FromStr for AccountType {
364    type Err = stripe_types::StripeParseError;
365    fn from_str(s: &str) -> Result<Self, Self::Err> {
366        use AccountType::*;
367        match s {
368            "custom" => Ok(Custom),
369            "express" => Ok(Express),
370            "none" => Ok(None),
371            "standard" => Ok(Standard),
372            _ => Err(stripe_types::StripeParseError),
373        }
374    }
375}
376impl std::fmt::Display for AccountType {
377    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
378        f.write_str(self.as_str())
379    }
380}
381
382impl std::fmt::Debug for AccountType {
383    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
384        f.write_str(self.as_str())
385    }
386}
387#[cfg(feature = "serialize")]
388impl serde::Serialize for AccountType {
389    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
390    where
391        S: serde::Serializer,
392    {
393        serializer.serialize_str(self.as_str())
394    }
395}
396impl miniserde::Deserialize for AccountType {
397    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
398        crate::Place::new(out)
399    }
400}
401
402impl miniserde::de::Visitor for crate::Place<AccountType> {
403    fn string(&mut self, s: &str) -> miniserde::Result<()> {
404        use std::str::FromStr;
405        self.out = Some(AccountType::from_str(s).map_err(|_| miniserde::Error)?);
406        Ok(())
407    }
408}
409
410stripe_types::impl_from_val_with_from_str!(AccountType);
411#[cfg(feature = "deserialize")]
412impl<'de> serde::Deserialize<'de> for AccountType {
413    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
414        use std::str::FromStr;
415        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
416        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for AccountType"))
417    }
418}
419impl stripe_types::Object for Account {
420    type Id = stripe_shared::AccountId;
421    fn id(&self) -> &Self::Id {
422        &self.id
423    }
424
425    fn into_id(self) -> Self::Id {
426        self.id
427    }
428}
429stripe_types::def_id!(AccountId);
430#[derive(Copy, Clone, Eq, PartialEq)]
431pub enum AccountBusinessType {
432    Company,
433    GovernmentEntity,
434    Individual,
435    NonProfit,
436}
437impl AccountBusinessType {
438    pub fn as_str(self) -> &'static str {
439        use AccountBusinessType::*;
440        match self {
441            Company => "company",
442            GovernmentEntity => "government_entity",
443            Individual => "individual",
444            NonProfit => "non_profit",
445        }
446    }
447}
448
449impl std::str::FromStr for AccountBusinessType {
450    type Err = stripe_types::StripeParseError;
451    fn from_str(s: &str) -> Result<Self, Self::Err> {
452        use AccountBusinessType::*;
453        match s {
454            "company" => Ok(Company),
455            "government_entity" => Ok(GovernmentEntity),
456            "individual" => Ok(Individual),
457            "non_profit" => Ok(NonProfit),
458            _ => Err(stripe_types::StripeParseError),
459        }
460    }
461}
462impl std::fmt::Display for AccountBusinessType {
463    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
464        f.write_str(self.as_str())
465    }
466}
467
468impl std::fmt::Debug for AccountBusinessType {
469    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
470        f.write_str(self.as_str())
471    }
472}
473impl serde::Serialize for AccountBusinessType {
474    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
475    where
476        S: serde::Serializer,
477    {
478        serializer.serialize_str(self.as_str())
479    }
480}
481impl miniserde::Deserialize for AccountBusinessType {
482    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
483        crate::Place::new(out)
484    }
485}
486
487impl miniserde::de::Visitor for crate::Place<AccountBusinessType> {
488    fn string(&mut self, s: &str) -> miniserde::Result<()> {
489        use std::str::FromStr;
490        self.out = Some(AccountBusinessType::from_str(s).map_err(|_| miniserde::Error)?);
491        Ok(())
492    }
493}
494
495stripe_types::impl_from_val_with_from_str!(AccountBusinessType);
496#[cfg(feature = "deserialize")]
497impl<'de> serde::Deserialize<'de> for AccountBusinessType {
498    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
499        use std::str::FromStr;
500        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
501        Self::from_str(&s)
502            .map_err(|_| serde::de::Error::custom("Unknown value for AccountBusinessType"))
503    }
504}