stripe_shared/
payment_method_details_ach_debit.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodDetailsAchDebit {
5    /// Type of entity that holds the account. This can be either `individual` or `company`.
6    pub account_holder_type: Option<PaymentMethodDetailsAchDebitAccountHolderType>,
7    /// Name of the bank associated with the bank account.
8    pub bank_name: Option<String>,
9    /// Two-letter ISO code representing the country the bank account is located in.
10    pub country: 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    /// Routing transit number of the bank account.
17    pub routing_number: Option<String>,
18}
19#[doc(hidden)]
20pub struct PaymentMethodDetailsAchDebitBuilder {
21    account_holder_type: Option<Option<PaymentMethodDetailsAchDebitAccountHolderType>>,
22    bank_name: Option<Option<String>>,
23    country: Option<Option<String>>,
24    fingerprint: Option<Option<String>>,
25    last4: Option<Option<String>>,
26    routing_number: Option<Option<String>>,
27}
28
29#[allow(
30    unused_variables,
31    irrefutable_let_patterns,
32    clippy::let_unit_value,
33    clippy::match_single_binding,
34    clippy::single_match
35)]
36const _: () = {
37    use miniserde::de::{Map, Visitor};
38    use miniserde::json::Value;
39    use miniserde::{make_place, Deserialize, Result};
40    use stripe_types::miniserde_helpers::FromValueOpt;
41    use stripe_types::{MapBuilder, ObjectDeser};
42
43    make_place!(Place);
44
45    impl Deserialize for PaymentMethodDetailsAchDebit {
46        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
47            Place::new(out)
48        }
49    }
50
51    struct Builder<'a> {
52        out: &'a mut Option<PaymentMethodDetailsAchDebit>,
53        builder: PaymentMethodDetailsAchDebitBuilder,
54    }
55
56    impl Visitor for Place<PaymentMethodDetailsAchDebit> {
57        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58            Ok(Box::new(Builder {
59                out: &mut self.out,
60                builder: PaymentMethodDetailsAchDebitBuilder::deser_default(),
61            }))
62        }
63    }
64
65    impl MapBuilder for PaymentMethodDetailsAchDebitBuilder {
66        type Out = PaymentMethodDetailsAchDebit;
67        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
68            Ok(match k {
69                "account_holder_type" => Deserialize::begin(&mut self.account_holder_type),
70                "bank_name" => Deserialize::begin(&mut self.bank_name),
71                "country" => Deserialize::begin(&mut self.country),
72                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
73                "last4" => Deserialize::begin(&mut self.last4),
74                "routing_number" => Deserialize::begin(&mut self.routing_number),
75
76                _ => <dyn Visitor>::ignore(),
77            })
78        }
79
80        fn deser_default() -> Self {
81            Self {
82                account_holder_type: Deserialize::default(),
83                bank_name: Deserialize::default(),
84                country: Deserialize::default(),
85                fingerprint: Deserialize::default(),
86                last4: Deserialize::default(),
87                routing_number: Deserialize::default(),
88            }
89        }
90
91        fn take_out(&mut self) -> Option<Self::Out> {
92            let (
93                Some(account_holder_type),
94                Some(bank_name),
95                Some(country),
96                Some(fingerprint),
97                Some(last4),
98                Some(routing_number),
99            ) = (
100                self.account_holder_type,
101                self.bank_name.take(),
102                self.country.take(),
103                self.fingerprint.take(),
104                self.last4.take(),
105                self.routing_number.take(),
106            )
107            else {
108                return None;
109            };
110            Some(Self::Out {
111                account_holder_type,
112                bank_name,
113                country,
114                fingerprint,
115                last4,
116                routing_number,
117            })
118        }
119    }
120
121    impl<'a> Map for Builder<'a> {
122        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
123            self.builder.key(k)
124        }
125
126        fn finish(&mut self) -> Result<()> {
127            *self.out = self.builder.take_out();
128            Ok(())
129        }
130    }
131
132    impl ObjectDeser for PaymentMethodDetailsAchDebit {
133        type Builder = PaymentMethodDetailsAchDebitBuilder;
134    }
135
136    impl FromValueOpt for PaymentMethodDetailsAchDebit {
137        fn from_value(v: Value) -> Option<Self> {
138            let Value::Object(obj) = v else {
139                return None;
140            };
141            let mut b = PaymentMethodDetailsAchDebitBuilder::deser_default();
142            for (k, v) in obj {
143                match k.as_str() {
144                    "account_holder_type" => b.account_holder_type = FromValueOpt::from_value(v),
145                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
146                    "country" => b.country = FromValueOpt::from_value(v),
147                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
148                    "last4" => b.last4 = FromValueOpt::from_value(v),
149                    "routing_number" => b.routing_number = FromValueOpt::from_value(v),
150
151                    _ => {}
152                }
153            }
154            b.take_out()
155        }
156    }
157};
158/// Type of entity that holds the account. This can be either `individual` or `company`.
159#[derive(Copy, Clone, Eq, PartialEq)]
160pub enum PaymentMethodDetailsAchDebitAccountHolderType {
161    Company,
162    Individual,
163}
164impl PaymentMethodDetailsAchDebitAccountHolderType {
165    pub fn as_str(self) -> &'static str {
166        use PaymentMethodDetailsAchDebitAccountHolderType::*;
167        match self {
168            Company => "company",
169            Individual => "individual",
170        }
171    }
172}
173
174impl std::str::FromStr for PaymentMethodDetailsAchDebitAccountHolderType {
175    type Err = stripe_types::StripeParseError;
176    fn from_str(s: &str) -> Result<Self, Self::Err> {
177        use PaymentMethodDetailsAchDebitAccountHolderType::*;
178        match s {
179            "company" => Ok(Company),
180            "individual" => Ok(Individual),
181            _ => Err(stripe_types::StripeParseError),
182        }
183    }
184}
185impl std::fmt::Display for PaymentMethodDetailsAchDebitAccountHolderType {
186    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
187        f.write_str(self.as_str())
188    }
189}
190
191impl std::fmt::Debug for PaymentMethodDetailsAchDebitAccountHolderType {
192    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
193        f.write_str(self.as_str())
194    }
195}
196#[cfg(feature = "serialize")]
197impl serde::Serialize for PaymentMethodDetailsAchDebitAccountHolderType {
198    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
199    where
200        S: serde::Serializer,
201    {
202        serializer.serialize_str(self.as_str())
203    }
204}
205impl miniserde::Deserialize for PaymentMethodDetailsAchDebitAccountHolderType {
206    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
207        crate::Place::new(out)
208    }
209}
210
211impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsAchDebitAccountHolderType> {
212    fn string(&mut self, s: &str) -> miniserde::Result<()> {
213        use std::str::FromStr;
214        self.out = Some(
215            PaymentMethodDetailsAchDebitAccountHolderType::from_str(s)
216                .map_err(|_| miniserde::Error)?,
217        );
218        Ok(())
219    }
220}
221
222stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsAchDebitAccountHolderType);
223#[cfg(feature = "deserialize")]
224impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsAchDebitAccountHolderType {
225    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
226        use std::str::FromStr;
227        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
228        Self::from_str(&s).map_err(|_| {
229            serde::de::Error::custom(
230                "Unknown value for PaymentMethodDetailsAchDebitAccountHolderType",
231            )
232        })
233    }
234}