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::{Deserialize, Result, make_place};
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                _ => <dyn Visitor>::ignore(),
76            })
77        }
78
79        fn deser_default() -> Self {
80            Self {
81                account_holder_type: Deserialize::default(),
82                bank_name: Deserialize::default(),
83                country: Deserialize::default(),
84                fingerprint: Deserialize::default(),
85                last4: Deserialize::default(),
86                routing_number: Deserialize::default(),
87            }
88        }
89
90        fn take_out(&mut self) -> Option<Self::Out> {
91            let (
92                Some(account_holder_type),
93                Some(bank_name),
94                Some(country),
95                Some(fingerprint),
96                Some(last4),
97                Some(routing_number),
98            ) = (
99                self.account_holder_type,
100                self.bank_name.take(),
101                self.country.take(),
102                self.fingerprint.take(),
103                self.last4.take(),
104                self.routing_number.take(),
105            )
106            else {
107                return None;
108            };
109            Some(Self::Out {
110                account_holder_type,
111                bank_name,
112                country,
113                fingerprint,
114                last4,
115                routing_number,
116            })
117        }
118    }
119
120    impl Map for Builder<'_> {
121        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
122            self.builder.key(k)
123        }
124
125        fn finish(&mut self) -> Result<()> {
126            *self.out = self.builder.take_out();
127            Ok(())
128        }
129    }
130
131    impl ObjectDeser for PaymentMethodDetailsAchDebit {
132        type Builder = PaymentMethodDetailsAchDebitBuilder;
133    }
134
135    impl FromValueOpt for PaymentMethodDetailsAchDebit {
136        fn from_value(v: Value) -> Option<Self> {
137            let Value::Object(obj) = v else {
138                return None;
139            };
140            let mut b = PaymentMethodDetailsAchDebitBuilder::deser_default();
141            for (k, v) in obj {
142                match k.as_str() {
143                    "account_holder_type" => b.account_holder_type = FromValueOpt::from_value(v),
144                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
145                    "country" => b.country = FromValueOpt::from_value(v),
146                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
147                    "last4" => b.last4 = FromValueOpt::from_value(v),
148                    "routing_number" => b.routing_number = FromValueOpt::from_value(v),
149                    _ => {}
150                }
151            }
152            b.take_out()
153        }
154    }
155};
156/// Type of entity that holds the account. This can be either `individual` or `company`.
157#[derive(Copy, Clone, Eq, PartialEq)]
158pub enum PaymentMethodDetailsAchDebitAccountHolderType {
159    Company,
160    Individual,
161}
162impl PaymentMethodDetailsAchDebitAccountHolderType {
163    pub fn as_str(self) -> &'static str {
164        use PaymentMethodDetailsAchDebitAccountHolderType::*;
165        match self {
166            Company => "company",
167            Individual => "individual",
168        }
169    }
170}
171
172impl std::str::FromStr for PaymentMethodDetailsAchDebitAccountHolderType {
173    type Err = stripe_types::StripeParseError;
174    fn from_str(s: &str) -> Result<Self, Self::Err> {
175        use PaymentMethodDetailsAchDebitAccountHolderType::*;
176        match s {
177            "company" => Ok(Company),
178            "individual" => Ok(Individual),
179            _ => Err(stripe_types::StripeParseError),
180        }
181    }
182}
183impl std::fmt::Display for PaymentMethodDetailsAchDebitAccountHolderType {
184    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185        f.write_str(self.as_str())
186    }
187}
188
189impl std::fmt::Debug for PaymentMethodDetailsAchDebitAccountHolderType {
190    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
191        f.write_str(self.as_str())
192    }
193}
194#[cfg(feature = "serialize")]
195impl serde::Serialize for PaymentMethodDetailsAchDebitAccountHolderType {
196    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
197    where
198        S: serde::Serializer,
199    {
200        serializer.serialize_str(self.as_str())
201    }
202}
203impl miniserde::Deserialize for PaymentMethodDetailsAchDebitAccountHolderType {
204    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
205        crate::Place::new(out)
206    }
207}
208
209impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsAchDebitAccountHolderType> {
210    fn string(&mut self, s: &str) -> miniserde::Result<()> {
211        use std::str::FromStr;
212        self.out = Some(
213            PaymentMethodDetailsAchDebitAccountHolderType::from_str(s)
214                .map_err(|_| miniserde::Error)?,
215        );
216        Ok(())
217    }
218}
219
220stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsAchDebitAccountHolderType);
221#[cfg(feature = "deserialize")]
222impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsAchDebitAccountHolderType {
223    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
224        use std::str::FromStr;
225        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
226        Self::from_str(&s).map_err(|_| {
227            serde::de::Error::custom(
228                "Unknown value for PaymentMethodDetailsAchDebitAccountHolderType",
229            )
230        })
231    }
232}