Skip to main content

stripe_shared/
subscription_payment_method_options_mandate_options_pix.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 SubscriptionPaymentMethodOptionsMandateOptionsPix {
6    /// Amount to be charged for future payments.
7    pub amount: Option<i64>,
8    /// Determines if the amount includes the IOF tax.
9    pub amount_includes_iof:
10        Option<SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof>,
11    /// Date when the mandate expires and no further payments will be charged, in `YYYY-MM-DD`.
12    pub end_date: Option<String>,
13    /// Schedule at which the future payments will be charged.
14    pub payment_schedule: Option<SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule>,
15}
16#[cfg(feature = "redact-generated-debug")]
17impl std::fmt::Debug for SubscriptionPaymentMethodOptionsMandateOptionsPix {
18    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19        f.debug_struct("SubscriptionPaymentMethodOptionsMandateOptionsPix").finish_non_exhaustive()
20    }
21}
22#[doc(hidden)]
23pub struct SubscriptionPaymentMethodOptionsMandateOptionsPixBuilder {
24    amount: Option<Option<i64>>,
25    amount_includes_iof:
26        Option<Option<SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof>>,
27    end_date: Option<Option<String>>,
28    payment_schedule:
29        Option<Option<SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule>>,
30}
31
32#[allow(
33    unused_variables,
34    irrefutable_let_patterns,
35    clippy::let_unit_value,
36    clippy::match_single_binding,
37    clippy::single_match
38)]
39const _: () = {
40    use miniserde::de::{Map, Visitor};
41    use miniserde::json::Value;
42    use miniserde::{Deserialize, Result, make_place};
43    use stripe_types::miniserde_helpers::FromValueOpt;
44    use stripe_types::{MapBuilder, ObjectDeser};
45
46    make_place!(Place);
47
48    impl Deserialize for SubscriptionPaymentMethodOptionsMandateOptionsPix {
49        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50            Place::new(out)
51        }
52    }
53
54    struct Builder<'a> {
55        out: &'a mut Option<SubscriptionPaymentMethodOptionsMandateOptionsPix>,
56        builder: SubscriptionPaymentMethodOptionsMandateOptionsPixBuilder,
57    }
58
59    impl Visitor for Place<SubscriptionPaymentMethodOptionsMandateOptionsPix> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: SubscriptionPaymentMethodOptionsMandateOptionsPixBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for SubscriptionPaymentMethodOptionsMandateOptionsPixBuilder {
69        type Out = SubscriptionPaymentMethodOptionsMandateOptionsPix;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "amount" => Deserialize::begin(&mut self.amount),
73                "amount_includes_iof" => Deserialize::begin(&mut self.amount_includes_iof),
74                "end_date" => Deserialize::begin(&mut self.end_date),
75                "payment_schedule" => Deserialize::begin(&mut self.payment_schedule),
76                _ => <dyn Visitor>::ignore(),
77            })
78        }
79
80        fn deser_default() -> Self {
81            Self {
82                amount: Some(None),
83                amount_includes_iof: Some(None),
84                end_date: Some(None),
85                payment_schedule: Some(None),
86            }
87        }
88
89        fn take_out(&mut self) -> Option<Self::Out> {
90            let (Some(amount), Some(amount_includes_iof), Some(end_date), Some(payment_schedule)) = (
91                self.amount,
92                self.amount_includes_iof.take(),
93                self.end_date.take(),
94                self.payment_schedule.take(),
95            ) else {
96                return None;
97            };
98            Some(Self::Out { amount, amount_includes_iof, end_date, payment_schedule })
99        }
100    }
101
102    impl Map for Builder<'_> {
103        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
104            self.builder.key(k)
105        }
106
107        fn finish(&mut self) -> Result<()> {
108            *self.out = self.builder.take_out();
109            Ok(())
110        }
111    }
112
113    impl ObjectDeser for SubscriptionPaymentMethodOptionsMandateOptionsPix {
114        type Builder = SubscriptionPaymentMethodOptionsMandateOptionsPixBuilder;
115    }
116
117    impl FromValueOpt for SubscriptionPaymentMethodOptionsMandateOptionsPix {
118        fn from_value(v: Value) -> Option<Self> {
119            let Value::Object(obj) = v else {
120                return None;
121            };
122            let mut b = SubscriptionPaymentMethodOptionsMandateOptionsPixBuilder::deser_default();
123            for (k, v) in obj {
124                match k.as_str() {
125                    "amount" => b.amount = FromValueOpt::from_value(v),
126                    "amount_includes_iof" => b.amount_includes_iof = FromValueOpt::from_value(v),
127                    "end_date" => b.end_date = FromValueOpt::from_value(v),
128                    "payment_schedule" => b.payment_schedule = FromValueOpt::from_value(v),
129                    _ => {}
130                }
131            }
132            b.take_out()
133        }
134    }
135};
136/// Determines if the amount includes the IOF tax.
137#[derive(Clone, Eq, PartialEq)]
138#[non_exhaustive]
139pub enum SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
140    Always,
141    Never,
142    /// An unrecognized value from Stripe. Should not be used as a request parameter.
143    Unknown(String),
144}
145impl SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
146    pub fn as_str(&self) -> &str {
147        use SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof::*;
148        match self {
149            Always => "always",
150            Never => "never",
151            Unknown(v) => v,
152        }
153    }
154}
155
156impl std::str::FromStr for SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
157    type Err = std::convert::Infallible;
158    fn from_str(s: &str) -> Result<Self, Self::Err> {
159        use SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof::*;
160        match s {
161            "always" => Ok(Always),
162            "never" => Ok(Never),
163            v => {
164                tracing::warn!(
165                    "Unknown value '{}' for enum '{}'",
166                    v,
167                    "SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof"
168                );
169                Ok(Unknown(v.to_owned()))
170            }
171        }
172    }
173}
174impl std::fmt::Display for SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
175    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
176        f.write_str(self.as_str())
177    }
178}
179
180#[cfg(not(feature = "redact-generated-debug"))]
181impl std::fmt::Debug for SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.write_str(self.as_str())
184    }
185}
186#[cfg(feature = "redact-generated-debug")]
187impl std::fmt::Debug for SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
188    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
189        f.debug_struct(stringify!(
190            SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof
191        ))
192        .finish_non_exhaustive()
193    }
194}
195#[cfg(feature = "serialize")]
196impl serde::Serialize for SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
197    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
198    where
199        S: serde::Serializer,
200    {
201        serializer.serialize_str(self.as_str())
202    }
203}
204impl miniserde::Deserialize for SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
205    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
206        crate::Place::new(out)
207    }
208}
209
210impl miniserde::de::Visitor
211    for crate::Place<SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof>
212{
213    fn string(&mut self, s: &str) -> miniserde::Result<()> {
214        use std::str::FromStr;
215        self.out = Some(
216            SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof::from_str(s)
217                .expect("infallible"),
218        );
219        Ok(())
220    }
221}
222
223stripe_types::impl_from_val_with_from_str!(
224    SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof
225);
226#[cfg(feature = "deserialize")]
227impl<'de> serde::Deserialize<'de>
228    for SubscriptionPaymentMethodOptionsMandateOptionsPixAmountIncludesIof
229{
230    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
231        use std::str::FromStr;
232        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
233        Ok(Self::from_str(&s).expect("infallible"))
234    }
235}
236/// Schedule at which the future payments will be charged.
237#[derive(Clone, Eq, PartialEq)]
238#[non_exhaustive]
239pub enum SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
240    Halfyearly,
241    Monthly,
242    Quarterly,
243    Weekly,
244    Yearly,
245    /// An unrecognized value from Stripe. Should not be used as a request parameter.
246    Unknown(String),
247}
248impl SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
249    pub fn as_str(&self) -> &str {
250        use SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule::*;
251        match self {
252            Halfyearly => "halfyearly",
253            Monthly => "monthly",
254            Quarterly => "quarterly",
255            Weekly => "weekly",
256            Yearly => "yearly",
257            Unknown(v) => v,
258        }
259    }
260}
261
262impl std::str::FromStr for SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
263    type Err = std::convert::Infallible;
264    fn from_str(s: &str) -> Result<Self, Self::Err> {
265        use SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule::*;
266        match s {
267            "halfyearly" => Ok(Halfyearly),
268            "monthly" => Ok(Monthly),
269            "quarterly" => Ok(Quarterly),
270            "weekly" => Ok(Weekly),
271            "yearly" => Ok(Yearly),
272            v => {
273                tracing::warn!(
274                    "Unknown value '{}' for enum '{}'",
275                    v,
276                    "SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule"
277                );
278                Ok(Unknown(v.to_owned()))
279            }
280        }
281    }
282}
283impl std::fmt::Display for SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
284    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
285        f.write_str(self.as_str())
286    }
287}
288
289#[cfg(not(feature = "redact-generated-debug"))]
290impl std::fmt::Debug for SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
291    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
292        f.write_str(self.as_str())
293    }
294}
295#[cfg(feature = "redact-generated-debug")]
296impl std::fmt::Debug for SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
297    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
298        f.debug_struct(stringify!(SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule))
299            .finish_non_exhaustive()
300    }
301}
302#[cfg(feature = "serialize")]
303impl serde::Serialize for SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
304    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
305    where
306        S: serde::Serializer,
307    {
308        serializer.serialize_str(self.as_str())
309    }
310}
311impl miniserde::Deserialize for SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule {
312    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
313        crate::Place::new(out)
314    }
315}
316
317impl miniserde::de::Visitor
318    for crate::Place<SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule>
319{
320    fn string(&mut self, s: &str) -> miniserde::Result<()> {
321        use std::str::FromStr;
322        self.out = Some(
323            SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule::from_str(s)
324                .expect("infallible"),
325        );
326        Ok(())
327    }
328}
329
330stripe_types::impl_from_val_with_from_str!(
331    SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule
332);
333#[cfg(feature = "deserialize")]
334impl<'de> serde::Deserialize<'de>
335    for SubscriptionPaymentMethodOptionsMandateOptionsPixPaymentSchedule
336{
337    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
338        use std::str::FromStr;
339        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
340        Ok(Self::from_str(&s).expect("infallible"))
341    }
342}