stripe_shared/
invoice_payment_method_options_acss_debit.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoicePaymentMethodOptionsAcssDebit {
5    pub mandate_options: Option<stripe_shared::InvoicePaymentMethodOptionsAcssDebitMandateOptions>,
6    /// Bank account verification method.
7    pub verification_method: Option<InvoicePaymentMethodOptionsAcssDebitVerificationMethod>,
8}
9#[doc(hidden)]
10pub struct InvoicePaymentMethodOptionsAcssDebitBuilder {
11    mandate_options:
12        Option<Option<stripe_shared::InvoicePaymentMethodOptionsAcssDebitMandateOptions>>,
13    verification_method: Option<Option<InvoicePaymentMethodOptionsAcssDebitVerificationMethod>>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for InvoicePaymentMethodOptionsAcssDebit {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<InvoicePaymentMethodOptionsAcssDebit>,
40        builder: InvoicePaymentMethodOptionsAcssDebitBuilder,
41    }
42
43    impl Visitor for Place<InvoicePaymentMethodOptionsAcssDebit> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: InvoicePaymentMethodOptionsAcssDebitBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for InvoicePaymentMethodOptionsAcssDebitBuilder {
53        type Out = InvoicePaymentMethodOptionsAcssDebit;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
57                "verification_method" => Deserialize::begin(&mut self.verification_method),
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self {
64                mandate_options: Deserialize::default(),
65                verification_method: Deserialize::default(),
66            }
67        }
68
69        fn take_out(&mut self) -> Option<Self::Out> {
70            let (Some(mandate_options), Some(verification_method)) =
71                (self.mandate_options, self.verification_method)
72            else {
73                return None;
74            };
75            Some(Self::Out { mandate_options, verification_method })
76        }
77    }
78
79    impl Map for Builder<'_> {
80        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81            self.builder.key(k)
82        }
83
84        fn finish(&mut self) -> Result<()> {
85            *self.out = self.builder.take_out();
86            Ok(())
87        }
88    }
89
90    impl ObjectDeser for InvoicePaymentMethodOptionsAcssDebit {
91        type Builder = InvoicePaymentMethodOptionsAcssDebitBuilder;
92    }
93
94    impl FromValueOpt for InvoicePaymentMethodOptionsAcssDebit {
95        fn from_value(v: Value) -> Option<Self> {
96            let Value::Object(obj) = v else {
97                return None;
98            };
99            let mut b = InvoicePaymentMethodOptionsAcssDebitBuilder::deser_default();
100            for (k, v) in obj {
101                match k.as_str() {
102                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
103                    "verification_method" => b.verification_method = FromValueOpt::from_value(v),
104                    _ => {}
105                }
106            }
107            b.take_out()
108        }
109    }
110};
111/// Bank account verification method.
112#[derive(Copy, Clone, Eq, PartialEq)]
113pub enum InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
114    Automatic,
115    Instant,
116    Microdeposits,
117}
118impl InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
119    pub fn as_str(self) -> &'static str {
120        use InvoicePaymentMethodOptionsAcssDebitVerificationMethod::*;
121        match self {
122            Automatic => "automatic",
123            Instant => "instant",
124            Microdeposits => "microdeposits",
125        }
126    }
127}
128
129impl std::str::FromStr for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
130    type Err = stripe_types::StripeParseError;
131    fn from_str(s: &str) -> Result<Self, Self::Err> {
132        use InvoicePaymentMethodOptionsAcssDebitVerificationMethod::*;
133        match s {
134            "automatic" => Ok(Automatic),
135            "instant" => Ok(Instant),
136            "microdeposits" => Ok(Microdeposits),
137            _ => Err(stripe_types::StripeParseError),
138        }
139    }
140}
141impl std::fmt::Display for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
142    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
143        f.write_str(self.as_str())
144    }
145}
146
147impl std::fmt::Debug for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.write_str(self.as_str())
150    }
151}
152#[cfg(feature = "serialize")]
153impl serde::Serialize for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
154    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
155    where
156        S: serde::Serializer,
157    {
158        serializer.serialize_str(self.as_str())
159    }
160}
161impl miniserde::Deserialize for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
162    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
163        crate::Place::new(out)
164    }
165}
166
167impl miniserde::de::Visitor
168    for crate::Place<InvoicePaymentMethodOptionsAcssDebitVerificationMethod>
169{
170    fn string(&mut self, s: &str) -> miniserde::Result<()> {
171        use std::str::FromStr;
172        self.out = Some(
173            InvoicePaymentMethodOptionsAcssDebitVerificationMethod::from_str(s)
174                .map_err(|_| miniserde::Error)?,
175        );
176        Ok(())
177    }
178}
179
180stripe_types::impl_from_val_with_from_str!(InvoicePaymentMethodOptionsAcssDebitVerificationMethod);
181#[cfg(feature = "deserialize")]
182impl<'de> serde::Deserialize<'de> for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
183    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
184        use std::str::FromStr;
185        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
186        Self::from_str(&s).map_err(|_| {
187            serde::de::Error::custom(
188                "Unknown value for InvoicePaymentMethodOptionsAcssDebitVerificationMethod",
189            )
190        })
191    }
192}