stripe_shared/
invoice_mandate_options_card.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoiceMandateOptionsCard {
5    /// Amount to be charged for future payments.
6    pub amount: Option<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: Option<InvoiceMandateOptionsCardAmountType>,
11    /// A description of the mandate or subscription that is meant to be displayed to the customer.
12    pub description: Option<String>,
13}
14#[doc(hidden)]
15pub struct InvoiceMandateOptionsCardBuilder {
16    amount: Option<Option<i64>>,
17    amount_type: Option<Option<InvoiceMandateOptionsCardAmountType>>,
18    description: Option<Option<String>>,
19}
20
21#[allow(
22    unused_variables,
23    irrefutable_let_patterns,
24    clippy::let_unit_value,
25    clippy::match_single_binding,
26    clippy::single_match
27)]
28const _: () = {
29    use miniserde::de::{Map, Visitor};
30    use miniserde::json::Value;
31    use miniserde::{Deserialize, Result, make_place};
32    use stripe_types::miniserde_helpers::FromValueOpt;
33    use stripe_types::{MapBuilder, ObjectDeser};
34
35    make_place!(Place);
36
37    impl Deserialize for InvoiceMandateOptionsCard {
38        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39            Place::new(out)
40        }
41    }
42
43    struct Builder<'a> {
44        out: &'a mut Option<InvoiceMandateOptionsCard>,
45        builder: InvoiceMandateOptionsCardBuilder,
46    }
47
48    impl Visitor for Place<InvoiceMandateOptionsCard> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: InvoiceMandateOptionsCardBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for InvoiceMandateOptionsCardBuilder {
58        type Out = InvoiceMandateOptionsCard;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "amount" => Deserialize::begin(&mut self.amount),
62                "amount_type" => Deserialize::begin(&mut self.amount_type),
63                "description" => Deserialize::begin(&mut self.description),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                amount: Deserialize::default(),
71                amount_type: Deserialize::default(),
72                description: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(amount), Some(amount_type), Some(description)) =
78                (self.amount, self.amount_type, self.description.take())
79            else {
80                return None;
81            };
82            Some(Self::Out { amount, amount_type, description })
83        }
84    }
85
86    impl Map for Builder<'_> {
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            self.builder.key(k)
89        }
90
91        fn finish(&mut self) -> Result<()> {
92            *self.out = self.builder.take_out();
93            Ok(())
94        }
95    }
96
97    impl ObjectDeser for InvoiceMandateOptionsCard {
98        type Builder = InvoiceMandateOptionsCardBuilder;
99    }
100
101    impl FromValueOpt for InvoiceMandateOptionsCard {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = InvoiceMandateOptionsCardBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "amount" => b.amount = FromValueOpt::from_value(v),
110                    "amount_type" => b.amount_type = FromValueOpt::from_value(v),
111                    "description" => b.description = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// One of `fixed` or `maximum`.
120/// If `fixed`, the `amount` param refers to the exact amount to be charged in future payments.
121/// If `maximum`, the amount charged can be up to the value passed for the `amount` param.
122#[derive(Copy, Clone, Eq, PartialEq)]
123pub enum InvoiceMandateOptionsCardAmountType {
124    Fixed,
125    Maximum,
126}
127impl InvoiceMandateOptionsCardAmountType {
128    pub fn as_str(self) -> &'static str {
129        use InvoiceMandateOptionsCardAmountType::*;
130        match self {
131            Fixed => "fixed",
132            Maximum => "maximum",
133        }
134    }
135}
136
137impl std::str::FromStr for InvoiceMandateOptionsCardAmountType {
138    type Err = stripe_types::StripeParseError;
139    fn from_str(s: &str) -> Result<Self, Self::Err> {
140        use InvoiceMandateOptionsCardAmountType::*;
141        match s {
142            "fixed" => Ok(Fixed),
143            "maximum" => Ok(Maximum),
144            _ => Err(stripe_types::StripeParseError),
145        }
146    }
147}
148impl std::fmt::Display for InvoiceMandateOptionsCardAmountType {
149    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
150        f.write_str(self.as_str())
151    }
152}
153
154impl std::fmt::Debug for InvoiceMandateOptionsCardAmountType {
155    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156        f.write_str(self.as_str())
157    }
158}
159#[cfg(feature = "serialize")]
160impl serde::Serialize for InvoiceMandateOptionsCardAmountType {
161    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
162    where
163        S: serde::Serializer,
164    {
165        serializer.serialize_str(self.as_str())
166    }
167}
168impl miniserde::Deserialize for InvoiceMandateOptionsCardAmountType {
169    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
170        crate::Place::new(out)
171    }
172}
173
174impl miniserde::de::Visitor for crate::Place<InvoiceMandateOptionsCardAmountType> {
175    fn string(&mut self, s: &str) -> miniserde::Result<()> {
176        use std::str::FromStr;
177        self.out =
178            Some(InvoiceMandateOptionsCardAmountType::from_str(s).map_err(|_| miniserde::Error)?);
179        Ok(())
180    }
181}
182
183stripe_types::impl_from_val_with_from_str!(InvoiceMandateOptionsCardAmountType);
184#[cfg(feature = "deserialize")]
185impl<'de> serde::Deserialize<'de> for InvoiceMandateOptionsCardAmountType {
186    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
187        use std::str::FromStr;
188        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
189        Self::from_str(&s).map_err(|_| {
190            serde::de::Error::custom("Unknown value for InvoiceMandateOptionsCardAmountType")
191        })
192    }
193}