stripe_shared/
payment_method_options_card_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 PaymentMethodOptionsCardMandateOptions {
5    /// Amount to be charged for future payments.
6    pub amount: i64,
7    /// One of `fixed` or `maximum`.
8    /// If `fixed`, the `amount` param refers to the exact amount to be charged in future payments.
9    /// If `maximum`, the amount charged can be up to the value passed for the `amount` param.
10    pub amount_type: PaymentMethodOptionsCardMandateOptionsAmountType,
11    /// A description of the mandate or subscription that is meant to be displayed to the customer.
12    pub description: Option<String>,
13    /// End date of the mandate or subscription.
14    /// If not provided, the mandate will be active until canceled.
15    /// If provided, end date should be after start date.
16    pub end_date: Option<stripe_types::Timestamp>,
17    /// Specifies payment frequency. One of `day`, `week`, `month`, `year`, or `sporadic`.
18    pub interval: PaymentMethodOptionsCardMandateOptionsInterval,
19    /// The number of intervals between payments.
20    /// For example, `interval=month` and `interval_count=3` indicates one payment every three months.
21    /// Maximum of one year interval allowed (1 year, 12 months, or 52 weeks).
22    /// This parameter is optional when `interval=sporadic`.
23    pub interval_count: Option<u64>,
24    /// Unique identifier for the mandate or subscription.
25    pub reference: String,
26    /// Start date of the mandate or subscription. Start date should not be lesser than yesterday.
27    pub start_date: stripe_types::Timestamp,
28    /// Specifies the type of mandates supported. Possible values are `india`.
29    pub supported_types: Option<Vec<PaymentMethodOptionsCardMandateOptionsSupportedTypes>>,
30}
31#[doc(hidden)]
32pub struct PaymentMethodOptionsCardMandateOptionsBuilder {
33    amount: Option<i64>,
34    amount_type: Option<PaymentMethodOptionsCardMandateOptionsAmountType>,
35    description: Option<Option<String>>,
36    end_date: Option<Option<stripe_types::Timestamp>>,
37    interval: Option<PaymentMethodOptionsCardMandateOptionsInterval>,
38    interval_count: Option<Option<u64>>,
39    reference: Option<String>,
40    start_date: Option<stripe_types::Timestamp>,
41    supported_types: Option<Option<Vec<PaymentMethodOptionsCardMandateOptionsSupportedTypes>>>,
42}
43
44#[allow(
45    unused_variables,
46    irrefutable_let_patterns,
47    clippy::let_unit_value,
48    clippy::match_single_binding,
49    clippy::single_match
50)]
51const _: () = {
52    use miniserde::de::{Map, Visitor};
53    use miniserde::json::Value;
54    use miniserde::{Deserialize, Result, make_place};
55    use stripe_types::miniserde_helpers::FromValueOpt;
56    use stripe_types::{MapBuilder, ObjectDeser};
57
58    make_place!(Place);
59
60    impl Deserialize for PaymentMethodOptionsCardMandateOptions {
61        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
62            Place::new(out)
63        }
64    }
65
66    struct Builder<'a> {
67        out: &'a mut Option<PaymentMethodOptionsCardMandateOptions>,
68        builder: PaymentMethodOptionsCardMandateOptionsBuilder,
69    }
70
71    impl Visitor for Place<PaymentMethodOptionsCardMandateOptions> {
72        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
73            Ok(Box::new(Builder {
74                out: &mut self.out,
75                builder: PaymentMethodOptionsCardMandateOptionsBuilder::deser_default(),
76            }))
77        }
78    }
79
80    impl MapBuilder for PaymentMethodOptionsCardMandateOptionsBuilder {
81        type Out = PaymentMethodOptionsCardMandateOptions;
82        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
83            Ok(match k {
84                "amount" => Deserialize::begin(&mut self.amount),
85                "amount_type" => Deserialize::begin(&mut self.amount_type),
86                "description" => Deserialize::begin(&mut self.description),
87                "end_date" => Deserialize::begin(&mut self.end_date),
88                "interval" => Deserialize::begin(&mut self.interval),
89                "interval_count" => Deserialize::begin(&mut self.interval_count),
90                "reference" => Deserialize::begin(&mut self.reference),
91                "start_date" => Deserialize::begin(&mut self.start_date),
92                "supported_types" => Deserialize::begin(&mut self.supported_types),
93                _ => <dyn Visitor>::ignore(),
94            })
95        }
96
97        fn deser_default() -> Self {
98            Self {
99                amount: Deserialize::default(),
100                amount_type: Deserialize::default(),
101                description: Deserialize::default(),
102                end_date: Deserialize::default(),
103                interval: Deserialize::default(),
104                interval_count: Deserialize::default(),
105                reference: Deserialize::default(),
106                start_date: Deserialize::default(),
107                supported_types: Deserialize::default(),
108            }
109        }
110
111        fn take_out(&mut self) -> Option<Self::Out> {
112            let (
113                Some(amount),
114                Some(amount_type),
115                Some(description),
116                Some(end_date),
117                Some(interval),
118                Some(interval_count),
119                Some(reference),
120                Some(start_date),
121                Some(supported_types),
122            ) = (
123                self.amount,
124                self.amount_type.take(),
125                self.description.take(),
126                self.end_date,
127                self.interval.take(),
128                self.interval_count,
129                self.reference.take(),
130                self.start_date,
131                self.supported_types.take(),
132            )
133            else {
134                return None;
135            };
136            Some(Self::Out {
137                amount,
138                amount_type,
139                description,
140                end_date,
141                interval,
142                interval_count,
143                reference,
144                start_date,
145                supported_types,
146            })
147        }
148    }
149
150    impl Map for Builder<'_> {
151        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
152            self.builder.key(k)
153        }
154
155        fn finish(&mut self) -> Result<()> {
156            *self.out = self.builder.take_out();
157            Ok(())
158        }
159    }
160
161    impl ObjectDeser for PaymentMethodOptionsCardMandateOptions {
162        type Builder = PaymentMethodOptionsCardMandateOptionsBuilder;
163    }
164
165    impl FromValueOpt for PaymentMethodOptionsCardMandateOptions {
166        fn from_value(v: Value) -> Option<Self> {
167            let Value::Object(obj) = v else {
168                return None;
169            };
170            let mut b = PaymentMethodOptionsCardMandateOptionsBuilder::deser_default();
171            for (k, v) in obj {
172                match k.as_str() {
173                    "amount" => b.amount = FromValueOpt::from_value(v),
174                    "amount_type" => b.amount_type = FromValueOpt::from_value(v),
175                    "description" => b.description = FromValueOpt::from_value(v),
176                    "end_date" => b.end_date = FromValueOpt::from_value(v),
177                    "interval" => b.interval = FromValueOpt::from_value(v),
178                    "interval_count" => b.interval_count = FromValueOpt::from_value(v),
179                    "reference" => b.reference = FromValueOpt::from_value(v),
180                    "start_date" => b.start_date = FromValueOpt::from_value(v),
181                    "supported_types" => b.supported_types = FromValueOpt::from_value(v),
182                    _ => {}
183                }
184            }
185            b.take_out()
186        }
187    }
188};
189/// One of `fixed` or `maximum`.
190/// If `fixed`, the `amount` param refers to the exact amount to be charged in future payments.
191/// If `maximum`, the amount charged can be up to the value passed for the `amount` param.
192#[derive(Clone, Eq, PartialEq)]
193#[non_exhaustive]
194pub enum PaymentMethodOptionsCardMandateOptionsAmountType {
195    Fixed,
196    Maximum,
197    /// An unrecognized value from Stripe. Should not be used as a request parameter.
198    Unknown(String),
199}
200impl PaymentMethodOptionsCardMandateOptionsAmountType {
201    pub fn as_str(&self) -> &str {
202        use PaymentMethodOptionsCardMandateOptionsAmountType::*;
203        match self {
204            Fixed => "fixed",
205            Maximum => "maximum",
206            Unknown(v) => v,
207        }
208    }
209}
210
211impl std::str::FromStr for PaymentMethodOptionsCardMandateOptionsAmountType {
212    type Err = std::convert::Infallible;
213    fn from_str(s: &str) -> Result<Self, Self::Err> {
214        use PaymentMethodOptionsCardMandateOptionsAmountType::*;
215        match s {
216            "fixed" => Ok(Fixed),
217            "maximum" => Ok(Maximum),
218            v => {
219                tracing::warn!(
220                    "Unknown value '{}' for enum '{}'",
221                    v,
222                    "PaymentMethodOptionsCardMandateOptionsAmountType"
223                );
224                Ok(Unknown(v.to_owned()))
225            }
226        }
227    }
228}
229impl std::fmt::Display for PaymentMethodOptionsCardMandateOptionsAmountType {
230    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
231        f.write_str(self.as_str())
232    }
233}
234
235impl std::fmt::Debug for PaymentMethodOptionsCardMandateOptionsAmountType {
236    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
237        f.write_str(self.as_str())
238    }
239}
240#[cfg(feature = "serialize")]
241impl serde::Serialize for PaymentMethodOptionsCardMandateOptionsAmountType {
242    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
243    where
244        S: serde::Serializer,
245    {
246        serializer.serialize_str(self.as_str())
247    }
248}
249impl miniserde::Deserialize for PaymentMethodOptionsCardMandateOptionsAmountType {
250    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
251        crate::Place::new(out)
252    }
253}
254
255impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardMandateOptionsAmountType> {
256    fn string(&mut self, s: &str) -> miniserde::Result<()> {
257        use std::str::FromStr;
258        self.out = Some(
259            PaymentMethodOptionsCardMandateOptionsAmountType::from_str(s).expect("infallible"),
260        );
261        Ok(())
262    }
263}
264
265stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardMandateOptionsAmountType);
266#[cfg(feature = "deserialize")]
267impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardMandateOptionsAmountType {
268    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
269        use std::str::FromStr;
270        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
271        Ok(Self::from_str(&s).expect("infallible"))
272    }
273}
274/// Specifies payment frequency. One of `day`, `week`, `month`, `year`, or `sporadic`.
275#[derive(Clone, Eq, PartialEq)]
276#[non_exhaustive]
277pub enum PaymentMethodOptionsCardMandateOptionsInterval {
278    Day,
279    Month,
280    Sporadic,
281    Week,
282    Year,
283    /// An unrecognized value from Stripe. Should not be used as a request parameter.
284    Unknown(String),
285}
286impl PaymentMethodOptionsCardMandateOptionsInterval {
287    pub fn as_str(&self) -> &str {
288        use PaymentMethodOptionsCardMandateOptionsInterval::*;
289        match self {
290            Day => "day",
291            Month => "month",
292            Sporadic => "sporadic",
293            Week => "week",
294            Year => "year",
295            Unknown(v) => v,
296        }
297    }
298}
299
300impl std::str::FromStr for PaymentMethodOptionsCardMandateOptionsInterval {
301    type Err = std::convert::Infallible;
302    fn from_str(s: &str) -> Result<Self, Self::Err> {
303        use PaymentMethodOptionsCardMandateOptionsInterval::*;
304        match s {
305            "day" => Ok(Day),
306            "month" => Ok(Month),
307            "sporadic" => Ok(Sporadic),
308            "week" => Ok(Week),
309            "year" => Ok(Year),
310            v => {
311                tracing::warn!(
312                    "Unknown value '{}' for enum '{}'",
313                    v,
314                    "PaymentMethodOptionsCardMandateOptionsInterval"
315                );
316                Ok(Unknown(v.to_owned()))
317            }
318        }
319    }
320}
321impl std::fmt::Display for PaymentMethodOptionsCardMandateOptionsInterval {
322    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
323        f.write_str(self.as_str())
324    }
325}
326
327impl std::fmt::Debug for PaymentMethodOptionsCardMandateOptionsInterval {
328    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
329        f.write_str(self.as_str())
330    }
331}
332#[cfg(feature = "serialize")]
333impl serde::Serialize for PaymentMethodOptionsCardMandateOptionsInterval {
334    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
335    where
336        S: serde::Serializer,
337    {
338        serializer.serialize_str(self.as_str())
339    }
340}
341impl miniserde::Deserialize for PaymentMethodOptionsCardMandateOptionsInterval {
342    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
343        crate::Place::new(out)
344    }
345}
346
347impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardMandateOptionsInterval> {
348    fn string(&mut self, s: &str) -> miniserde::Result<()> {
349        use std::str::FromStr;
350        self.out =
351            Some(PaymentMethodOptionsCardMandateOptionsInterval::from_str(s).expect("infallible"));
352        Ok(())
353    }
354}
355
356stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardMandateOptionsInterval);
357#[cfg(feature = "deserialize")]
358impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardMandateOptionsInterval {
359    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
360        use std::str::FromStr;
361        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
362        Ok(Self::from_str(&s).expect("infallible"))
363    }
364}
365/// Specifies the type of mandates supported. Possible values are `india`.
366#[derive(Clone, Eq, PartialEq)]
367#[non_exhaustive]
368pub enum PaymentMethodOptionsCardMandateOptionsSupportedTypes {
369    India,
370    /// An unrecognized value from Stripe. Should not be used as a request parameter.
371    Unknown(String),
372}
373impl PaymentMethodOptionsCardMandateOptionsSupportedTypes {
374    pub fn as_str(&self) -> &str {
375        use PaymentMethodOptionsCardMandateOptionsSupportedTypes::*;
376        match self {
377            India => "india",
378            Unknown(v) => v,
379        }
380    }
381}
382
383impl std::str::FromStr for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
384    type Err = std::convert::Infallible;
385    fn from_str(s: &str) -> Result<Self, Self::Err> {
386        use PaymentMethodOptionsCardMandateOptionsSupportedTypes::*;
387        match s {
388            "india" => Ok(India),
389            v => {
390                tracing::warn!(
391                    "Unknown value '{}' for enum '{}'",
392                    v,
393                    "PaymentMethodOptionsCardMandateOptionsSupportedTypes"
394                );
395                Ok(Unknown(v.to_owned()))
396            }
397        }
398    }
399}
400impl std::fmt::Display for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
401    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
402        f.write_str(self.as_str())
403    }
404}
405
406impl std::fmt::Debug for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
407    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
408        f.write_str(self.as_str())
409    }
410}
411#[cfg(feature = "serialize")]
412impl serde::Serialize for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
413    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
414    where
415        S: serde::Serializer,
416    {
417        serializer.serialize_str(self.as_str())
418    }
419}
420impl miniserde::Deserialize for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
421    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
422        crate::Place::new(out)
423    }
424}
425
426impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardMandateOptionsSupportedTypes> {
427    fn string(&mut self, s: &str) -> miniserde::Result<()> {
428        use std::str::FromStr;
429        self.out = Some(
430            PaymentMethodOptionsCardMandateOptionsSupportedTypes::from_str(s).expect("infallible"),
431        );
432        Ok(())
433    }
434}
435
436stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardMandateOptionsSupportedTypes);
437#[cfg(feature = "deserialize")]
438impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
439    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
440        use std::str::FromStr;
441        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
442        Ok(Self::from_str(&s).expect("infallible"))
443    }
444}