stripe_shared/
mandate_acss_debit.rs

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