Skip to main content

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