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