Skip to main content

stripe_shared/
payment_method_details_us_bank_account.rs

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