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.take(),
206                self.capabilities.take(),
207                self.charges_enabled,
208                self.company.take(),
209                self.controller.take(),
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_.take(),
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(Clone, Eq, PartialEq)]
343#[non_exhaustive]
344pub enum AccountType {
345    Custom,
346    Express,
347    None,
348    Standard,
349    /// An unrecognized value from Stripe. Should not be used as a request parameter.
350    Unknown(String),
351}
352impl AccountType {
353    pub fn as_str(&self) -> &str {
354        use AccountType::*;
355        match self {
356            Custom => "custom",
357            Express => "express",
358            None => "none",
359            Standard => "standard",
360            Unknown(v) => v,
361        }
362    }
363}
364
365impl std::str::FromStr for AccountType {
366    type Err = std::convert::Infallible;
367    fn from_str(s: &str) -> Result<Self, Self::Err> {
368        use AccountType::*;
369        match s {
370            "custom" => Ok(Custom),
371            "express" => Ok(Express),
372            "none" => Ok(None),
373            "standard" => Ok(Standard),
374            v => {
375                tracing::warn!("Unknown value '{}' for enum '{}'", v, "AccountType");
376                Ok(Unknown(v.to_owned()))
377            }
378        }
379    }
380}
381impl std::fmt::Display for AccountType {
382    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
383        f.write_str(self.as_str())
384    }
385}
386
387impl std::fmt::Debug for AccountType {
388    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
389        f.write_str(self.as_str())
390    }
391}
392#[cfg(feature = "serialize")]
393impl serde::Serialize for AccountType {
394    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
395    where
396        S: serde::Serializer,
397    {
398        serializer.serialize_str(self.as_str())
399    }
400}
401impl miniserde::Deserialize for AccountType {
402    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
403        crate::Place::new(out)
404    }
405}
406
407impl miniserde::de::Visitor for crate::Place<AccountType> {
408    fn string(&mut self, s: &str) -> miniserde::Result<()> {
409        use std::str::FromStr;
410        self.out = Some(AccountType::from_str(s).expect("infallible"));
411        Ok(())
412    }
413}
414
415stripe_types::impl_from_val_with_from_str!(AccountType);
416#[cfg(feature = "deserialize")]
417impl<'de> serde::Deserialize<'de> for AccountType {
418    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
419        use std::str::FromStr;
420        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
421        Ok(Self::from_str(&s).expect("infallible"))
422    }
423}
424impl stripe_types::Object for Account {
425    type Id = stripe_shared::AccountId;
426    fn id(&self) -> &Self::Id {
427        &self.id
428    }
429
430    fn into_id(self) -> Self::Id {
431        self.id
432    }
433}
434stripe_types::def_id!(AccountId);
435#[derive(Clone, Eq, PartialEq)]
436#[non_exhaustive]
437pub enum AccountBusinessType {
438    Company,
439    GovernmentEntity,
440    Individual,
441    NonProfit,
442    /// An unrecognized value from Stripe. Should not be used as a request parameter.
443    Unknown(String),
444}
445impl AccountBusinessType {
446    pub fn as_str(&self) -> &str {
447        use AccountBusinessType::*;
448        match self {
449            Company => "company",
450            GovernmentEntity => "government_entity",
451            Individual => "individual",
452            NonProfit => "non_profit",
453            Unknown(v) => v,
454        }
455    }
456}
457
458impl std::str::FromStr for AccountBusinessType {
459    type Err = std::convert::Infallible;
460    fn from_str(s: &str) -> Result<Self, Self::Err> {
461        use AccountBusinessType::*;
462        match s {
463            "company" => Ok(Company),
464            "government_entity" => Ok(GovernmentEntity),
465            "individual" => Ok(Individual),
466            "non_profit" => Ok(NonProfit),
467            v => {
468                tracing::warn!("Unknown value '{}' for enum '{}'", v, "AccountBusinessType");
469                Ok(Unknown(v.to_owned()))
470            }
471        }
472    }
473}
474impl std::fmt::Display for AccountBusinessType {
475    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
476        f.write_str(self.as_str())
477    }
478}
479
480impl std::fmt::Debug for AccountBusinessType {
481    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
482        f.write_str(self.as_str())
483    }
484}
485impl serde::Serialize for AccountBusinessType {
486    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
487    where
488        S: serde::Serializer,
489    {
490        serializer.serialize_str(self.as_str())
491    }
492}
493impl miniserde::Deserialize for AccountBusinessType {
494    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
495        crate::Place::new(out)
496    }
497}
498
499impl miniserde::de::Visitor for crate::Place<AccountBusinessType> {
500    fn string(&mut self, s: &str) -> miniserde::Result<()> {
501        use std::str::FromStr;
502        self.out = Some(AccountBusinessType::from_str(s).expect("infallible"));
503        Ok(())
504    }
505}
506
507stripe_types::impl_from_val_with_from_str!(AccountBusinessType);
508#[cfg(feature = "deserialize")]
509impl<'de> serde::Deserialize<'de> for AccountBusinessType {
510    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
511        use std::str::FromStr;
512        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
513        Ok(Self::from_str(&s).expect("infallible"))
514    }
515}