Skip to main content

stripe_shared/
invoice_payment_method_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 InvoicePaymentMethodOptionsPix {
6    /// Determines if the amount includes the IOF tax.
7    pub amount_includes_iof: Option<InvoicePaymentMethodOptionsPixAmountIncludesIof>,
8    /// The number of seconds (between 10 and 1209600) after which Pix payment will expire.
9    /// Defaults to 86400 seconds.
10    pub expires_after_seconds: Option<i64>,
11}
12#[cfg(feature = "redact-generated-debug")]
13impl std::fmt::Debug for InvoicePaymentMethodOptionsPix {
14    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15        f.debug_struct("InvoicePaymentMethodOptionsPix").finish_non_exhaustive()
16    }
17}
18#[doc(hidden)]
19pub struct InvoicePaymentMethodOptionsPixBuilder {
20    amount_includes_iof: Option<Option<InvoicePaymentMethodOptionsPixAmountIncludesIof>>,
21    expires_after_seconds: Option<Option<i64>>,
22}
23
24#[allow(
25    unused_variables,
26    irrefutable_let_patterns,
27    clippy::let_unit_value,
28    clippy::match_single_binding,
29    clippy::single_match
30)]
31const _: () = {
32    use miniserde::de::{Map, Visitor};
33    use miniserde::json::Value;
34    use miniserde::{Deserialize, Result, make_place};
35    use stripe_types::miniserde_helpers::FromValueOpt;
36    use stripe_types::{MapBuilder, ObjectDeser};
37
38    make_place!(Place);
39
40    impl Deserialize for InvoicePaymentMethodOptionsPix {
41        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
42            Place::new(out)
43        }
44    }
45
46    struct Builder<'a> {
47        out: &'a mut Option<InvoicePaymentMethodOptionsPix>,
48        builder: InvoicePaymentMethodOptionsPixBuilder,
49    }
50
51    impl Visitor for Place<InvoicePaymentMethodOptionsPix> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: InvoicePaymentMethodOptionsPixBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for InvoicePaymentMethodOptionsPixBuilder {
61        type Out = InvoicePaymentMethodOptionsPix;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "amount_includes_iof" => Deserialize::begin(&mut self.amount_includes_iof),
65                "expires_after_seconds" => Deserialize::begin(&mut self.expires_after_seconds),
66                _ => <dyn Visitor>::ignore(),
67            })
68        }
69
70        fn deser_default() -> Self {
71            Self { amount_includes_iof: Some(None), expires_after_seconds: Some(None) }
72        }
73
74        fn take_out(&mut self) -> Option<Self::Out> {
75            let (Some(amount_includes_iof), Some(expires_after_seconds)) =
76                (self.amount_includes_iof.take(), self.expires_after_seconds)
77            else {
78                return None;
79            };
80            Some(Self::Out { amount_includes_iof, expires_after_seconds })
81        }
82    }
83
84    impl Map for Builder<'_> {
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            self.builder.key(k)
87        }
88
89        fn finish(&mut self) -> Result<()> {
90            *self.out = self.builder.take_out();
91            Ok(())
92        }
93    }
94
95    impl ObjectDeser for InvoicePaymentMethodOptionsPix {
96        type Builder = InvoicePaymentMethodOptionsPixBuilder;
97    }
98
99    impl FromValueOpt for InvoicePaymentMethodOptionsPix {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = InvoicePaymentMethodOptionsPixBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "amount_includes_iof" => b.amount_includes_iof = FromValueOpt::from_value(v),
108                    "expires_after_seconds" => {
109                        b.expires_after_seconds = FromValueOpt::from_value(v)
110                    }
111                    _ => {}
112                }
113            }
114            b.take_out()
115        }
116    }
117};
118/// Determines if the amount includes the IOF tax.
119#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum InvoicePaymentMethodOptionsPixAmountIncludesIof {
122    Always,
123    Never,
124    /// An unrecognized value from Stripe. Should not be used as a request parameter.
125    Unknown(String),
126}
127impl InvoicePaymentMethodOptionsPixAmountIncludesIof {
128    pub fn as_str(&self) -> &str {
129        use InvoicePaymentMethodOptionsPixAmountIncludesIof::*;
130        match self {
131            Always => "always",
132            Never => "never",
133            Unknown(v) => v,
134        }
135    }
136}
137
138impl std::str::FromStr for InvoicePaymentMethodOptionsPixAmountIncludesIof {
139    type Err = std::convert::Infallible;
140    fn from_str(s: &str) -> Result<Self, Self::Err> {
141        use InvoicePaymentMethodOptionsPixAmountIncludesIof::*;
142        match s {
143            "always" => Ok(Always),
144            "never" => Ok(Never),
145            v => {
146                tracing::warn!(
147                    "Unknown value '{}' for enum '{}'",
148                    v,
149                    "InvoicePaymentMethodOptionsPixAmountIncludesIof"
150                );
151                Ok(Unknown(v.to_owned()))
152            }
153        }
154    }
155}
156impl std::fmt::Display for InvoicePaymentMethodOptionsPixAmountIncludesIof {
157    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161
162#[cfg(not(feature = "redact-generated-debug"))]
163impl std::fmt::Debug for InvoicePaymentMethodOptionsPixAmountIncludesIof {
164    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165        f.write_str(self.as_str())
166    }
167}
168#[cfg(feature = "redact-generated-debug")]
169impl std::fmt::Debug for InvoicePaymentMethodOptionsPixAmountIncludesIof {
170    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171        f.debug_struct(stringify!(InvoicePaymentMethodOptionsPixAmountIncludesIof))
172            .finish_non_exhaustive()
173    }
174}
175#[cfg(feature = "serialize")]
176impl serde::Serialize for InvoicePaymentMethodOptionsPixAmountIncludesIof {
177    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
178    where
179        S: serde::Serializer,
180    {
181        serializer.serialize_str(self.as_str())
182    }
183}
184impl miniserde::Deserialize for InvoicePaymentMethodOptionsPixAmountIncludesIof {
185    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
186        crate::Place::new(out)
187    }
188}
189
190impl miniserde::de::Visitor for crate::Place<InvoicePaymentMethodOptionsPixAmountIncludesIof> {
191    fn string(&mut self, s: &str) -> miniserde::Result<()> {
192        use std::str::FromStr;
193        self.out =
194            Some(InvoicePaymentMethodOptionsPixAmountIncludesIof::from_str(s).expect("infallible"));
195        Ok(())
196    }
197}
198
199stripe_types::impl_from_val_with_from_str!(InvoicePaymentMethodOptionsPixAmountIncludesIof);
200#[cfg(feature = "deserialize")]
201impl<'de> serde::Deserialize<'de> for InvoicePaymentMethodOptionsPixAmountIncludesIof {
202    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
203        use std::str::FromStr;
204        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
205        Ok(Self::from_str(&s).expect("infallible"))
206    }
207}