stripe_shared/
checkout_pix_payment_method_options.rs

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