Skip to main content

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