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.take(),
120                self.account_type.take(),
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.take(),
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(Clone, Eq, PartialEq)]
189#[non_exhaustive]
190pub enum PaymentMethodUsBankAccountAccountHolderType {
191    Company,
192    Individual,
193    /// An unrecognized value from Stripe. Should not be used as a request parameter.
194    Unknown(String),
195}
196impl PaymentMethodUsBankAccountAccountHolderType {
197    pub fn as_str(&self) -> &str {
198        use PaymentMethodUsBankAccountAccountHolderType::*;
199        match self {
200            Company => "company",
201            Individual => "individual",
202            Unknown(v) => v,
203        }
204    }
205}
206
207impl std::str::FromStr for PaymentMethodUsBankAccountAccountHolderType {
208    type Err = std::convert::Infallible;
209    fn from_str(s: &str) -> Result<Self, Self::Err> {
210        use PaymentMethodUsBankAccountAccountHolderType::*;
211        match s {
212            "company" => Ok(Company),
213            "individual" => Ok(Individual),
214            v => {
215                tracing::warn!(
216                    "Unknown value '{}' for enum '{}'",
217                    v,
218                    "PaymentMethodUsBankAccountAccountHolderType"
219                );
220                Ok(Unknown(v.to_owned()))
221            }
222        }
223    }
224}
225impl std::fmt::Display for PaymentMethodUsBankAccountAccountHolderType {
226    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
227        f.write_str(self.as_str())
228    }
229}
230
231impl std::fmt::Debug for PaymentMethodUsBankAccountAccountHolderType {
232    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
233        f.write_str(self.as_str())
234    }
235}
236#[cfg(feature = "serialize")]
237impl serde::Serialize for PaymentMethodUsBankAccountAccountHolderType {
238    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
239    where
240        S: serde::Serializer,
241    {
242        serializer.serialize_str(self.as_str())
243    }
244}
245impl miniserde::Deserialize for PaymentMethodUsBankAccountAccountHolderType {
246    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
247        crate::Place::new(out)
248    }
249}
250
251impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountAccountHolderType> {
252    fn string(&mut self, s: &str) -> miniserde::Result<()> {
253        use std::str::FromStr;
254        self.out =
255            Some(PaymentMethodUsBankAccountAccountHolderType::from_str(s).expect("infallible"));
256        Ok(())
257    }
258}
259
260stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountAccountHolderType);
261#[cfg(feature = "deserialize")]
262impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountAccountHolderType {
263    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
264        use std::str::FromStr;
265        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
266        Ok(Self::from_str(&s).expect("infallible"))
267    }
268}
269/// Account type: checkings or savings. Defaults to checking if omitted.
270#[derive(Clone, Eq, PartialEq)]
271#[non_exhaustive]
272pub enum PaymentMethodUsBankAccountAccountType {
273    Checking,
274    Savings,
275    /// An unrecognized value from Stripe. Should not be used as a request parameter.
276    Unknown(String),
277}
278impl PaymentMethodUsBankAccountAccountType {
279    pub fn as_str(&self) -> &str {
280        use PaymentMethodUsBankAccountAccountType::*;
281        match self {
282            Checking => "checking",
283            Savings => "savings",
284            Unknown(v) => v,
285        }
286    }
287}
288
289impl std::str::FromStr for PaymentMethodUsBankAccountAccountType {
290    type Err = std::convert::Infallible;
291    fn from_str(s: &str) -> Result<Self, Self::Err> {
292        use PaymentMethodUsBankAccountAccountType::*;
293        match s {
294            "checking" => Ok(Checking),
295            "savings" => Ok(Savings),
296            v => {
297                tracing::warn!(
298                    "Unknown value '{}' for enum '{}'",
299                    v,
300                    "PaymentMethodUsBankAccountAccountType"
301                );
302                Ok(Unknown(v.to_owned()))
303            }
304        }
305    }
306}
307impl std::fmt::Display for PaymentMethodUsBankAccountAccountType {
308    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
309        f.write_str(self.as_str())
310    }
311}
312
313impl std::fmt::Debug for PaymentMethodUsBankAccountAccountType {
314    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
315        f.write_str(self.as_str())
316    }
317}
318#[cfg(feature = "serialize")]
319impl serde::Serialize for PaymentMethodUsBankAccountAccountType {
320    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
321    where
322        S: serde::Serializer,
323    {
324        serializer.serialize_str(self.as_str())
325    }
326}
327impl miniserde::Deserialize for PaymentMethodUsBankAccountAccountType {
328    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
329        crate::Place::new(out)
330    }
331}
332
333impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountAccountType> {
334    fn string(&mut self, s: &str) -> miniserde::Result<()> {
335        use std::str::FromStr;
336        self.out = Some(PaymentMethodUsBankAccountAccountType::from_str(s).expect("infallible"));
337        Ok(())
338    }
339}
340
341stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountAccountType);
342#[cfg(feature = "deserialize")]
343impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountAccountType {
344    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
345        use std::str::FromStr;
346        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
347        Ok(Self::from_str(&s).expect("infallible"))
348    }
349}