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