stripe_shared/
payment_method_us_bank_account.rs

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