stripe_shared/
mandate_options_payto.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct MandateOptionsPayto {
5    /// Amount that will be collected. It is required when `amount_type` is `fixed`.
6    pub amount: Option<i64>,
7    /// The type of amount that will be collected.
8    /// The amount charged must be exact or up to the value of `amount` param for `fixed` or `maximum` type respectively.
9    /// Defaults to `maximum`.
10    pub amount_type: Option<MandateOptionsPaytoAmountType>,
11    /// Date, in YYYY-MM-DD format, after which payments will not be collected. Defaults to no end date.
12    pub end_date: Option<String>,
13    /// The periodicity at which payments will be collected. Defaults to `adhoc`.
14    pub payment_schedule: Option<MandateOptionsPaytoPaymentSchedule>,
15    /// The number of payments that will be made during a payment period.
16    /// Defaults to 1 except for when `payment_schedule` is `adhoc`.
17    /// In that case, it defaults to no limit.
18    pub payments_per_period: Option<i64>,
19    /// The purpose for which payments are made. Has a default value based on your merchant category code.
20    pub purpose: Option<MandateOptionsPaytoPurpose>,
21    /// Date, in YYYY-MM-DD format, from which payments will be collected. Defaults to confirmation time.
22    pub start_date: Option<String>,
23}
24#[doc(hidden)]
25pub struct MandateOptionsPaytoBuilder {
26    amount: Option<Option<i64>>,
27    amount_type: Option<Option<MandateOptionsPaytoAmountType>>,
28    end_date: Option<Option<String>>,
29    payment_schedule: Option<Option<MandateOptionsPaytoPaymentSchedule>>,
30    payments_per_period: Option<Option<i64>>,
31    purpose: Option<Option<MandateOptionsPaytoPurpose>>,
32    start_date: Option<Option<String>>,
33}
34
35#[allow(
36    unused_variables,
37    irrefutable_let_patterns,
38    clippy::let_unit_value,
39    clippy::match_single_binding,
40    clippy::single_match
41)]
42const _: () = {
43    use miniserde::de::{Map, Visitor};
44    use miniserde::json::Value;
45    use miniserde::{Deserialize, Result, make_place};
46    use stripe_types::miniserde_helpers::FromValueOpt;
47    use stripe_types::{MapBuilder, ObjectDeser};
48
49    make_place!(Place);
50
51    impl Deserialize for MandateOptionsPayto {
52        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
53            Place::new(out)
54        }
55    }
56
57    struct Builder<'a> {
58        out: &'a mut Option<MandateOptionsPayto>,
59        builder: MandateOptionsPaytoBuilder,
60    }
61
62    impl Visitor for Place<MandateOptionsPayto> {
63        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
64            Ok(Box::new(Builder {
65                out: &mut self.out,
66                builder: MandateOptionsPaytoBuilder::deser_default(),
67            }))
68        }
69    }
70
71    impl MapBuilder for MandateOptionsPaytoBuilder {
72        type Out = MandateOptionsPayto;
73        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
74            Ok(match k {
75                "amount" => Deserialize::begin(&mut self.amount),
76                "amount_type" => Deserialize::begin(&mut self.amount_type),
77                "end_date" => Deserialize::begin(&mut self.end_date),
78                "payment_schedule" => Deserialize::begin(&mut self.payment_schedule),
79                "payments_per_period" => Deserialize::begin(&mut self.payments_per_period),
80                "purpose" => Deserialize::begin(&mut self.purpose),
81                "start_date" => Deserialize::begin(&mut self.start_date),
82                _ => <dyn Visitor>::ignore(),
83            })
84        }
85
86        fn deser_default() -> Self {
87            Self {
88                amount: Deserialize::default(),
89                amount_type: Deserialize::default(),
90                end_date: Deserialize::default(),
91                payment_schedule: Deserialize::default(),
92                payments_per_period: Deserialize::default(),
93                purpose: Deserialize::default(),
94                start_date: Deserialize::default(),
95            }
96        }
97
98        fn take_out(&mut self) -> Option<Self::Out> {
99            let (
100                Some(amount),
101                Some(amount_type),
102                Some(end_date),
103                Some(payment_schedule),
104                Some(payments_per_period),
105                Some(purpose),
106                Some(start_date),
107            ) = (
108                self.amount,
109                self.amount_type.take(),
110                self.end_date.take(),
111                self.payment_schedule.take(),
112                self.payments_per_period,
113                self.purpose.take(),
114                self.start_date.take(),
115            )
116            else {
117                return None;
118            };
119            Some(Self::Out {
120                amount,
121                amount_type,
122                end_date,
123                payment_schedule,
124                payments_per_period,
125                purpose,
126                start_date,
127            })
128        }
129    }
130
131    impl Map for Builder<'_> {
132        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
133            self.builder.key(k)
134        }
135
136        fn finish(&mut self) -> Result<()> {
137            *self.out = self.builder.take_out();
138            Ok(())
139        }
140    }
141
142    impl ObjectDeser for MandateOptionsPayto {
143        type Builder = MandateOptionsPaytoBuilder;
144    }
145
146    impl FromValueOpt for MandateOptionsPayto {
147        fn from_value(v: Value) -> Option<Self> {
148            let Value::Object(obj) = v else {
149                return None;
150            };
151            let mut b = MandateOptionsPaytoBuilder::deser_default();
152            for (k, v) in obj {
153                match k.as_str() {
154                    "amount" => b.amount = FromValueOpt::from_value(v),
155                    "amount_type" => b.amount_type = FromValueOpt::from_value(v),
156                    "end_date" => b.end_date = FromValueOpt::from_value(v),
157                    "payment_schedule" => b.payment_schedule = FromValueOpt::from_value(v),
158                    "payments_per_period" => b.payments_per_period = FromValueOpt::from_value(v),
159                    "purpose" => b.purpose = FromValueOpt::from_value(v),
160                    "start_date" => b.start_date = FromValueOpt::from_value(v),
161                    _ => {}
162                }
163            }
164            b.take_out()
165        }
166    }
167};
168/// The type of amount that will be collected.
169/// The amount charged must be exact or up to the value of `amount` param for `fixed` or `maximum` type respectively.
170/// Defaults to `maximum`.
171#[derive(Clone, Eq, PartialEq)]
172#[non_exhaustive]
173pub enum MandateOptionsPaytoAmountType {
174    Fixed,
175    Maximum,
176    /// An unrecognized value from Stripe. Should not be used as a request parameter.
177    Unknown(String),
178}
179impl MandateOptionsPaytoAmountType {
180    pub fn as_str(&self) -> &str {
181        use MandateOptionsPaytoAmountType::*;
182        match self {
183            Fixed => "fixed",
184            Maximum => "maximum",
185            Unknown(v) => v,
186        }
187    }
188}
189
190impl std::str::FromStr for MandateOptionsPaytoAmountType {
191    type Err = std::convert::Infallible;
192    fn from_str(s: &str) -> Result<Self, Self::Err> {
193        use MandateOptionsPaytoAmountType::*;
194        match s {
195            "fixed" => Ok(Fixed),
196            "maximum" => Ok(Maximum),
197            v => {
198                tracing::warn!(
199                    "Unknown value '{}' for enum '{}'",
200                    v,
201                    "MandateOptionsPaytoAmountType"
202                );
203                Ok(Unknown(v.to_owned()))
204            }
205        }
206    }
207}
208impl std::fmt::Display for MandateOptionsPaytoAmountType {
209    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
210        f.write_str(self.as_str())
211    }
212}
213
214impl std::fmt::Debug for MandateOptionsPaytoAmountType {
215    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
216        f.write_str(self.as_str())
217    }
218}
219#[cfg(feature = "serialize")]
220impl serde::Serialize for MandateOptionsPaytoAmountType {
221    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
222    where
223        S: serde::Serializer,
224    {
225        serializer.serialize_str(self.as_str())
226    }
227}
228impl miniserde::Deserialize for MandateOptionsPaytoAmountType {
229    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
230        crate::Place::new(out)
231    }
232}
233
234impl miniserde::de::Visitor for crate::Place<MandateOptionsPaytoAmountType> {
235    fn string(&mut self, s: &str) -> miniserde::Result<()> {
236        use std::str::FromStr;
237        self.out = Some(MandateOptionsPaytoAmountType::from_str(s).expect("infallible"));
238        Ok(())
239    }
240}
241
242stripe_types::impl_from_val_with_from_str!(MandateOptionsPaytoAmountType);
243#[cfg(feature = "deserialize")]
244impl<'de> serde::Deserialize<'de> for MandateOptionsPaytoAmountType {
245    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
246        use std::str::FromStr;
247        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
248        Ok(Self::from_str(&s).expect("infallible"))
249    }
250}
251/// The periodicity at which payments will be collected. Defaults to `adhoc`.
252#[derive(Clone, Eq, PartialEq)]
253#[non_exhaustive]
254pub enum MandateOptionsPaytoPaymentSchedule {
255    Adhoc,
256    Annual,
257    Daily,
258    Fortnightly,
259    Monthly,
260    Quarterly,
261    SemiAnnual,
262    Weekly,
263    /// An unrecognized value from Stripe. Should not be used as a request parameter.
264    Unknown(String),
265}
266impl MandateOptionsPaytoPaymentSchedule {
267    pub fn as_str(&self) -> &str {
268        use MandateOptionsPaytoPaymentSchedule::*;
269        match self {
270            Adhoc => "adhoc",
271            Annual => "annual",
272            Daily => "daily",
273            Fortnightly => "fortnightly",
274            Monthly => "monthly",
275            Quarterly => "quarterly",
276            SemiAnnual => "semi_annual",
277            Weekly => "weekly",
278            Unknown(v) => v,
279        }
280    }
281}
282
283impl std::str::FromStr for MandateOptionsPaytoPaymentSchedule {
284    type Err = std::convert::Infallible;
285    fn from_str(s: &str) -> Result<Self, Self::Err> {
286        use MandateOptionsPaytoPaymentSchedule::*;
287        match s {
288            "adhoc" => Ok(Adhoc),
289            "annual" => Ok(Annual),
290            "daily" => Ok(Daily),
291            "fortnightly" => Ok(Fortnightly),
292            "monthly" => Ok(Monthly),
293            "quarterly" => Ok(Quarterly),
294            "semi_annual" => Ok(SemiAnnual),
295            "weekly" => Ok(Weekly),
296            v => {
297                tracing::warn!(
298                    "Unknown value '{}' for enum '{}'",
299                    v,
300                    "MandateOptionsPaytoPaymentSchedule"
301                );
302                Ok(Unknown(v.to_owned()))
303            }
304        }
305    }
306}
307impl std::fmt::Display for MandateOptionsPaytoPaymentSchedule {
308    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
309        f.write_str(self.as_str())
310    }
311}
312
313impl std::fmt::Debug for MandateOptionsPaytoPaymentSchedule {
314    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
315        f.write_str(self.as_str())
316    }
317}
318#[cfg(feature = "serialize")]
319impl serde::Serialize for MandateOptionsPaytoPaymentSchedule {
320    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
321    where
322        S: serde::Serializer,
323    {
324        serializer.serialize_str(self.as_str())
325    }
326}
327impl miniserde::Deserialize for MandateOptionsPaytoPaymentSchedule {
328    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
329        crate::Place::new(out)
330    }
331}
332
333impl miniserde::de::Visitor for crate::Place<MandateOptionsPaytoPaymentSchedule> {
334    fn string(&mut self, s: &str) -> miniserde::Result<()> {
335        use std::str::FromStr;
336        self.out = Some(MandateOptionsPaytoPaymentSchedule::from_str(s).expect("infallible"));
337        Ok(())
338    }
339}
340
341stripe_types::impl_from_val_with_from_str!(MandateOptionsPaytoPaymentSchedule);
342#[cfg(feature = "deserialize")]
343impl<'de> serde::Deserialize<'de> for MandateOptionsPaytoPaymentSchedule {
344    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
345        use std::str::FromStr;
346        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
347        Ok(Self::from_str(&s).expect("infallible"))
348    }
349}
350/// The purpose for which payments are made. Has a default value based on your merchant category code.
351#[derive(Clone, Eq, PartialEq)]
352#[non_exhaustive]
353pub enum MandateOptionsPaytoPurpose {
354    DependantSupport,
355    Government,
356    Loan,
357    Mortgage,
358    Other,
359    Pension,
360    Personal,
361    Retail,
362    Salary,
363    Tax,
364    Utility,
365    /// An unrecognized value from Stripe. Should not be used as a request parameter.
366    Unknown(String),
367}
368impl MandateOptionsPaytoPurpose {
369    pub fn as_str(&self) -> &str {
370        use MandateOptionsPaytoPurpose::*;
371        match self {
372            DependantSupport => "dependant_support",
373            Government => "government",
374            Loan => "loan",
375            Mortgage => "mortgage",
376            Other => "other",
377            Pension => "pension",
378            Personal => "personal",
379            Retail => "retail",
380            Salary => "salary",
381            Tax => "tax",
382            Utility => "utility",
383            Unknown(v) => v,
384        }
385    }
386}
387
388impl std::str::FromStr for MandateOptionsPaytoPurpose {
389    type Err = std::convert::Infallible;
390    fn from_str(s: &str) -> Result<Self, Self::Err> {
391        use MandateOptionsPaytoPurpose::*;
392        match s {
393            "dependant_support" => Ok(DependantSupport),
394            "government" => Ok(Government),
395            "loan" => Ok(Loan),
396            "mortgage" => Ok(Mortgage),
397            "other" => Ok(Other),
398            "pension" => Ok(Pension),
399            "personal" => Ok(Personal),
400            "retail" => Ok(Retail),
401            "salary" => Ok(Salary),
402            "tax" => Ok(Tax),
403            "utility" => Ok(Utility),
404            v => {
405                tracing::warn!("Unknown value '{}' for enum '{}'", v, "MandateOptionsPaytoPurpose");
406                Ok(Unknown(v.to_owned()))
407            }
408        }
409    }
410}
411impl std::fmt::Display for MandateOptionsPaytoPurpose {
412    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
413        f.write_str(self.as_str())
414    }
415}
416
417impl std::fmt::Debug for MandateOptionsPaytoPurpose {
418    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
419        f.write_str(self.as_str())
420    }
421}
422#[cfg(feature = "serialize")]
423impl serde::Serialize for MandateOptionsPaytoPurpose {
424    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
425    where
426        S: serde::Serializer,
427    {
428        serializer.serialize_str(self.as_str())
429    }
430}
431impl miniserde::Deserialize for MandateOptionsPaytoPurpose {
432    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
433        crate::Place::new(out)
434    }
435}
436
437impl miniserde::de::Visitor for crate::Place<MandateOptionsPaytoPurpose> {
438    fn string(&mut self, s: &str) -> miniserde::Result<()> {
439        use std::str::FromStr;
440        self.out = Some(MandateOptionsPaytoPurpose::from_str(s).expect("infallible"));
441        Ok(())
442    }
443}
444
445stripe_types::impl_from_val_with_from_str!(MandateOptionsPaytoPurpose);
446#[cfg(feature = "deserialize")]
447impl<'de> serde::Deserialize<'de> for MandateOptionsPaytoPurpose {
448    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
449        use std::str::FromStr;
450        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
451        Ok(Self::from_str(&s).expect("infallible"))
452    }
453}