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