Skip to main content

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