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`, 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 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.
58    ///
59    /// For external accounts, possible values are `new`, `errored` and `verification_failed`.
60    /// If a payout fails, the status is set to `errored` and scheduled payouts are stopped until account details are updated.
61    /// 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`.
62    /// Other validations aren't run against external accounts because they're only used for payouts.
63    /// This means the other statuses don't apply.
64    pub status: String,
65}
66#[doc(hidden)]
67pub struct BankAccountBuilder {
68    account: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
69    account_holder_name: Option<Option<String>>,
70    account_holder_type: Option<Option<String>>,
71    account_type: Option<Option<String>>,
72    available_payout_methods: Option<Option<Vec<BankAccountAvailablePayoutMethods>>>,
73    bank_name: Option<Option<String>>,
74    country: Option<String>,
75    currency: Option<stripe_types::Currency>,
76    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
77    default_for_currency: Option<Option<bool>>,
78    fingerprint: Option<Option<String>>,
79    future_requirements: Option<Option<stripe_shared::ExternalAccountRequirements>>,
80    id: Option<stripe_shared::BankAccountId>,
81    last4: Option<String>,
82    metadata: Option<Option<std::collections::HashMap<String, String>>>,
83    requirements: Option<Option<stripe_shared::ExternalAccountRequirements>>,
84    routing_number: Option<Option<String>>,
85    status: Option<String>,
86}
87
88#[allow(
89    unused_variables,
90    irrefutable_let_patterns,
91    clippy::let_unit_value,
92    clippy::match_single_binding,
93    clippy::single_match
94)]
95const _: () = {
96    use miniserde::de::{Map, Visitor};
97    use miniserde::json::Value;
98    use miniserde::{Deserialize, Result, make_place};
99    use stripe_types::miniserde_helpers::FromValueOpt;
100    use stripe_types::{MapBuilder, ObjectDeser};
101
102    make_place!(Place);
103
104    impl Deserialize for BankAccount {
105        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
106            Place::new(out)
107        }
108    }
109
110    struct Builder<'a> {
111        out: &'a mut Option<BankAccount>,
112        builder: BankAccountBuilder,
113    }
114
115    impl Visitor for Place<BankAccount> {
116        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
117            Ok(Box::new(Builder {
118                out: &mut self.out,
119                builder: BankAccountBuilder::deser_default(),
120            }))
121        }
122    }
123
124    impl MapBuilder for BankAccountBuilder {
125        type Out = BankAccount;
126        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
127            Ok(match k {
128                "account" => Deserialize::begin(&mut self.account),
129                "account_holder_name" => Deserialize::begin(&mut self.account_holder_name),
130                "account_holder_type" => Deserialize::begin(&mut self.account_holder_type),
131                "account_type" => Deserialize::begin(&mut self.account_type),
132                "available_payout_methods" => {
133                    Deserialize::begin(&mut self.available_payout_methods)
134                }
135                "bank_name" => Deserialize::begin(&mut self.bank_name),
136                "country" => Deserialize::begin(&mut self.country),
137                "currency" => Deserialize::begin(&mut self.currency),
138                "customer" => Deserialize::begin(&mut self.customer),
139                "default_for_currency" => Deserialize::begin(&mut self.default_for_currency),
140                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
141                "future_requirements" => Deserialize::begin(&mut self.future_requirements),
142                "id" => Deserialize::begin(&mut self.id),
143                "last4" => Deserialize::begin(&mut self.last4),
144                "metadata" => Deserialize::begin(&mut self.metadata),
145                "requirements" => Deserialize::begin(&mut self.requirements),
146                "routing_number" => Deserialize::begin(&mut self.routing_number),
147                "status" => Deserialize::begin(&mut self.status),
148                _ => <dyn Visitor>::ignore(),
149            })
150        }
151
152        fn deser_default() -> Self {
153            Self {
154                account: Deserialize::default(),
155                account_holder_name: Deserialize::default(),
156                account_holder_type: Deserialize::default(),
157                account_type: Deserialize::default(),
158                available_payout_methods: Deserialize::default(),
159                bank_name: Deserialize::default(),
160                country: Deserialize::default(),
161                currency: Deserialize::default(),
162                customer: Deserialize::default(),
163                default_for_currency: Deserialize::default(),
164                fingerprint: Deserialize::default(),
165                future_requirements: Deserialize::default(),
166                id: Deserialize::default(),
167                last4: Deserialize::default(),
168                metadata: Deserialize::default(),
169                requirements: Deserialize::default(),
170                routing_number: Deserialize::default(),
171                status: Deserialize::default(),
172            }
173        }
174
175        fn take_out(&mut self) -> Option<Self::Out> {
176            let (
177                Some(account),
178                Some(account_holder_name),
179                Some(account_holder_type),
180                Some(account_type),
181                Some(available_payout_methods),
182                Some(bank_name),
183                Some(country),
184                Some(currency),
185                Some(customer),
186                Some(default_for_currency),
187                Some(fingerprint),
188                Some(future_requirements),
189                Some(id),
190                Some(last4),
191                Some(metadata),
192                Some(requirements),
193                Some(routing_number),
194                Some(status),
195            ) = (
196                self.account.take(),
197                self.account_holder_name.take(),
198                self.account_holder_type.take(),
199                self.account_type.take(),
200                self.available_payout_methods.take(),
201                self.bank_name.take(),
202                self.country.take(),
203                self.currency.take(),
204                self.customer.take(),
205                self.default_for_currency,
206                self.fingerprint.take(),
207                self.future_requirements.take(),
208                self.id.take(),
209                self.last4.take(),
210                self.metadata.take(),
211                self.requirements.take(),
212                self.routing_number.take(),
213                self.status.take(),
214            )
215            else {
216                return None;
217            };
218            Some(Self::Out {
219                account,
220                account_holder_name,
221                account_holder_type,
222                account_type,
223                available_payout_methods,
224                bank_name,
225                country,
226                currency,
227                customer,
228                default_for_currency,
229                fingerprint,
230                future_requirements,
231                id,
232                last4,
233                metadata,
234                requirements,
235                routing_number,
236                status,
237            })
238        }
239    }
240
241    impl Map for Builder<'_> {
242        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
243            self.builder.key(k)
244        }
245
246        fn finish(&mut self) -> Result<()> {
247            *self.out = self.builder.take_out();
248            Ok(())
249        }
250    }
251
252    impl ObjectDeser for BankAccount {
253        type Builder = BankAccountBuilder;
254    }
255
256    impl FromValueOpt for BankAccount {
257        fn from_value(v: Value) -> Option<Self> {
258            let Value::Object(obj) = v else {
259                return None;
260            };
261            let mut b = BankAccountBuilder::deser_default();
262            for (k, v) in obj {
263                match k.as_str() {
264                    "account" => b.account = FromValueOpt::from_value(v),
265                    "account_holder_name" => b.account_holder_name = FromValueOpt::from_value(v),
266                    "account_holder_type" => b.account_holder_type = FromValueOpt::from_value(v),
267                    "account_type" => b.account_type = FromValueOpt::from_value(v),
268                    "available_payout_methods" => {
269                        b.available_payout_methods = FromValueOpt::from_value(v)
270                    }
271                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
272                    "country" => b.country = FromValueOpt::from_value(v),
273                    "currency" => b.currency = FromValueOpt::from_value(v),
274                    "customer" => b.customer = FromValueOpt::from_value(v),
275                    "default_for_currency" => b.default_for_currency = FromValueOpt::from_value(v),
276                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
277                    "future_requirements" => b.future_requirements = FromValueOpt::from_value(v),
278                    "id" => b.id = FromValueOpt::from_value(v),
279                    "last4" => b.last4 = FromValueOpt::from_value(v),
280                    "metadata" => b.metadata = FromValueOpt::from_value(v),
281                    "requirements" => b.requirements = FromValueOpt::from_value(v),
282                    "routing_number" => b.routing_number = FromValueOpt::from_value(v),
283                    "status" => b.status = FromValueOpt::from_value(v),
284                    _ => {}
285                }
286            }
287            b.take_out()
288        }
289    }
290};
291#[cfg(feature = "serialize")]
292impl serde::Serialize for BankAccount {
293    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
294        use serde::ser::SerializeStruct;
295        let mut s = s.serialize_struct("BankAccount", 19)?;
296        s.serialize_field("account", &self.account)?;
297        s.serialize_field("account_holder_name", &self.account_holder_name)?;
298        s.serialize_field("account_holder_type", &self.account_holder_type)?;
299        s.serialize_field("account_type", &self.account_type)?;
300        s.serialize_field("available_payout_methods", &self.available_payout_methods)?;
301        s.serialize_field("bank_name", &self.bank_name)?;
302        s.serialize_field("country", &self.country)?;
303        s.serialize_field("currency", &self.currency)?;
304        s.serialize_field("customer", &self.customer)?;
305        s.serialize_field("default_for_currency", &self.default_for_currency)?;
306        s.serialize_field("fingerprint", &self.fingerprint)?;
307        s.serialize_field("future_requirements", &self.future_requirements)?;
308        s.serialize_field("id", &self.id)?;
309        s.serialize_field("last4", &self.last4)?;
310        s.serialize_field("metadata", &self.metadata)?;
311        s.serialize_field("requirements", &self.requirements)?;
312        s.serialize_field("routing_number", &self.routing_number)?;
313        s.serialize_field("status", &self.status)?;
314
315        s.serialize_field("object", "bank_account")?;
316        s.end()
317    }
318}
319/// A set of available payout methods for this bank account.
320/// Only values from this set should be passed as the `method` when creating a payout.
321#[derive(Copy, Clone, Eq, PartialEq)]
322pub enum BankAccountAvailablePayoutMethods {
323    Instant,
324    Standard,
325}
326impl BankAccountAvailablePayoutMethods {
327    pub fn as_str(self) -> &'static str {
328        use BankAccountAvailablePayoutMethods::*;
329        match self {
330            Instant => "instant",
331            Standard => "standard",
332        }
333    }
334}
335
336impl std::str::FromStr for BankAccountAvailablePayoutMethods {
337    type Err = stripe_types::StripeParseError;
338    fn from_str(s: &str) -> Result<Self, Self::Err> {
339        use BankAccountAvailablePayoutMethods::*;
340        match s {
341            "instant" => Ok(Instant),
342            "standard" => Ok(Standard),
343            _ => Err(stripe_types::StripeParseError),
344        }
345    }
346}
347impl std::fmt::Display for BankAccountAvailablePayoutMethods {
348    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
349        f.write_str(self.as_str())
350    }
351}
352
353impl std::fmt::Debug for BankAccountAvailablePayoutMethods {
354    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
355        f.write_str(self.as_str())
356    }
357}
358#[cfg(feature = "serialize")]
359impl serde::Serialize for BankAccountAvailablePayoutMethods {
360    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
361    where
362        S: serde::Serializer,
363    {
364        serializer.serialize_str(self.as_str())
365    }
366}
367impl miniserde::Deserialize for BankAccountAvailablePayoutMethods {
368    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
369        crate::Place::new(out)
370    }
371}
372
373impl miniserde::de::Visitor for crate::Place<BankAccountAvailablePayoutMethods> {
374    fn string(&mut self, s: &str) -> miniserde::Result<()> {
375        use std::str::FromStr;
376        self.out =
377            Some(BankAccountAvailablePayoutMethods::from_str(s).map_err(|_| miniserde::Error)?);
378        Ok(())
379    }
380}
381
382stripe_types::impl_from_val_with_from_str!(BankAccountAvailablePayoutMethods);
383#[cfg(feature = "deserialize")]
384impl<'de> serde::Deserialize<'de> for BankAccountAvailablePayoutMethods {
385    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
386        use std::str::FromStr;
387        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
388        Self::from_str(&s).map_err(|_| {
389            serde::de::Error::custom("Unknown value for BankAccountAvailablePayoutMethods")
390        })
391    }
392}
393impl stripe_types::Object for BankAccount {
394    type Id = stripe_shared::BankAccountId;
395    fn id(&self) -> &Self::Id {
396        &self.id
397    }
398
399    fn into_id(self) -> Self::Id {
400        self.id
401    }
402}
403stripe_types::def_id!(BankAccountId);