stripe_shared/
bank_account.rs

1/// These bank accounts are payment methods on `Customer` objects.
2///
3/// On the other hand [External Accounts](/api#external_accounts) are transfer
4/// destinations on `Account` objects for connected accounts.
5/// They can be bank accounts or debit cards as well, and are documented in the links above.
6///
7/// Related guide: [Bank debits and transfers](/payments/bank-debits-transfers)
8#[derive(Clone, Debug)]
9#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
10pub struct BankAccount {
11    /// The account this bank account belongs to.
12    /// Only applicable on Accounts (not customers or recipients) This property is only available when returned as an [External Account](/api/external_account_bank_accounts/object) where [controller.is_controller](/api/accounts/object#account_object-controller-is_controller) is `true`.
13    pub account: Option<stripe_types::Expandable<stripe_shared::Account>>,
14    /// The name of the person or business that owns the bank account.
15    pub account_holder_name: Option<String>,
16    /// The type of entity that holds the account. This can be either `individual` or `company`.
17    pub account_holder_type: Option<String>,
18    /// The bank account type.
19    /// This can only be `checking` or `savings` in most countries.
20    /// In Japan, this can only be `futsu` or `toza`.
21    pub account_type: Option<String>,
22    /// A set of available payout methods for this bank account.
23    /// Only values from this set should be passed as the `method` when creating a payout.
24    pub available_payout_methods: Option<Vec<BankAccountAvailablePayoutMethods>>,
25    /// Name of the bank associated with the routing number (e.g., `WELLS FARGO`).
26    pub bank_name: Option<String>,
27    /// Two-letter ISO code representing the country the bank account is located in.
28    pub country: String,
29    /// Three-letter [ISO code for the currency](https://stripe.com/docs/payouts) paid out to the bank account.
30    pub currency: stripe_types::Currency,
31    /// The ID of the customer that the bank account is associated with.
32    pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
33    /// Whether this bank account is the default external account for its currency.
34    pub default_for_currency: Option<bool>,
35    /// Uniquely identifies this particular bank account.
36    /// You can use this attribute to check whether two bank accounts are the same.
37    pub fingerprint: Option<String>,
38    /// Information about the [upcoming new requirements for the bank account](https://stripe.com/docs/connect/custom-accounts/future-requirements), including what information needs to be collected, and by when.
39    pub future_requirements: Option<stripe_shared::ExternalAccountRequirements>,
40    /// Unique identifier for the object.
41    pub id: stripe_shared::BankAccountId,
42    /// The last four digits of the bank account number.
43    pub last4: String,
44    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
45    /// This can be useful for storing additional information about the object in a structured format.
46    pub metadata: Option<std::collections::HashMap<String, String>>,
47    /// Information about the requirements for the bank account, including what information needs to be collected.
48    pub requirements: Option<stripe_shared::ExternalAccountRequirements>,
49    /// The routing transit number for the bank account.
50    pub routing_number: Option<String>,
51    /// For bank accounts, possible values are `new`, `validated`, `verified`, `verification_failed`, `tokenized_account_number_deactivated` or `errored`.
52    /// A bank account that hasn't had any activity or validation performed is `new`.
53    /// If Stripe can determine that the bank account exists, its status will be `validated`.
54    /// Note that there often isn’t enough information to know (e.g., for smaller credit unions), and the validation is not always run.
55    /// If customer bank account verification has succeeded, the bank account status will be `verified`.
56    /// If the verification failed for any reason, such as microdeposit failure, the status will be `verification_failed`.
57    /// If the status is `tokenized_account_number_deactivated`, the account utilizes a tokenized account number which has been deactivated due to expiration or revocation.
58    /// This account will need to be reverified to continue using it for money movement.
59    /// If a payout sent to this bank account fails, we'll set the status to `errored` and will not continue to send [scheduled payouts](https://stripe.com/docs/payouts#payout-schedule) until the bank details are updated.
60    ///
61    /// For external accounts, possible values are `new`, `errored`, `verification_failed`, and `tokenized_account_number_deactivated`.
62    /// If a payout fails, the status is set to `errored` and scheduled payouts are stopped until account details are updated.
63    /// In the US and India, if we can't [verify the owner of the bank account](https://support.stripe.com/questions/bank-account-ownership-verification), we'll set the status to `verification_failed`.
64    /// Other validations aren't run against external accounts because they're only used for payouts.
65    /// This means the other statuses don't apply.
66    pub status: String,
67}
68#[doc(hidden)]
69pub struct BankAccountBuilder {
70    account: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
71    account_holder_name: Option<Option<String>>,
72    account_holder_type: Option<Option<String>>,
73    account_type: Option<Option<String>>,
74    available_payout_methods: Option<Option<Vec<BankAccountAvailablePayoutMethods>>>,
75    bank_name: Option<Option<String>>,
76    country: Option<String>,
77    currency: Option<stripe_types::Currency>,
78    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
79    default_for_currency: Option<Option<bool>>,
80    fingerprint: Option<Option<String>>,
81    future_requirements: Option<Option<stripe_shared::ExternalAccountRequirements>>,
82    id: Option<stripe_shared::BankAccountId>,
83    last4: Option<String>,
84    metadata: Option<Option<std::collections::HashMap<String, String>>>,
85    requirements: Option<Option<stripe_shared::ExternalAccountRequirements>>,
86    routing_number: Option<Option<String>>,
87    status: Option<String>,
88}
89
90#[allow(
91    unused_variables,
92    irrefutable_let_patterns,
93    clippy::let_unit_value,
94    clippy::match_single_binding,
95    clippy::single_match
96)]
97const _: () = {
98    use miniserde::de::{Map, Visitor};
99    use miniserde::json::Value;
100    use miniserde::{Deserialize, Result, make_place};
101    use stripe_types::miniserde_helpers::FromValueOpt;
102    use stripe_types::{MapBuilder, ObjectDeser};
103
104    make_place!(Place);
105
106    impl Deserialize for BankAccount {
107        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
108            Place::new(out)
109        }
110    }
111
112    struct Builder<'a> {
113        out: &'a mut Option<BankAccount>,
114        builder: BankAccountBuilder,
115    }
116
117    impl Visitor for Place<BankAccount> {
118        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
119            Ok(Box::new(Builder {
120                out: &mut self.out,
121                builder: BankAccountBuilder::deser_default(),
122            }))
123        }
124    }
125
126    impl MapBuilder for BankAccountBuilder {
127        type Out = BankAccount;
128        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
129            Ok(match k {
130                "account" => Deserialize::begin(&mut self.account),
131                "account_holder_name" => Deserialize::begin(&mut self.account_holder_name),
132                "account_holder_type" => Deserialize::begin(&mut self.account_holder_type),
133                "account_type" => Deserialize::begin(&mut self.account_type),
134                "available_payout_methods" => {
135                    Deserialize::begin(&mut self.available_payout_methods)
136                }
137                "bank_name" => Deserialize::begin(&mut self.bank_name),
138                "country" => Deserialize::begin(&mut self.country),
139                "currency" => Deserialize::begin(&mut self.currency),
140                "customer" => Deserialize::begin(&mut self.customer),
141                "default_for_currency" => Deserialize::begin(&mut self.default_for_currency),
142                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
143                "future_requirements" => Deserialize::begin(&mut self.future_requirements),
144                "id" => Deserialize::begin(&mut self.id),
145                "last4" => Deserialize::begin(&mut self.last4),
146                "metadata" => Deserialize::begin(&mut self.metadata),
147                "requirements" => Deserialize::begin(&mut self.requirements),
148                "routing_number" => Deserialize::begin(&mut self.routing_number),
149                "status" => Deserialize::begin(&mut self.status),
150                _ => <dyn Visitor>::ignore(),
151            })
152        }
153
154        fn deser_default() -> Self {
155            Self {
156                account: Deserialize::default(),
157                account_holder_name: Deserialize::default(),
158                account_holder_type: Deserialize::default(),
159                account_type: Deserialize::default(),
160                available_payout_methods: Deserialize::default(),
161                bank_name: Deserialize::default(),
162                country: Deserialize::default(),
163                currency: Deserialize::default(),
164                customer: Deserialize::default(),
165                default_for_currency: Deserialize::default(),
166                fingerprint: Deserialize::default(),
167                future_requirements: Deserialize::default(),
168                id: Deserialize::default(),
169                last4: Deserialize::default(),
170                metadata: Deserialize::default(),
171                requirements: Deserialize::default(),
172                routing_number: Deserialize::default(),
173                status: Deserialize::default(),
174            }
175        }
176
177        fn take_out(&mut self) -> Option<Self::Out> {
178            let (
179                Some(account),
180                Some(account_holder_name),
181                Some(account_holder_type),
182                Some(account_type),
183                Some(available_payout_methods),
184                Some(bank_name),
185                Some(country),
186                Some(currency),
187                Some(customer),
188                Some(default_for_currency),
189                Some(fingerprint),
190                Some(future_requirements),
191                Some(id),
192                Some(last4),
193                Some(metadata),
194                Some(requirements),
195                Some(routing_number),
196                Some(status),
197            ) = (
198                self.account.take(),
199                self.account_holder_name.take(),
200                self.account_holder_type.take(),
201                self.account_type.take(),
202                self.available_payout_methods.take(),
203                self.bank_name.take(),
204                self.country.take(),
205                self.currency.take(),
206                self.customer.take(),
207                self.default_for_currency,
208                self.fingerprint.take(),
209                self.future_requirements.take(),
210                self.id.take(),
211                self.last4.take(),
212                self.metadata.take(),
213                self.requirements.take(),
214                self.routing_number.take(),
215                self.status.take(),
216            )
217            else {
218                return None;
219            };
220            Some(Self::Out {
221                account,
222                account_holder_name,
223                account_holder_type,
224                account_type,
225                available_payout_methods,
226                bank_name,
227                country,
228                currency,
229                customer,
230                default_for_currency,
231                fingerprint,
232                future_requirements,
233                id,
234                last4,
235                metadata,
236                requirements,
237                routing_number,
238                status,
239            })
240        }
241    }
242
243    impl Map for Builder<'_> {
244        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
245            self.builder.key(k)
246        }
247
248        fn finish(&mut self) -> Result<()> {
249            *self.out = self.builder.take_out();
250            Ok(())
251        }
252    }
253
254    impl ObjectDeser for BankAccount {
255        type Builder = BankAccountBuilder;
256    }
257
258    impl FromValueOpt for BankAccount {
259        fn from_value(v: Value) -> Option<Self> {
260            let Value::Object(obj) = v else {
261                return None;
262            };
263            let mut b = BankAccountBuilder::deser_default();
264            for (k, v) in obj {
265                match k.as_str() {
266                    "account" => b.account = FromValueOpt::from_value(v),
267                    "account_holder_name" => b.account_holder_name = FromValueOpt::from_value(v),
268                    "account_holder_type" => b.account_holder_type = FromValueOpt::from_value(v),
269                    "account_type" => b.account_type = FromValueOpt::from_value(v),
270                    "available_payout_methods" => {
271                        b.available_payout_methods = FromValueOpt::from_value(v)
272                    }
273                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
274                    "country" => b.country = FromValueOpt::from_value(v),
275                    "currency" => b.currency = FromValueOpt::from_value(v),
276                    "customer" => b.customer = FromValueOpt::from_value(v),
277                    "default_for_currency" => b.default_for_currency = FromValueOpt::from_value(v),
278                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
279                    "future_requirements" => b.future_requirements = FromValueOpt::from_value(v),
280                    "id" => b.id = FromValueOpt::from_value(v),
281                    "last4" => b.last4 = FromValueOpt::from_value(v),
282                    "metadata" => b.metadata = FromValueOpt::from_value(v),
283                    "requirements" => b.requirements = FromValueOpt::from_value(v),
284                    "routing_number" => b.routing_number = FromValueOpt::from_value(v),
285                    "status" => b.status = FromValueOpt::from_value(v),
286                    _ => {}
287                }
288            }
289            b.take_out()
290        }
291    }
292};
293#[cfg(feature = "serialize")]
294impl serde::Serialize for BankAccount {
295    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
296        use serde::ser::SerializeStruct;
297        let mut s = s.serialize_struct("BankAccount", 19)?;
298        s.serialize_field("account", &self.account)?;
299        s.serialize_field("account_holder_name", &self.account_holder_name)?;
300        s.serialize_field("account_holder_type", &self.account_holder_type)?;
301        s.serialize_field("account_type", &self.account_type)?;
302        s.serialize_field("available_payout_methods", &self.available_payout_methods)?;
303        s.serialize_field("bank_name", &self.bank_name)?;
304        s.serialize_field("country", &self.country)?;
305        s.serialize_field("currency", &self.currency)?;
306        s.serialize_field("customer", &self.customer)?;
307        s.serialize_field("default_for_currency", &self.default_for_currency)?;
308        s.serialize_field("fingerprint", &self.fingerprint)?;
309        s.serialize_field("future_requirements", &self.future_requirements)?;
310        s.serialize_field("id", &self.id)?;
311        s.serialize_field("last4", &self.last4)?;
312        s.serialize_field("metadata", &self.metadata)?;
313        s.serialize_field("requirements", &self.requirements)?;
314        s.serialize_field("routing_number", &self.routing_number)?;
315        s.serialize_field("status", &self.status)?;
316
317        s.serialize_field("object", "bank_account")?;
318        s.end()
319    }
320}
321/// A set of available payout methods for this bank account.
322/// Only values from this set should be passed as the `method` when creating a payout.
323#[derive(Copy, Clone, Eq, PartialEq)]
324pub enum BankAccountAvailablePayoutMethods {
325    Instant,
326    Standard,
327}
328impl BankAccountAvailablePayoutMethods {
329    pub fn as_str(self) -> &'static str {
330        use BankAccountAvailablePayoutMethods::*;
331        match self {
332            Instant => "instant",
333            Standard => "standard",
334        }
335    }
336}
337
338impl std::str::FromStr for BankAccountAvailablePayoutMethods {
339    type Err = stripe_types::StripeParseError;
340    fn from_str(s: &str) -> Result<Self, Self::Err> {
341        use BankAccountAvailablePayoutMethods::*;
342        match s {
343            "instant" => Ok(Instant),
344            "standard" => Ok(Standard),
345            _ => Err(stripe_types::StripeParseError),
346        }
347    }
348}
349impl std::fmt::Display for BankAccountAvailablePayoutMethods {
350    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
351        f.write_str(self.as_str())
352    }
353}
354
355impl std::fmt::Debug for BankAccountAvailablePayoutMethods {
356    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
357        f.write_str(self.as_str())
358    }
359}
360#[cfg(feature = "serialize")]
361impl serde::Serialize for BankAccountAvailablePayoutMethods {
362    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
363    where
364        S: serde::Serializer,
365    {
366        serializer.serialize_str(self.as_str())
367    }
368}
369impl miniserde::Deserialize for BankAccountAvailablePayoutMethods {
370    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
371        crate::Place::new(out)
372    }
373}
374
375impl miniserde::de::Visitor for crate::Place<BankAccountAvailablePayoutMethods> {
376    fn string(&mut self, s: &str) -> miniserde::Result<()> {
377        use std::str::FromStr;
378        self.out =
379            Some(BankAccountAvailablePayoutMethods::from_str(s).map_err(|_| miniserde::Error)?);
380        Ok(())
381    }
382}
383
384stripe_types::impl_from_val_with_from_str!(BankAccountAvailablePayoutMethods);
385#[cfg(feature = "deserialize")]
386impl<'de> serde::Deserialize<'de> for BankAccountAvailablePayoutMethods {
387    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
388        use std::str::FromStr;
389        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
390        Self::from_str(&s).map_err(|_| {
391            serde::de::Error::custom("Unknown value for BankAccountAvailablePayoutMethods")
392        })
393    }
394}
395impl stripe_types::Object for BankAccount {
396    type Id = stripe_shared::BankAccountId;
397    fn id(&self) -> &Self::Id {
398        &self.id
399    }
400
401    fn into_id(self) -> Self::Id {
402        self.id
403    }
404}
405stripe_types::def_id!(BankAccountId);