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
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                amount: Deserialize::default(),
72                amount_type: Deserialize::default(),
73                description: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(amount), Some(amount_type), Some(description)) =
79                (self.amount, self.amount_type, self.description.take())
80            else {
81                return None;
82            };
83            Some(Self::Out { amount, amount_type, description })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for InvoiceMandateOptionsCard {
99        type Builder = InvoiceMandateOptionsCardBuilder;
100    }
101
102    impl FromValueOpt for InvoiceMandateOptionsCard {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = InvoiceMandateOptionsCardBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "amount" => b.amount = FromValueOpt::from_value(v),
111                    "amount_type" => b.amount_type = FromValueOpt::from_value(v),
112                    "description" => b.description = FromValueOpt::from_value(v),
113
114                    _ => {}
115                }
116            }
117            b.take_out()
118        }
119    }
120};
121/// One of `fixed` or `maximum`.
122/// If `fixed`, the `amount` param refers to the exact amount to be charged in future payments.
123/// If `maximum`, the amount charged can be up to the value passed for the `amount` param.
124#[derive(Copy, Clone, Eq, PartialEq)]
125pub enum InvoiceMandateOptionsCardAmountType {
126    Fixed,
127    Maximum,
128}
129impl InvoiceMandateOptionsCardAmountType {
130    pub fn as_str(self) -> &'static str {
131        use InvoiceMandateOptionsCardAmountType::*;
132        match self {
133            Fixed => "fixed",
134            Maximum => "maximum",
135        }
136    }
137}
138
139impl std::str::FromStr for InvoiceMandateOptionsCardAmountType {
140    type Err = stripe_types::StripeParseError;
141    fn from_str(s: &str) -> Result<Self, Self::Err> {
142        use InvoiceMandateOptionsCardAmountType::*;
143        match s {
144            "fixed" => Ok(Fixed),
145            "maximum" => Ok(Maximum),
146            _ => Err(stripe_types::StripeParseError),
147        }
148    }
149}
150impl std::fmt::Display for InvoiceMandateOptionsCardAmountType {
151    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152        f.write_str(self.as_str())
153    }
154}
155
156impl std::fmt::Debug for InvoiceMandateOptionsCardAmountType {
157    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161#[cfg(feature = "serialize")]
162impl serde::Serialize for InvoiceMandateOptionsCardAmountType {
163    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
164    where
165        S: serde::Serializer,
166    {
167        serializer.serialize_str(self.as_str())
168    }
169}
170impl miniserde::Deserialize for InvoiceMandateOptionsCardAmountType {
171    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
172        crate::Place::new(out)
173    }
174}
175
176impl miniserde::de::Visitor for crate::Place<InvoiceMandateOptionsCardAmountType> {
177    fn string(&mut self, s: &str) -> miniserde::Result<()> {
178        use std::str::FromStr;
179        self.out =
180            Some(InvoiceMandateOptionsCardAmountType::from_str(s).map_err(|_| miniserde::Error)?);
181        Ok(())
182    }
183}
184
185stripe_types::impl_from_val_with_from_str!(InvoiceMandateOptionsCardAmountType);
186#[cfg(feature = "deserialize")]
187impl<'de> serde::Deserialize<'de> for InvoiceMandateOptionsCardAmountType {
188    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
189        use std::str::FromStr;
190        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
191        Self::from_str(&s).map_err(|_| {
192            serde::de::Error::custom("Unknown value for InvoiceMandateOptionsCardAmountType")
193        })
194    }
195}