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::{make_place, Deserialize, Result};
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
94                _ => <dyn Visitor>::ignore(),
95            })
96        }
97
98        fn deser_default() -> Self {
99            Self {
100                amount: Deserialize::default(),
101                amount_type: Deserialize::default(),
102                description: Deserialize::default(),
103                end_date: Deserialize::default(),
104                interval: Deserialize::default(),
105                interval_count: Deserialize::default(),
106                reference: Deserialize::default(),
107                start_date: Deserialize::default(),
108                supported_types: Deserialize::default(),
109            }
110        }
111
112        fn take_out(&mut self) -> Option<Self::Out> {
113            let (
114                Some(amount),
115                Some(amount_type),
116                Some(description),
117                Some(end_date),
118                Some(interval),
119                Some(interval_count),
120                Some(reference),
121                Some(start_date),
122                Some(supported_types),
123            ) = (
124                self.amount,
125                self.amount_type,
126                self.description.take(),
127                self.end_date,
128                self.interval,
129                self.interval_count,
130                self.reference.take(),
131                self.start_date,
132                self.supported_types.take(),
133            )
134            else {
135                return None;
136            };
137            Some(Self::Out {
138                amount,
139                amount_type,
140                description,
141                end_date,
142                interval,
143                interval_count,
144                reference,
145                start_date,
146                supported_types,
147            })
148        }
149    }
150
151    impl<'a> Map for Builder<'a> {
152        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
153            self.builder.key(k)
154        }
155
156        fn finish(&mut self) -> Result<()> {
157            *self.out = self.builder.take_out();
158            Ok(())
159        }
160    }
161
162    impl ObjectDeser for PaymentMethodOptionsCardMandateOptions {
163        type Builder = PaymentMethodOptionsCardMandateOptionsBuilder;
164    }
165
166    impl FromValueOpt for PaymentMethodOptionsCardMandateOptions {
167        fn from_value(v: Value) -> Option<Self> {
168            let Value::Object(obj) = v else {
169                return None;
170            };
171            let mut b = PaymentMethodOptionsCardMandateOptionsBuilder::deser_default();
172            for (k, v) in obj {
173                match k.as_str() {
174                    "amount" => b.amount = FromValueOpt::from_value(v),
175                    "amount_type" => b.amount_type = FromValueOpt::from_value(v),
176                    "description" => b.description = FromValueOpt::from_value(v),
177                    "end_date" => b.end_date = FromValueOpt::from_value(v),
178                    "interval" => b.interval = FromValueOpt::from_value(v),
179                    "interval_count" => b.interval_count = FromValueOpt::from_value(v),
180                    "reference" => b.reference = FromValueOpt::from_value(v),
181                    "start_date" => b.start_date = FromValueOpt::from_value(v),
182                    "supported_types" => b.supported_types = FromValueOpt::from_value(v),
183
184                    _ => {}
185                }
186            }
187            b.take_out()
188        }
189    }
190};
191/// One of `fixed` or `maximum`.
192/// If `fixed`, the `amount` param refers to the exact amount to be charged in future payments.
193/// If `maximum`, the amount charged can be up to the value passed for the `amount` param.
194#[derive(Copy, Clone, Eq, PartialEq)]
195pub enum PaymentMethodOptionsCardMandateOptionsAmountType {
196    Fixed,
197    Maximum,
198}
199impl PaymentMethodOptionsCardMandateOptionsAmountType {
200    pub fn as_str(self) -> &'static str {
201        use PaymentMethodOptionsCardMandateOptionsAmountType::*;
202        match self {
203            Fixed => "fixed",
204            Maximum => "maximum",
205        }
206    }
207}
208
209impl std::str::FromStr for PaymentMethodOptionsCardMandateOptionsAmountType {
210    type Err = stripe_types::StripeParseError;
211    fn from_str(s: &str) -> Result<Self, Self::Err> {
212        use PaymentMethodOptionsCardMandateOptionsAmountType::*;
213        match s {
214            "fixed" => Ok(Fixed),
215            "maximum" => Ok(Maximum),
216            _ => Err(stripe_types::StripeParseError),
217        }
218    }
219}
220impl std::fmt::Display for PaymentMethodOptionsCardMandateOptionsAmountType {
221    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
222        f.write_str(self.as_str())
223    }
224}
225
226impl std::fmt::Debug for PaymentMethodOptionsCardMandateOptionsAmountType {
227    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
228        f.write_str(self.as_str())
229    }
230}
231#[cfg(feature = "serialize")]
232impl serde::Serialize for PaymentMethodOptionsCardMandateOptionsAmountType {
233    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
234    where
235        S: serde::Serializer,
236    {
237        serializer.serialize_str(self.as_str())
238    }
239}
240impl miniserde::Deserialize for PaymentMethodOptionsCardMandateOptionsAmountType {
241    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
242        crate::Place::new(out)
243    }
244}
245
246impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardMandateOptionsAmountType> {
247    fn string(&mut self, s: &str) -> miniserde::Result<()> {
248        use std::str::FromStr;
249        self.out = Some(
250            PaymentMethodOptionsCardMandateOptionsAmountType::from_str(s)
251                .map_err(|_| miniserde::Error)?,
252        );
253        Ok(())
254    }
255}
256
257stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardMandateOptionsAmountType);
258#[cfg(feature = "deserialize")]
259impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardMandateOptionsAmountType {
260    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
261        use std::str::FromStr;
262        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
263        Self::from_str(&s).map_err(|_| {
264            serde::de::Error::custom(
265                "Unknown value for PaymentMethodOptionsCardMandateOptionsAmountType",
266            )
267        })
268    }
269}
270/// Specifies payment frequency. One of `day`, `week`, `month`, `year`, or `sporadic`.
271#[derive(Copy, Clone, Eq, PartialEq)]
272pub enum PaymentMethodOptionsCardMandateOptionsInterval {
273    Day,
274    Month,
275    Sporadic,
276    Week,
277    Year,
278}
279impl PaymentMethodOptionsCardMandateOptionsInterval {
280    pub fn as_str(self) -> &'static str {
281        use PaymentMethodOptionsCardMandateOptionsInterval::*;
282        match self {
283            Day => "day",
284            Month => "month",
285            Sporadic => "sporadic",
286            Week => "week",
287            Year => "year",
288        }
289    }
290}
291
292impl std::str::FromStr for PaymentMethodOptionsCardMandateOptionsInterval {
293    type Err = stripe_types::StripeParseError;
294    fn from_str(s: &str) -> Result<Self, Self::Err> {
295        use PaymentMethodOptionsCardMandateOptionsInterval::*;
296        match s {
297            "day" => Ok(Day),
298            "month" => Ok(Month),
299            "sporadic" => Ok(Sporadic),
300            "week" => Ok(Week),
301            "year" => Ok(Year),
302            _ => Err(stripe_types::StripeParseError),
303        }
304    }
305}
306impl std::fmt::Display for PaymentMethodOptionsCardMandateOptionsInterval {
307    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308        f.write_str(self.as_str())
309    }
310}
311
312impl std::fmt::Debug for PaymentMethodOptionsCardMandateOptionsInterval {
313    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
314        f.write_str(self.as_str())
315    }
316}
317#[cfg(feature = "serialize")]
318impl serde::Serialize for PaymentMethodOptionsCardMandateOptionsInterval {
319    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
320    where
321        S: serde::Serializer,
322    {
323        serializer.serialize_str(self.as_str())
324    }
325}
326impl miniserde::Deserialize for PaymentMethodOptionsCardMandateOptionsInterval {
327    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
328        crate::Place::new(out)
329    }
330}
331
332impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardMandateOptionsInterval> {
333    fn string(&mut self, s: &str) -> miniserde::Result<()> {
334        use std::str::FromStr;
335        self.out = Some(
336            PaymentMethodOptionsCardMandateOptionsInterval::from_str(s)
337                .map_err(|_| miniserde::Error)?,
338        );
339        Ok(())
340    }
341}
342
343stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardMandateOptionsInterval);
344#[cfg(feature = "deserialize")]
345impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardMandateOptionsInterval {
346    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
347        use std::str::FromStr;
348        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
349        Self::from_str(&s).map_err(|_| {
350            serde::de::Error::custom(
351                "Unknown value for PaymentMethodOptionsCardMandateOptionsInterval",
352            )
353        })
354    }
355}
356/// Specifies the type of mandates supported. Possible values are `india`.
357#[derive(Copy, Clone, Eq, PartialEq)]
358pub enum PaymentMethodOptionsCardMandateOptionsSupportedTypes {
359    India,
360}
361impl PaymentMethodOptionsCardMandateOptionsSupportedTypes {
362    pub fn as_str(self) -> &'static str {
363        use PaymentMethodOptionsCardMandateOptionsSupportedTypes::*;
364        match self {
365            India => "india",
366        }
367    }
368}
369
370impl std::str::FromStr for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
371    type Err = stripe_types::StripeParseError;
372    fn from_str(s: &str) -> Result<Self, Self::Err> {
373        use PaymentMethodOptionsCardMandateOptionsSupportedTypes::*;
374        match s {
375            "india" => Ok(India),
376            _ => Err(stripe_types::StripeParseError),
377        }
378    }
379}
380impl std::fmt::Display for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
381    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
382        f.write_str(self.as_str())
383    }
384}
385
386impl std::fmt::Debug for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
387    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
388        f.write_str(self.as_str())
389    }
390}
391#[cfg(feature = "serialize")]
392impl serde::Serialize for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
393    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
394    where
395        S: serde::Serializer,
396    {
397        serializer.serialize_str(self.as_str())
398    }
399}
400impl miniserde::Deserialize for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
401    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
402        crate::Place::new(out)
403    }
404}
405
406impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardMandateOptionsSupportedTypes> {
407    fn string(&mut self, s: &str) -> miniserde::Result<()> {
408        use std::str::FromStr;
409        self.out = Some(
410            PaymentMethodOptionsCardMandateOptionsSupportedTypes::from_str(s)
411                .map_err(|_| miniserde::Error)?,
412        );
413        Ok(())
414    }
415}
416
417stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardMandateOptionsSupportedTypes);
418#[cfg(feature = "deserialize")]
419impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardMandateOptionsSupportedTypes {
420    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
421        use std::str::FromStr;
422        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
423        Self::from_str(&s).map_err(|_| {
424            serde::de::Error::custom(
425                "Unknown value for PaymentMethodOptionsCardMandateOptionsSupportedTypes",
426            )
427        })
428    }
429}