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::{make_place, Deserialize, Result};
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
90                _ => <dyn Visitor>::ignore(),
91            })
92        }
93
94        fn deser_default() -> Self {
95            Self {
96                account_holder_type: Deserialize::default(),
97                account_type: Deserialize::default(),
98                bank_name: Deserialize::default(),
99                financial_connections_account: Deserialize::default(),
100                fingerprint: Deserialize::default(),
101                last4: Deserialize::default(),
102                networks: Deserialize::default(),
103                routing_number: Deserialize::default(),
104                status_details: Deserialize::default(),
105            }
106        }
107
108        fn take_out(&mut self) -> Option<Self::Out> {
109            let (
110                Some(account_holder_type),
111                Some(account_type),
112                Some(bank_name),
113                Some(financial_connections_account),
114                Some(fingerprint),
115                Some(last4),
116                Some(networks),
117                Some(routing_number),
118                Some(status_details),
119            ) = (
120                self.account_holder_type,
121                self.account_type,
122                self.bank_name.take(),
123                self.financial_connections_account.take(),
124                self.fingerprint.take(),
125                self.last4.take(),
126                self.networks.take(),
127                self.routing_number.take(),
128                self.status_details,
129            )
130            else {
131                return None;
132            };
133            Some(Self::Out {
134                account_holder_type,
135                account_type,
136                bank_name,
137                financial_connections_account,
138                fingerprint,
139                last4,
140                networks,
141                routing_number,
142                status_details,
143            })
144        }
145    }
146
147    impl<'a> Map for Builder<'a> {
148        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
149            self.builder.key(k)
150        }
151
152        fn finish(&mut self) -> Result<()> {
153            *self.out = self.builder.take_out();
154            Ok(())
155        }
156    }
157
158    impl ObjectDeser for PaymentMethodUsBankAccount {
159        type Builder = PaymentMethodUsBankAccountBuilder;
160    }
161
162    impl FromValueOpt for PaymentMethodUsBankAccount {
163        fn from_value(v: Value) -> Option<Self> {
164            let Value::Object(obj) = v else {
165                return None;
166            };
167            let mut b = PaymentMethodUsBankAccountBuilder::deser_default();
168            for (k, v) in obj {
169                match k.as_str() {
170                    "account_holder_type" => b.account_holder_type = FromValueOpt::from_value(v),
171                    "account_type" => b.account_type = FromValueOpt::from_value(v),
172                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
173                    "financial_connections_account" => {
174                        b.financial_connections_account = FromValueOpt::from_value(v)
175                    }
176                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
177                    "last4" => b.last4 = FromValueOpt::from_value(v),
178                    "networks" => b.networks = FromValueOpt::from_value(v),
179                    "routing_number" => b.routing_number = FromValueOpt::from_value(v),
180                    "status_details" => b.status_details = FromValueOpt::from_value(v),
181
182                    _ => {}
183                }
184            }
185            b.take_out()
186        }
187    }
188};
189/// Account holder type: individual or company.
190#[derive(Copy, Clone, Eq, PartialEq)]
191pub enum PaymentMethodUsBankAccountAccountHolderType {
192    Company,
193    Individual,
194}
195impl PaymentMethodUsBankAccountAccountHolderType {
196    pub fn as_str(self) -> &'static str {
197        use PaymentMethodUsBankAccountAccountHolderType::*;
198        match self {
199            Company => "company",
200            Individual => "individual",
201        }
202    }
203}
204
205impl std::str::FromStr for PaymentMethodUsBankAccountAccountHolderType {
206    type Err = stripe_types::StripeParseError;
207    fn from_str(s: &str) -> Result<Self, Self::Err> {
208        use PaymentMethodUsBankAccountAccountHolderType::*;
209        match s {
210            "company" => Ok(Company),
211            "individual" => Ok(Individual),
212            _ => Err(stripe_types::StripeParseError),
213        }
214    }
215}
216impl std::fmt::Display for PaymentMethodUsBankAccountAccountHolderType {
217    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
218        f.write_str(self.as_str())
219    }
220}
221
222impl std::fmt::Debug for PaymentMethodUsBankAccountAccountHolderType {
223    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
224        f.write_str(self.as_str())
225    }
226}
227#[cfg(feature = "serialize")]
228impl serde::Serialize for PaymentMethodUsBankAccountAccountHolderType {
229    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
230    where
231        S: serde::Serializer,
232    {
233        serializer.serialize_str(self.as_str())
234    }
235}
236impl miniserde::Deserialize for PaymentMethodUsBankAccountAccountHolderType {
237    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
238        crate::Place::new(out)
239    }
240}
241
242impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountAccountHolderType> {
243    fn string(&mut self, s: &str) -> miniserde::Result<()> {
244        use std::str::FromStr;
245        self.out = Some(
246            PaymentMethodUsBankAccountAccountHolderType::from_str(s)
247                .map_err(|_| miniserde::Error)?,
248        );
249        Ok(())
250    }
251}
252
253stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountAccountHolderType);
254#[cfg(feature = "deserialize")]
255impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountAccountHolderType {
256    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
257        use std::str::FromStr;
258        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
259        Self::from_str(&s).map_err(|_| {
260            serde::de::Error::custom(
261                "Unknown value for PaymentMethodUsBankAccountAccountHolderType",
262            )
263        })
264    }
265}
266/// Account type: checkings or savings. Defaults to checking if omitted.
267#[derive(Copy, Clone, Eq, PartialEq)]
268pub enum PaymentMethodUsBankAccountAccountType {
269    Checking,
270    Savings,
271}
272impl PaymentMethodUsBankAccountAccountType {
273    pub fn as_str(self) -> &'static str {
274        use PaymentMethodUsBankAccountAccountType::*;
275        match self {
276            Checking => "checking",
277            Savings => "savings",
278        }
279    }
280}
281
282impl std::str::FromStr for PaymentMethodUsBankAccountAccountType {
283    type Err = stripe_types::StripeParseError;
284    fn from_str(s: &str) -> Result<Self, Self::Err> {
285        use PaymentMethodUsBankAccountAccountType::*;
286        match s {
287            "checking" => Ok(Checking),
288            "savings" => Ok(Savings),
289            _ => Err(stripe_types::StripeParseError),
290        }
291    }
292}
293impl std::fmt::Display for PaymentMethodUsBankAccountAccountType {
294    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
295        f.write_str(self.as_str())
296    }
297}
298
299impl std::fmt::Debug for PaymentMethodUsBankAccountAccountType {
300    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
301        f.write_str(self.as_str())
302    }
303}
304#[cfg(feature = "serialize")]
305impl serde::Serialize for PaymentMethodUsBankAccountAccountType {
306    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
307    where
308        S: serde::Serializer,
309    {
310        serializer.serialize_str(self.as_str())
311    }
312}
313impl miniserde::Deserialize for PaymentMethodUsBankAccountAccountType {
314    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
315        crate::Place::new(out)
316    }
317}
318
319impl miniserde::de::Visitor for crate::Place<PaymentMethodUsBankAccountAccountType> {
320    fn string(&mut self, s: &str) -> miniserde::Result<()> {
321        use std::str::FromStr;
322        self.out =
323            Some(PaymentMethodUsBankAccountAccountType::from_str(s).map_err(|_| miniserde::Error)?);
324        Ok(())
325    }
326}
327
328stripe_types::impl_from_val_with_from_str!(PaymentMethodUsBankAccountAccountType);
329#[cfg(feature = "deserialize")]
330impl<'de> serde::Deserialize<'de> for PaymentMethodUsBankAccountAccountType {
331    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
332        use std::str::FromStr;
333        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
334        Self::from_str(&s).map_err(|_| {
335            serde::de::Error::custom("Unknown value for PaymentMethodUsBankAccountAccountType")
336        })
337    }
338}