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