stripe_shared/
checkout_acss_debit_mandate_options.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CheckoutAcssDebitMandateOptions {
5    /// A URL for custom mandate text
6    pub custom_mandate_url: Option<String>,
7    /// List of Stripe products where this mandate can be selected automatically.
8    /// Returned when the Session is in `setup` mode.
9    pub default_for: Option<Vec<CheckoutAcssDebitMandateOptionsDefaultFor>>,
10    /// Description of the interval.
11    /// Only required if the 'payment_schedule' parameter is 'interval' or 'combined'.
12    pub interval_description: Option<String>,
13    /// Payment schedule for the mandate.
14    pub payment_schedule: Option<CheckoutAcssDebitMandateOptionsPaymentSchedule>,
15    /// Transaction type of the mandate.
16    pub transaction_type: Option<CheckoutAcssDebitMandateOptionsTransactionType>,
17}
18#[doc(hidden)]
19pub struct CheckoutAcssDebitMandateOptionsBuilder {
20    custom_mandate_url: Option<Option<String>>,
21    default_for: Option<Option<Vec<CheckoutAcssDebitMandateOptionsDefaultFor>>>,
22    interval_description: Option<Option<String>>,
23    payment_schedule: Option<Option<CheckoutAcssDebitMandateOptionsPaymentSchedule>>,
24    transaction_type: Option<Option<CheckoutAcssDebitMandateOptionsTransactionType>>,
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::{make_place, Deserialize, Result};
38    use stripe_types::miniserde_helpers::FromValueOpt;
39    use stripe_types::{MapBuilder, ObjectDeser};
40
41    make_place!(Place);
42
43    impl Deserialize for CheckoutAcssDebitMandateOptions {
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<CheckoutAcssDebitMandateOptions>,
51        builder: CheckoutAcssDebitMandateOptionsBuilder,
52    }
53
54    impl Visitor for Place<CheckoutAcssDebitMandateOptions> {
55        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
56            Ok(Box::new(Builder {
57                out: &mut self.out,
58                builder: CheckoutAcssDebitMandateOptionsBuilder::deser_default(),
59            }))
60        }
61    }
62
63    impl MapBuilder for CheckoutAcssDebitMandateOptionsBuilder {
64        type Out = CheckoutAcssDebitMandateOptions;
65        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
66            Ok(match k {
67                "custom_mandate_url" => Deserialize::begin(&mut self.custom_mandate_url),
68                "default_for" => Deserialize::begin(&mut self.default_for),
69                "interval_description" => Deserialize::begin(&mut self.interval_description),
70                "payment_schedule" => Deserialize::begin(&mut self.payment_schedule),
71                "transaction_type" => Deserialize::begin(&mut self.transaction_type),
72
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self {
79                custom_mandate_url: Deserialize::default(),
80                default_for: Deserialize::default(),
81                interval_description: Deserialize::default(),
82                payment_schedule: Deserialize::default(),
83                transaction_type: Deserialize::default(),
84            }
85        }
86
87        fn take_out(&mut self) -> Option<Self::Out> {
88            let (
89                Some(custom_mandate_url),
90                Some(default_for),
91                Some(interval_description),
92                Some(payment_schedule),
93                Some(transaction_type),
94            ) = (
95                self.custom_mandate_url.take(),
96                self.default_for.take(),
97                self.interval_description.take(),
98                self.payment_schedule,
99                self.transaction_type,
100            )
101            else {
102                return None;
103            };
104            Some(Self::Out {
105                custom_mandate_url,
106                default_for,
107                interval_description,
108                payment_schedule,
109                transaction_type,
110            })
111        }
112    }
113
114    impl Map for Builder<'_> {
115        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
116            self.builder.key(k)
117        }
118
119        fn finish(&mut self) -> Result<()> {
120            *self.out = self.builder.take_out();
121            Ok(())
122        }
123    }
124
125    impl ObjectDeser for CheckoutAcssDebitMandateOptions {
126        type Builder = CheckoutAcssDebitMandateOptionsBuilder;
127    }
128
129    impl FromValueOpt for CheckoutAcssDebitMandateOptions {
130        fn from_value(v: Value) -> Option<Self> {
131            let Value::Object(obj) = v else {
132                return None;
133            };
134            let mut b = CheckoutAcssDebitMandateOptionsBuilder::deser_default();
135            for (k, v) in obj {
136                match k.as_str() {
137                    "custom_mandate_url" => b.custom_mandate_url = FromValueOpt::from_value(v),
138                    "default_for" => b.default_for = FromValueOpt::from_value(v),
139                    "interval_description" => b.interval_description = FromValueOpt::from_value(v),
140                    "payment_schedule" => b.payment_schedule = FromValueOpt::from_value(v),
141                    "transaction_type" => b.transaction_type = FromValueOpt::from_value(v),
142
143                    _ => {}
144                }
145            }
146            b.take_out()
147        }
148    }
149};
150/// List of Stripe products where this mandate can be selected automatically.
151/// Returned when the Session is in `setup` mode.
152#[derive(Copy, Clone, Eq, PartialEq)]
153pub enum CheckoutAcssDebitMandateOptionsDefaultFor {
154    Invoice,
155    Subscription,
156}
157impl CheckoutAcssDebitMandateOptionsDefaultFor {
158    pub fn as_str(self) -> &'static str {
159        use CheckoutAcssDebitMandateOptionsDefaultFor::*;
160        match self {
161            Invoice => "invoice",
162            Subscription => "subscription",
163        }
164    }
165}
166
167impl std::str::FromStr for CheckoutAcssDebitMandateOptionsDefaultFor {
168    type Err = stripe_types::StripeParseError;
169    fn from_str(s: &str) -> Result<Self, Self::Err> {
170        use CheckoutAcssDebitMandateOptionsDefaultFor::*;
171        match s {
172            "invoice" => Ok(Invoice),
173            "subscription" => Ok(Subscription),
174            _ => Err(stripe_types::StripeParseError),
175        }
176    }
177}
178impl std::fmt::Display for CheckoutAcssDebitMandateOptionsDefaultFor {
179    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180        f.write_str(self.as_str())
181    }
182}
183
184impl std::fmt::Debug for CheckoutAcssDebitMandateOptionsDefaultFor {
185    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
186        f.write_str(self.as_str())
187    }
188}
189#[cfg(feature = "serialize")]
190impl serde::Serialize for CheckoutAcssDebitMandateOptionsDefaultFor {
191    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
192    where
193        S: serde::Serializer,
194    {
195        serializer.serialize_str(self.as_str())
196    }
197}
198impl miniserde::Deserialize for CheckoutAcssDebitMandateOptionsDefaultFor {
199    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
200        crate::Place::new(out)
201    }
202}
203
204impl miniserde::de::Visitor for crate::Place<CheckoutAcssDebitMandateOptionsDefaultFor> {
205    fn string(&mut self, s: &str) -> miniserde::Result<()> {
206        use std::str::FromStr;
207        self.out = Some(
208            CheckoutAcssDebitMandateOptionsDefaultFor::from_str(s).map_err(|_| miniserde::Error)?,
209        );
210        Ok(())
211    }
212}
213
214stripe_types::impl_from_val_with_from_str!(CheckoutAcssDebitMandateOptionsDefaultFor);
215#[cfg(feature = "deserialize")]
216impl<'de> serde::Deserialize<'de> for CheckoutAcssDebitMandateOptionsDefaultFor {
217    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
218        use std::str::FromStr;
219        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
220        Self::from_str(&s).map_err(|_| {
221            serde::de::Error::custom("Unknown value for CheckoutAcssDebitMandateOptionsDefaultFor")
222        })
223    }
224}
225/// Payment schedule for the mandate.
226#[derive(Copy, Clone, Eq, PartialEq)]
227pub enum CheckoutAcssDebitMandateOptionsPaymentSchedule {
228    Combined,
229    Interval,
230    Sporadic,
231}
232impl CheckoutAcssDebitMandateOptionsPaymentSchedule {
233    pub fn as_str(self) -> &'static str {
234        use CheckoutAcssDebitMandateOptionsPaymentSchedule::*;
235        match self {
236            Combined => "combined",
237            Interval => "interval",
238            Sporadic => "sporadic",
239        }
240    }
241}
242
243impl std::str::FromStr for CheckoutAcssDebitMandateOptionsPaymentSchedule {
244    type Err = stripe_types::StripeParseError;
245    fn from_str(s: &str) -> Result<Self, Self::Err> {
246        use CheckoutAcssDebitMandateOptionsPaymentSchedule::*;
247        match s {
248            "combined" => Ok(Combined),
249            "interval" => Ok(Interval),
250            "sporadic" => Ok(Sporadic),
251            _ => Err(stripe_types::StripeParseError),
252        }
253    }
254}
255impl std::fmt::Display for CheckoutAcssDebitMandateOptionsPaymentSchedule {
256    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
257        f.write_str(self.as_str())
258    }
259}
260
261impl std::fmt::Debug for CheckoutAcssDebitMandateOptionsPaymentSchedule {
262    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
263        f.write_str(self.as_str())
264    }
265}
266#[cfg(feature = "serialize")]
267impl serde::Serialize for CheckoutAcssDebitMandateOptionsPaymentSchedule {
268    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
269    where
270        S: serde::Serializer,
271    {
272        serializer.serialize_str(self.as_str())
273    }
274}
275impl miniserde::Deserialize for CheckoutAcssDebitMandateOptionsPaymentSchedule {
276    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
277        crate::Place::new(out)
278    }
279}
280
281impl miniserde::de::Visitor for crate::Place<CheckoutAcssDebitMandateOptionsPaymentSchedule> {
282    fn string(&mut self, s: &str) -> miniserde::Result<()> {
283        use std::str::FromStr;
284        self.out = Some(
285            CheckoutAcssDebitMandateOptionsPaymentSchedule::from_str(s)
286                .map_err(|_| miniserde::Error)?,
287        );
288        Ok(())
289    }
290}
291
292stripe_types::impl_from_val_with_from_str!(CheckoutAcssDebitMandateOptionsPaymentSchedule);
293#[cfg(feature = "deserialize")]
294impl<'de> serde::Deserialize<'de> for CheckoutAcssDebitMandateOptionsPaymentSchedule {
295    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
296        use std::str::FromStr;
297        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
298        Self::from_str(&s).map_err(|_| {
299            serde::de::Error::custom(
300                "Unknown value for CheckoutAcssDebitMandateOptionsPaymentSchedule",
301            )
302        })
303    }
304}
305/// Transaction type of the mandate.
306#[derive(Copy, Clone, Eq, PartialEq)]
307pub enum CheckoutAcssDebitMandateOptionsTransactionType {
308    Business,
309    Personal,
310}
311impl CheckoutAcssDebitMandateOptionsTransactionType {
312    pub fn as_str(self) -> &'static str {
313        use CheckoutAcssDebitMandateOptionsTransactionType::*;
314        match self {
315            Business => "business",
316            Personal => "personal",
317        }
318    }
319}
320
321impl std::str::FromStr for CheckoutAcssDebitMandateOptionsTransactionType {
322    type Err = stripe_types::StripeParseError;
323    fn from_str(s: &str) -> Result<Self, Self::Err> {
324        use CheckoutAcssDebitMandateOptionsTransactionType::*;
325        match s {
326            "business" => Ok(Business),
327            "personal" => Ok(Personal),
328            _ => Err(stripe_types::StripeParseError),
329        }
330    }
331}
332impl std::fmt::Display for CheckoutAcssDebitMandateOptionsTransactionType {
333    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
334        f.write_str(self.as_str())
335    }
336}
337
338impl std::fmt::Debug for CheckoutAcssDebitMandateOptionsTransactionType {
339    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
340        f.write_str(self.as_str())
341    }
342}
343#[cfg(feature = "serialize")]
344impl serde::Serialize for CheckoutAcssDebitMandateOptionsTransactionType {
345    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
346    where
347        S: serde::Serializer,
348    {
349        serializer.serialize_str(self.as_str())
350    }
351}
352impl miniserde::Deserialize for CheckoutAcssDebitMandateOptionsTransactionType {
353    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
354        crate::Place::new(out)
355    }
356}
357
358impl miniserde::de::Visitor for crate::Place<CheckoutAcssDebitMandateOptionsTransactionType> {
359    fn string(&mut self, s: &str) -> miniserde::Result<()> {
360        use std::str::FromStr;
361        self.out = Some(
362            CheckoutAcssDebitMandateOptionsTransactionType::from_str(s)
363                .map_err(|_| miniserde::Error)?,
364        );
365        Ok(())
366    }
367}
368
369stripe_types::impl_from_val_with_from_str!(CheckoutAcssDebitMandateOptionsTransactionType);
370#[cfg(feature = "deserialize")]
371impl<'de> serde::Deserialize<'de> for CheckoutAcssDebitMandateOptionsTransactionType {
372    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
373        use std::str::FromStr;
374        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
375        Self::from_str(&s).map_err(|_| {
376            serde::de::Error::custom(
377                "Unknown value for CheckoutAcssDebitMandateOptionsTransactionType",
378            )
379        })
380    }
381}