stripe_shared/
payment_method_options_pix.rs

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