Skip to main content

stripe_shared/
setup_intent_payment_method_options_acss_debit.rs

1#[derive(Clone, Eq, PartialEq)]
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 SetupIntentPaymentMethodOptionsAcssDebit {
6    /// Currency supported by the bank account
7    pub currency: Option<SetupIntentPaymentMethodOptionsAcssDebitCurrency>,
8    pub mandate_options:
9        Option<stripe_shared::SetupIntentPaymentMethodOptionsMandateOptionsAcssDebit>,
10    /// Bank account verification method. The default value is `automatic`.
11    pub verification_method: Option<SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod>,
12}
13#[cfg(feature = "redact-generated-debug")]
14impl std::fmt::Debug for SetupIntentPaymentMethodOptionsAcssDebit {
15    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16        f.debug_struct("SetupIntentPaymentMethodOptionsAcssDebit").finish_non_exhaustive()
17    }
18}
19#[doc(hidden)]
20pub struct SetupIntentPaymentMethodOptionsAcssDebitBuilder {
21    currency: Option<Option<SetupIntentPaymentMethodOptionsAcssDebitCurrency>>,
22    mandate_options:
23        Option<Option<stripe_shared::SetupIntentPaymentMethodOptionsMandateOptionsAcssDebit>>,
24    verification_method: Option<Option<SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod>>,
25}
26
27#[allow(
28    unused_variables,
29    irrefutable_let_patterns,
30    clippy::let_unit_value,
31    clippy::match_single_binding,
32    clippy::single_match
33)]
34const _: () = {
35    use miniserde::de::{Map, Visitor};
36    use miniserde::json::Value;
37    use miniserde::{Deserialize, Result, make_place};
38    use stripe_types::miniserde_helpers::FromValueOpt;
39    use stripe_types::{MapBuilder, ObjectDeser};
40
41    make_place!(Place);
42
43    impl Deserialize for SetupIntentPaymentMethodOptionsAcssDebit {
44        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
45            Place::new(out)
46        }
47    }
48
49    struct Builder<'a> {
50        out: &'a mut Option<SetupIntentPaymentMethodOptionsAcssDebit>,
51        builder: SetupIntentPaymentMethodOptionsAcssDebitBuilder,
52    }
53
54    impl Visitor for Place<SetupIntentPaymentMethodOptionsAcssDebit> {
55        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
56            Ok(Box::new(Builder {
57                out: &mut self.out,
58                builder: SetupIntentPaymentMethodOptionsAcssDebitBuilder::deser_default(),
59            }))
60        }
61    }
62
63    impl MapBuilder for SetupIntentPaymentMethodOptionsAcssDebitBuilder {
64        type Out = SetupIntentPaymentMethodOptionsAcssDebit;
65        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
66            Ok(match k {
67                "currency" => Deserialize::begin(&mut self.currency),
68                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
69                "verification_method" => Deserialize::begin(&mut self.verification_method),
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                currency: Deserialize::default(),
77                mandate_options: Deserialize::default(),
78                verification_method: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (Some(currency), Some(mandate_options), Some(verification_method)) = (
84                self.currency.take(),
85                self.mandate_options.take(),
86                self.verification_method.take(),
87            ) else {
88                return None;
89            };
90            Some(Self::Out { currency, mandate_options, verification_method })
91        }
92    }
93
94    impl Map for Builder<'_> {
95        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96            self.builder.key(k)
97        }
98
99        fn finish(&mut self) -> Result<()> {
100            *self.out = self.builder.take_out();
101            Ok(())
102        }
103    }
104
105    impl ObjectDeser for SetupIntentPaymentMethodOptionsAcssDebit {
106        type Builder = SetupIntentPaymentMethodOptionsAcssDebitBuilder;
107    }
108
109    impl FromValueOpt for SetupIntentPaymentMethodOptionsAcssDebit {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = SetupIntentPaymentMethodOptionsAcssDebitBuilder::deser_default();
115            for (k, v) in obj {
116                match k.as_str() {
117                    "currency" => b.currency = FromValueOpt::from_value(v),
118                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
119                    "verification_method" => b.verification_method = FromValueOpt::from_value(v),
120                    _ => {}
121                }
122            }
123            b.take_out()
124        }
125    }
126};
127/// Currency supported by the bank account
128#[derive(Clone, Eq, PartialEq)]
129#[non_exhaustive]
130pub enum SetupIntentPaymentMethodOptionsAcssDebitCurrency {
131    Cad,
132    Usd,
133    /// An unrecognized value from Stripe. Should not be used as a request parameter.
134    Unknown(String),
135}
136impl SetupIntentPaymentMethodOptionsAcssDebitCurrency {
137    pub fn as_str(&self) -> &str {
138        use SetupIntentPaymentMethodOptionsAcssDebitCurrency::*;
139        match self {
140            Cad => "cad",
141            Usd => "usd",
142            Unknown(v) => v,
143        }
144    }
145}
146
147impl std::str::FromStr for SetupIntentPaymentMethodOptionsAcssDebitCurrency {
148    type Err = std::convert::Infallible;
149    fn from_str(s: &str) -> Result<Self, Self::Err> {
150        use SetupIntentPaymentMethodOptionsAcssDebitCurrency::*;
151        match s {
152            "cad" => Ok(Cad),
153            "usd" => Ok(Usd),
154            v => {
155                tracing::warn!(
156                    "Unknown value '{}' for enum '{}'",
157                    v,
158                    "SetupIntentPaymentMethodOptionsAcssDebitCurrency"
159                );
160                Ok(Unknown(v.to_owned()))
161            }
162        }
163    }
164}
165impl std::fmt::Display for SetupIntentPaymentMethodOptionsAcssDebitCurrency {
166    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167        f.write_str(self.as_str())
168    }
169}
170
171#[cfg(not(feature = "redact-generated-debug"))]
172impl std::fmt::Debug for SetupIntentPaymentMethodOptionsAcssDebitCurrency {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177#[cfg(feature = "redact-generated-debug")]
178impl std::fmt::Debug for SetupIntentPaymentMethodOptionsAcssDebitCurrency {
179    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180        f.debug_struct(stringify!(SetupIntentPaymentMethodOptionsAcssDebitCurrency))
181            .finish_non_exhaustive()
182    }
183}
184#[cfg(feature = "serialize")]
185impl serde::Serialize for SetupIntentPaymentMethodOptionsAcssDebitCurrency {
186    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
187    where
188        S: serde::Serializer,
189    {
190        serializer.serialize_str(self.as_str())
191    }
192}
193impl miniserde::Deserialize for SetupIntentPaymentMethodOptionsAcssDebitCurrency {
194    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
195        crate::Place::new(out)
196    }
197}
198
199impl miniserde::de::Visitor for crate::Place<SetupIntentPaymentMethodOptionsAcssDebitCurrency> {
200    fn string(&mut self, s: &str) -> miniserde::Result<()> {
201        use std::str::FromStr;
202        self.out = Some(
203            SetupIntentPaymentMethodOptionsAcssDebitCurrency::from_str(s).expect("infallible"),
204        );
205        Ok(())
206    }
207}
208
209stripe_types::impl_from_val_with_from_str!(SetupIntentPaymentMethodOptionsAcssDebitCurrency);
210#[cfg(feature = "deserialize")]
211impl<'de> serde::Deserialize<'de> for SetupIntentPaymentMethodOptionsAcssDebitCurrency {
212    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
213        use std::str::FromStr;
214        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
215        Ok(Self::from_str(&s).expect("infallible"))
216    }
217}
218/// Bank account verification method. The default value is `automatic`.
219#[derive(Clone, Eq, PartialEq)]
220#[non_exhaustive]
221pub enum SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
222    Automatic,
223    Instant,
224    Microdeposits,
225    /// An unrecognized value from Stripe. Should not be used as a request parameter.
226    Unknown(String),
227}
228impl SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
229    pub fn as_str(&self) -> &str {
230        use SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod::*;
231        match self {
232            Automatic => "automatic",
233            Instant => "instant",
234            Microdeposits => "microdeposits",
235            Unknown(v) => v,
236        }
237    }
238}
239
240impl std::str::FromStr for SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
241    type Err = std::convert::Infallible;
242    fn from_str(s: &str) -> Result<Self, Self::Err> {
243        use SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod::*;
244        match s {
245            "automatic" => Ok(Automatic),
246            "instant" => Ok(Instant),
247            "microdeposits" => Ok(Microdeposits),
248            v => {
249                tracing::warn!(
250                    "Unknown value '{}' for enum '{}'",
251                    v,
252                    "SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod"
253                );
254                Ok(Unknown(v.to_owned()))
255            }
256        }
257    }
258}
259impl std::fmt::Display for SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
260    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
261        f.write_str(self.as_str())
262    }
263}
264
265#[cfg(not(feature = "redact-generated-debug"))]
266impl std::fmt::Debug for SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
267    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
268        f.write_str(self.as_str())
269    }
270}
271#[cfg(feature = "redact-generated-debug")]
272impl std::fmt::Debug for SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
273    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274        f.debug_struct(stringify!(SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod))
275            .finish_non_exhaustive()
276    }
277}
278#[cfg(feature = "serialize")]
279impl serde::Serialize for SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
280    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
281    where
282        S: serde::Serializer,
283    {
284        serializer.serialize_str(self.as_str())
285    }
286}
287impl miniserde::Deserialize for SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
288    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
289        crate::Place::new(out)
290    }
291}
292
293impl miniserde::de::Visitor
294    for crate::Place<SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod>
295{
296    fn string(&mut self, s: &str) -> miniserde::Result<()> {
297        use std::str::FromStr;
298        self.out = Some(
299            SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod::from_str(s)
300                .expect("infallible"),
301        );
302        Ok(())
303    }
304}
305
306stripe_types::impl_from_val_with_from_str!(
307    SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod
308);
309#[cfg(feature = "deserialize")]
310impl<'de> serde::Deserialize<'de> for SetupIntentPaymentMethodOptionsAcssDebitVerificationMethod {
311    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
312        use std::str::FromStr;
313        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
314        Ok(Self::from_str(&s).expect("infallible"))
315    }
316}