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