Skip to main content

stripe_shared/
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 PaymentMethodOptionsMandateOptionsPix {
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: Option<PaymentMethodOptionsMandateOptionsPixAmountIncludesIof>,
10    /// Type of amount.
11    pub amount_type: Option<PaymentMethodOptionsMandateOptionsPixAmountType>,
12    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
13    pub currency: Option<stripe_types::Currency>,
14    /// Date when the mandate expires and no further payments will be charged, in `YYYY-MM-DD`.
15    pub end_date: Option<String>,
16    /// Schedule at which the future payments will be charged.
17    pub payment_schedule: Option<PaymentMethodOptionsMandateOptionsPixPaymentSchedule>,
18    /// Subscription name displayed to buyers in their bank app.
19    pub reference: Option<String>,
20    /// Start date of the mandate, in `YYYY-MM-DD`.
21    pub start_date: Option<String>,
22}
23#[cfg(feature = "redact-generated-debug")]
24impl std::fmt::Debug for PaymentMethodOptionsMandateOptionsPix {
25    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26        f.debug_struct("PaymentMethodOptionsMandateOptionsPix").finish_non_exhaustive()
27    }
28}
29#[doc(hidden)]
30pub struct PaymentMethodOptionsMandateOptionsPixBuilder {
31    amount: Option<Option<i64>>,
32    amount_includes_iof: Option<Option<PaymentMethodOptionsMandateOptionsPixAmountIncludesIof>>,
33    amount_type: Option<Option<PaymentMethodOptionsMandateOptionsPixAmountType>>,
34    currency: Option<Option<stripe_types::Currency>>,
35    end_date: Option<Option<String>>,
36    payment_schedule: Option<Option<PaymentMethodOptionsMandateOptionsPixPaymentSchedule>>,
37    reference: Option<Option<String>>,
38    start_date: Option<Option<String>>,
39}
40
41#[allow(
42    unused_variables,
43    irrefutable_let_patterns,
44    clippy::let_unit_value,
45    clippy::match_single_binding,
46    clippy::single_match
47)]
48const _: () = {
49    use miniserde::de::{Map, Visitor};
50    use miniserde::json::Value;
51    use miniserde::{Deserialize, Result, make_place};
52    use stripe_types::miniserde_helpers::FromValueOpt;
53    use stripe_types::{MapBuilder, ObjectDeser};
54
55    make_place!(Place);
56
57    impl Deserialize for PaymentMethodOptionsMandateOptionsPix {
58        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
59            Place::new(out)
60        }
61    }
62
63    struct Builder<'a> {
64        out: &'a mut Option<PaymentMethodOptionsMandateOptionsPix>,
65        builder: PaymentMethodOptionsMandateOptionsPixBuilder,
66    }
67
68    impl Visitor for Place<PaymentMethodOptionsMandateOptionsPix> {
69        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
70            Ok(Box::new(Builder {
71                out: &mut self.out,
72                builder: PaymentMethodOptionsMandateOptionsPixBuilder::deser_default(),
73            }))
74        }
75    }
76
77    impl MapBuilder for PaymentMethodOptionsMandateOptionsPixBuilder {
78        type Out = PaymentMethodOptionsMandateOptionsPix;
79        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80            Ok(match k {
81                "amount" => Deserialize::begin(&mut self.amount),
82                "amount_includes_iof" => Deserialize::begin(&mut self.amount_includes_iof),
83                "amount_type" => Deserialize::begin(&mut self.amount_type),
84                "currency" => Deserialize::begin(&mut self.currency),
85                "end_date" => Deserialize::begin(&mut self.end_date),
86                "payment_schedule" => Deserialize::begin(&mut self.payment_schedule),
87                "reference" => Deserialize::begin(&mut self.reference),
88                "start_date" => Deserialize::begin(&mut self.start_date),
89                _ => <dyn Visitor>::ignore(),
90            })
91        }
92
93        fn deser_default() -> Self {
94            Self {
95                amount: Some(None),
96                amount_includes_iof: Some(None),
97                amount_type: Some(None),
98                currency: Some(None),
99                end_date: Some(None),
100                payment_schedule: Some(None),
101                reference: Some(None),
102                start_date: Some(None),
103            }
104        }
105
106        fn take_out(&mut self) -> Option<Self::Out> {
107            let (
108                Some(amount),
109                Some(amount_includes_iof),
110                Some(amount_type),
111                Some(currency),
112                Some(end_date),
113                Some(payment_schedule),
114                Some(reference),
115                Some(start_date),
116            ) = (
117                self.amount,
118                self.amount_includes_iof.take(),
119                self.amount_type.take(),
120                self.currency.take(),
121                self.end_date.take(),
122                self.payment_schedule.take(),
123                self.reference.take(),
124                self.start_date.take(),
125            )
126            else {
127                return None;
128            };
129            Some(Self::Out {
130                amount,
131                amount_includes_iof,
132                amount_type,
133                currency,
134                end_date,
135                payment_schedule,
136                reference,
137                start_date,
138            })
139        }
140    }
141
142    impl Map for Builder<'_> {
143        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
144            self.builder.key(k)
145        }
146
147        fn finish(&mut self) -> Result<()> {
148            *self.out = self.builder.take_out();
149            Ok(())
150        }
151    }
152
153    impl ObjectDeser for PaymentMethodOptionsMandateOptionsPix {
154        type Builder = PaymentMethodOptionsMandateOptionsPixBuilder;
155    }
156
157    impl FromValueOpt for PaymentMethodOptionsMandateOptionsPix {
158        fn from_value(v: Value) -> Option<Self> {
159            let Value::Object(obj) = v else {
160                return None;
161            };
162            let mut b = PaymentMethodOptionsMandateOptionsPixBuilder::deser_default();
163            for (k, v) in obj {
164                match k.as_str() {
165                    "amount" => b.amount = FromValueOpt::from_value(v),
166                    "amount_includes_iof" => b.amount_includes_iof = FromValueOpt::from_value(v),
167                    "amount_type" => b.amount_type = FromValueOpt::from_value(v),
168                    "currency" => b.currency = FromValueOpt::from_value(v),
169                    "end_date" => b.end_date = FromValueOpt::from_value(v),
170                    "payment_schedule" => b.payment_schedule = FromValueOpt::from_value(v),
171                    "reference" => b.reference = FromValueOpt::from_value(v),
172                    "start_date" => b.start_date = FromValueOpt::from_value(v),
173                    _ => {}
174                }
175            }
176            b.take_out()
177        }
178    }
179};
180/// Determines if the amount includes the IOF tax.
181#[derive(Clone, Eq, PartialEq)]
182#[non_exhaustive]
183pub enum PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
184    Always,
185    Never,
186    /// An unrecognized value from Stripe. Should not be used as a request parameter.
187    Unknown(String),
188}
189impl PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
190    pub fn as_str(&self) -> &str {
191        use PaymentMethodOptionsMandateOptionsPixAmountIncludesIof::*;
192        match self {
193            Always => "always",
194            Never => "never",
195            Unknown(v) => v,
196        }
197    }
198}
199
200impl std::str::FromStr for PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
201    type Err = std::convert::Infallible;
202    fn from_str(s: &str) -> Result<Self, Self::Err> {
203        use PaymentMethodOptionsMandateOptionsPixAmountIncludesIof::*;
204        match s {
205            "always" => Ok(Always),
206            "never" => Ok(Never),
207            v => {
208                tracing::warn!(
209                    "Unknown value '{}' for enum '{}'",
210                    v,
211                    "PaymentMethodOptionsMandateOptionsPixAmountIncludesIof"
212                );
213                Ok(Unknown(v.to_owned()))
214            }
215        }
216    }
217}
218impl std::fmt::Display for PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
219    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
220        f.write_str(self.as_str())
221    }
222}
223
224#[cfg(not(feature = "redact-generated-debug"))]
225impl std::fmt::Debug for PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
226    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
227        f.write_str(self.as_str())
228    }
229}
230#[cfg(feature = "redact-generated-debug")]
231impl std::fmt::Debug for PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
232    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
233        f.debug_struct(stringify!(PaymentMethodOptionsMandateOptionsPixAmountIncludesIof))
234            .finish_non_exhaustive()
235    }
236}
237#[cfg(feature = "serialize")]
238impl serde::Serialize for PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
239    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
240    where
241        S: serde::Serializer,
242    {
243        serializer.serialize_str(self.as_str())
244    }
245}
246impl miniserde::Deserialize for PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
247    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
248        crate::Place::new(out)
249    }
250}
251
252impl miniserde::de::Visitor
253    for crate::Place<PaymentMethodOptionsMandateOptionsPixAmountIncludesIof>
254{
255    fn string(&mut self, s: &str) -> miniserde::Result<()> {
256        use std::str::FromStr;
257        self.out = Some(
258            PaymentMethodOptionsMandateOptionsPixAmountIncludesIof::from_str(s)
259                .expect("infallible"),
260        );
261        Ok(())
262    }
263}
264
265stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsMandateOptionsPixAmountIncludesIof);
266#[cfg(feature = "deserialize")]
267impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsMandateOptionsPixAmountIncludesIof {
268    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
269        use std::str::FromStr;
270        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
271        Ok(Self::from_str(&s).expect("infallible"))
272    }
273}
274/// Type of amount.
275#[derive(Clone, Eq, PartialEq)]
276#[non_exhaustive]
277pub enum PaymentMethodOptionsMandateOptionsPixAmountType {
278    Fixed,
279    Maximum,
280    /// An unrecognized value from Stripe. Should not be used as a request parameter.
281    Unknown(String),
282}
283impl PaymentMethodOptionsMandateOptionsPixAmountType {
284    pub fn as_str(&self) -> &str {
285        use PaymentMethodOptionsMandateOptionsPixAmountType::*;
286        match self {
287            Fixed => "fixed",
288            Maximum => "maximum",
289            Unknown(v) => v,
290        }
291    }
292}
293
294impl std::str::FromStr for PaymentMethodOptionsMandateOptionsPixAmountType {
295    type Err = std::convert::Infallible;
296    fn from_str(s: &str) -> Result<Self, Self::Err> {
297        use PaymentMethodOptionsMandateOptionsPixAmountType::*;
298        match s {
299            "fixed" => Ok(Fixed),
300            "maximum" => Ok(Maximum),
301            v => {
302                tracing::warn!(
303                    "Unknown value '{}' for enum '{}'",
304                    v,
305                    "PaymentMethodOptionsMandateOptionsPixAmountType"
306                );
307                Ok(Unknown(v.to_owned()))
308            }
309        }
310    }
311}
312impl std::fmt::Display for PaymentMethodOptionsMandateOptionsPixAmountType {
313    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
314        f.write_str(self.as_str())
315    }
316}
317
318#[cfg(not(feature = "redact-generated-debug"))]
319impl std::fmt::Debug for PaymentMethodOptionsMandateOptionsPixAmountType {
320    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
321        f.write_str(self.as_str())
322    }
323}
324#[cfg(feature = "redact-generated-debug")]
325impl std::fmt::Debug for PaymentMethodOptionsMandateOptionsPixAmountType {
326    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
327        f.debug_struct(stringify!(PaymentMethodOptionsMandateOptionsPixAmountType))
328            .finish_non_exhaustive()
329    }
330}
331#[cfg(feature = "serialize")]
332impl serde::Serialize for PaymentMethodOptionsMandateOptionsPixAmountType {
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 PaymentMethodOptionsMandateOptionsPixAmountType {
341    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
342        crate::Place::new(out)
343    }
344}
345
346impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsMandateOptionsPixAmountType> {
347    fn string(&mut self, s: &str) -> miniserde::Result<()> {
348        use std::str::FromStr;
349        self.out =
350            Some(PaymentMethodOptionsMandateOptionsPixAmountType::from_str(s).expect("infallible"));
351        Ok(())
352    }
353}
354
355stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsMandateOptionsPixAmountType);
356#[cfg(feature = "deserialize")]
357impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsMandateOptionsPixAmountType {
358    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
359        use std::str::FromStr;
360        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
361        Ok(Self::from_str(&s).expect("infallible"))
362    }
363}
364/// Schedule at which the future payments will be charged.
365#[derive(Clone, Eq, PartialEq)]
366#[non_exhaustive]
367pub enum PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
368    Halfyearly,
369    Monthly,
370    Quarterly,
371    Weekly,
372    Yearly,
373    /// An unrecognized value from Stripe. Should not be used as a request parameter.
374    Unknown(String),
375}
376impl PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
377    pub fn as_str(&self) -> &str {
378        use PaymentMethodOptionsMandateOptionsPixPaymentSchedule::*;
379        match self {
380            Halfyearly => "halfyearly",
381            Monthly => "monthly",
382            Quarterly => "quarterly",
383            Weekly => "weekly",
384            Yearly => "yearly",
385            Unknown(v) => v,
386        }
387    }
388}
389
390impl std::str::FromStr for PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
391    type Err = std::convert::Infallible;
392    fn from_str(s: &str) -> Result<Self, Self::Err> {
393        use PaymentMethodOptionsMandateOptionsPixPaymentSchedule::*;
394        match s {
395            "halfyearly" => Ok(Halfyearly),
396            "monthly" => Ok(Monthly),
397            "quarterly" => Ok(Quarterly),
398            "weekly" => Ok(Weekly),
399            "yearly" => Ok(Yearly),
400            v => {
401                tracing::warn!(
402                    "Unknown value '{}' for enum '{}'",
403                    v,
404                    "PaymentMethodOptionsMandateOptionsPixPaymentSchedule"
405                );
406                Ok(Unknown(v.to_owned()))
407            }
408        }
409    }
410}
411impl std::fmt::Display for PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
412    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
413        f.write_str(self.as_str())
414    }
415}
416
417#[cfg(not(feature = "redact-generated-debug"))]
418impl std::fmt::Debug for PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
419    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
420        f.write_str(self.as_str())
421    }
422}
423#[cfg(feature = "redact-generated-debug")]
424impl std::fmt::Debug for PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
425    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
426        f.debug_struct(stringify!(PaymentMethodOptionsMandateOptionsPixPaymentSchedule))
427            .finish_non_exhaustive()
428    }
429}
430#[cfg(feature = "serialize")]
431impl serde::Serialize for PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
432    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
433    where
434        S: serde::Serializer,
435    {
436        serializer.serialize_str(self.as_str())
437    }
438}
439impl miniserde::Deserialize for PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
440    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
441        crate::Place::new(out)
442    }
443}
444
445impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsMandateOptionsPixPaymentSchedule> {
446    fn string(&mut self, s: &str) -> miniserde::Result<()> {
447        use std::str::FromStr;
448        self.out = Some(
449            PaymentMethodOptionsMandateOptionsPixPaymentSchedule::from_str(s).expect("infallible"),
450        );
451        Ok(())
452    }
453}
454
455stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsMandateOptionsPixPaymentSchedule);
456#[cfg(feature = "deserialize")]
457impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsMandateOptionsPixPaymentSchedule {
458    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
459        use std::str::FromStr;
460        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
461        Ok(Self::from_str(&s).expect("infallible"))
462    }
463}