Skip to main content

stripe_shared/
account.rs

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