stripe_shared/
setup_intent_payment_method_options_acss_debit.rs

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