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