Skip to main content

stripe_shared/
setup_intent_payment_method_options_card_mandate_options.rs

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