Skip to main content

stripe_shared/
payment_method_us_bank_account.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentMethodUsBankAccount {
6    /// Account holder type: individual or company.
7    pub account_holder_type: Option<PaymentMethodUsBankAccountAccountHolderType>,
8    /// Account type: checkings or savings. Defaults to checking if omitted.
9    pub account_type: Option<PaymentMethodUsBankAccountAccountType>,
10    /// The name of the bank.
11    pub bank_name: Option<String>,
12    /// The ID of the Financial Connections Account used to create the payment method.
13    pub financial_connections_account: Option<String>,
14    /// Uniquely identifies this particular bank account.
15    /// You can use this attribute to check whether two bank accounts are the same.
16    pub fingerprint: Option<String>,
17    /// Last four digits of the bank account number.
18    pub last4: Option<String>,
19    /// Contains information about US bank account networks that can be used.
20    pub networks: Option<stripe_shared::UsBankAccountNetworks>,
21    /// Routing number of the bank account.
22    pub routing_number: Option<String>,
23    /// Contains information about the future reusability of this PaymentMethod.
24    pub status_details: Option<stripe_shared::PaymentMethodUsBankAccountStatusDetails>,
25}
26#[cfg(feature = "redact-generated-debug")]
27impl std::fmt::Debug for PaymentMethodUsBankAccount {
28    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
29        f.debug_struct("PaymentMethodUsBankAccount").finish_non_exhaustive()
30    }
31}
32#[doc(hidden)]
33pub struct PaymentMethodUsBankAccountBuilder {
34    account_holder_type: Option<Option<PaymentMethodUsBankAccountAccountHolderType>>,
35    account_type: Option<Option<PaymentMethodUsBankAccountAccountType>>,
36    bank_name: Option<Option<String>>,
37    financial_connections_account: Option<Option<String>>,
38    fingerprint: Option<Option<String>>,
39    last4: Option<Option<String>>,
40    networks: Option<Option<stripe_shared::UsBankAccountNetworks>>,
41    routing_number: Option<Option<String>>,
42    status_details: Option<Option<stripe_shared::PaymentMethodUsBankAccountStatusDetails>>,
43}
44
45#[allow(
46    unused_variables,
47    irrefutable_let_patterns,
48    clippy::let_unit_value,
49    clippy::match_single_binding,
50    clippy::single_match
51)]
52const _: () = {
53    use miniserde::de::{Map, Visitor};
54    use miniserde::json::Value;
55    use miniserde::{Deserialize, Result, make_place};
56    use stripe_types::miniserde_helpers::FromValueOpt;
57    use stripe_types::{MapBuilder, ObjectDeser};
58
59    make_place!(Place);
60
61    impl Deserialize for PaymentMethodUsBankAccount {
62        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
63            Place::new(out)
64        }
65    }
66
67    struct Builder<'a> {
68        out: &'a mut Option<PaymentMethodUsBankAccount>,
69        builder: PaymentMethodUsBankAccountBuilder,
70    }
71
72    impl Visitor for Place<PaymentMethodUsBankAccount> {
73        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
74            Ok(Box::new(Builder {
75                out: &mut self.out,
76                builder: PaymentMethodUsBankAccountBuilder::deser_default(),
77            }))
78        }
79    }
80
81    impl MapBuilder for PaymentMethodUsBankAccountBuilder {
82        type Out = PaymentMethodUsBankAccount;
83        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
84            Ok(match k {
85                "account_holder_type" => Deserialize::begin(&mut self.account_holder_type),
86                "account_type" => Deserialize::begin(&mut self.account_type),
87                "bank_name" => Deserialize::begin(&mut self.bank_name),
88                "financial_connections_account" => {
89                    Deserialize::begin(&mut self.financial_connections_account)
90                }
91                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
92                "last4" => Deserialize::begin(&mut self.last4),
93                "networks" => Deserialize::begin(&mut self.networks),
94                "routing_number" => Deserialize::begin(&mut self.routing_number),
95                "status_details" => Deserialize::begin(&mut self.status_details),
96                _ => <dyn Visitor>::ignore(),
97            })
98        }
99
100        fn deser_default() -> Self {
101            Self {
102                account_holder_type: Some(None),
103                account_type: Some(None),
104                bank_name: Some(None),
105                financial_connections_account: Some(None),
106                fingerprint: Some(None),
107                last4: Some(None),
108                networks: Some(None),
109                routing_number: Some(None),
110                status_details: Some(None),
111            }
112        }
113
114        fn take_out(&mut self) -> Option<Self::Out> {
115            let (
116                Some(account_holder_type),
117                Some(account_type),
118                Some(bank_name),
119                Some(financial_connections_account),
120                Some(fingerprint),
121                Some(last4),
122                Some(networks),
123                Some(routing_number),
124                Some(status_details),
125            ) = (
126                self.account_holder_type.take(),
127                self.account_type.take(),
128                self.bank_name.take(),
129                self.financial_connections_account.take(),
130                self.fingerprint.take(),
131                self.last4.take(),
132                self.networks.take(),
133                self.routing_number.take(),
134                self.status_details.take(),
135            )
136            else {
137                return None;
138            };
139            Some(Self::Out {
140                account_holder_type,
141                account_type,
142                bank_name,
143                financial_connections_account,
144                fingerprint,
145                last4,
146                networks,
147                routing_number,
148                status_details,
149            })
150        }
151    }
152
153    impl Map for Builder<'_> {
154        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
155            self.builder.key(k)
156        }
157
158        fn finish(&mut self) -> Result<()> {
159            *self.out = self.builder.take_out();
160            Ok(())
161        }
162    }
163
164    impl ObjectDeser for PaymentMethodUsBankAccount {
165        type Builder = PaymentMethodUsBankAccountBuilder;
166    }
167
168    impl FromValueOpt for PaymentMethodUsBankAccount {
169        fn from_value(v: Value) -> Option<Self> {
170            let Value::Object(obj) = v else {
171                return None;
172            };
173            let mut b = PaymentMethodUsBankAccountBuilder::deser_default();
174            for (k, v) in obj {
175                match k.as_str() {
176                    "account_holder_type" => b.account_holder_type = FromValueOpt::from_value(v),
177                    "account_type" => b.account_type = FromValueOpt::from_value(v),
178                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
179                    "financial_connections_account" => {
180                        b.financial_connections_account = FromValueOpt::from_value(v)
181                    }
182                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
183                    "last4" => b.last4 = FromValueOpt::from_value(v),
184                    "networks" => b.networks = FromValueOpt::from_value(v),
185                    "routing_number" => b.routing_number = FromValueOpt::from_value(v),
186                    "status_details" => b.status_details = FromValueOpt::from_value(v),
187                    _ => {}
188                }
189            }
190            b.take_out()
191        }
192    }
193};
194/// Account holder type: individual or company.
195#[derive(Clone, Eq, PartialEq)]
196#[non_exhaustive]
197pub enum PaymentMethodUsBankAccountAccountHolderType {
198    Company,
199    Individual,
200    /// An unrecognized value from Stripe. Should not be used as a request parameter.
201    Unknown(String),
202}
203impl PaymentMethodUsBankAccountAccountHolderType {
204    pub fn as_str(&self) -> &str {
205        use PaymentMethodUsBankAccountAccountHolderType::*;
206        match self {
207            Company => "company",
208            Individual => "individual",
209            Unknown(v) => v,
210        }
211    }
212}
213
214impl std::str::FromStr for PaymentMethodUsBankAccountAccountHolderType {
215    type Err = std::convert::Infallible;
216    fn from_str(s: &str) -> Result<Self, Self::Err> {
217        use PaymentMethodUsBankAccountAccountHolderType::*;
218        match s {
219            "company" => Ok(Company),
220            "individual" => Ok(Individual),
221            v => {
222                tracing::warn!(
223                    "Unknown value '{}' for enum '{}'",
224                    v,
225                    "PaymentMethodUsBankAccountAccountHolderType"
226                );
227                Ok(Unknown(v.to_owned()))
228            }
229        }
230    }
231}
232impl std::fmt::Display for PaymentMethodUsBankAccountAccountHolderType {
233    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
234        f.write_str(self.as_str())
235    }
236}
237
238#[cfg(not(feature = "redact-generated-debug"))]
239impl std::fmt::Debug for PaymentMethodUsBankAccountAccountHolderType {
240    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
241        f.write_str(self.as_str())
242    }
243}
244#[cfg(feature = "redact-generated-debug")]
245impl std::fmt::Debug for PaymentMethodUsBankAccountAccountHolderType {
246    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
247        f.debug_struct(stringify!(PaymentMethodUsBankAccountAccountHolderType))
248            .finish_non_exhaustive()
249    }
250}
251#[cfg(feature = "serialize")]
252impl serde::Serialize for PaymentMethodUsBankAccountAccountHolderType {
253    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
254    where
255        S: serde::Serializer,
256    {
257        serializer.serialize_str(self.as_str())
258    }
259}
260impl miniserde::Deserialize for PaymentMethodUsBankAccountAccountHolderType {
261    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
262        crate::Place::new(out)
263    }
264}
265
266impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountAccountHolderType> {
267    fn string(&mut self, s: &str) -> miniserde::Result<()> {
268        use std::str::FromStr;
269        self.out =
270            Some(PaymentMethodUsBankAccountAccountHolderType::from_str(s).expect("infallible"));
271        Ok(())
272    }
273}
274
275stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountAccountHolderType);
276#[cfg(feature = "deserialize")]
277impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountAccountHolderType {
278    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
279        use std::str::FromStr;
280        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
281        Ok(Self::from_str(&s).expect("infallible"))
282    }
283}
284/// Account type: checkings or savings. Defaults to checking if omitted.
285#[derive(Clone, Eq, PartialEq)]
286#[non_exhaustive]
287pub enum PaymentMethodUsBankAccountAccountType {
288    Checking,
289    Savings,
290    /// An unrecognized value from Stripe. Should not be used as a request parameter.
291    Unknown(String),
292}
293impl PaymentMethodUsBankAccountAccountType {
294    pub fn as_str(&self) -> &str {
295        use PaymentMethodUsBankAccountAccountType::*;
296        match self {
297            Checking => "checking",
298            Savings => "savings",
299            Unknown(v) => v,
300        }
301    }
302}
303
304impl std::str::FromStr for PaymentMethodUsBankAccountAccountType {
305    type Err = std::convert::Infallible;
306    fn from_str(s: &str) -> Result<Self, Self::Err> {
307        use PaymentMethodUsBankAccountAccountType::*;
308        match s {
309            "checking" => Ok(Checking),
310            "savings" => Ok(Savings),
311            v => {
312                tracing::warn!(
313                    "Unknown value '{}' for enum '{}'",
314                    v,
315                    "PaymentMethodUsBankAccountAccountType"
316                );
317                Ok(Unknown(v.to_owned()))
318            }
319        }
320    }
321}
322impl std::fmt::Display for PaymentMethodUsBankAccountAccountType {
323    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
324        f.write_str(self.as_str())
325    }
326}
327
328#[cfg(not(feature = "redact-generated-debug"))]
329impl std::fmt::Debug for PaymentMethodUsBankAccountAccountType {
330    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
331        f.write_str(self.as_str())
332    }
333}
334#[cfg(feature = "redact-generated-debug")]
335impl std::fmt::Debug for PaymentMethodUsBankAccountAccountType {
336    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
337        f.debug_struct(stringify!(PaymentMethodUsBankAccountAccountType)).finish_non_exhaustive()
338    }
339}
340#[cfg(feature = "serialize")]
341impl serde::Serialize for PaymentMethodUsBankAccountAccountType {
342    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
343    where
344        S: serde::Serializer,
345    {
346        serializer.serialize_str(self.as_str())
347    }
348}
349impl miniserde::Deserialize for PaymentMethodUsBankAccountAccountType {
350    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
351        crate::Place::new(out)
352    }
353}
354
355impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountAccountType> {
356    fn string(&mut self, s: &str) -> miniserde::Result<()> {
357        use std::str::FromStr;
358        self.out = Some(PaymentMethodUsBankAccountAccountType::from_str(s).expect("infallible"));
359        Ok(())
360    }
361}
362
363stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountAccountType);
364#[cfg(feature = "deserialize")]
365impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountAccountType {
366    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
367        use std::str::FromStr;
368        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
369        Ok(Self::from_str(&s).expect("infallible"))
370    }
371}