stripe_shared/
checkout_pix_payment_method_options.rs

1#[derive(Copy, 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, self.expires_after_seconds, self.setup_future_usage)
84            else {
85                return None;
86            };
87            Some(Self::Out { amount_includes_iof, expires_after_seconds, setup_future_usage })
88        }
89    }
90
91    impl Map for Builder<'_> {
92        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93            self.builder.key(k)
94        }
95
96        fn finish(&mut self) -> Result<()> {
97            *self.out = self.builder.take_out();
98            Ok(())
99        }
100    }
101
102    impl ObjectDeser for CheckoutPixPaymentMethodOptions {
103        type Builder = CheckoutPixPaymentMethodOptionsBuilder;
104    }
105
106    impl FromValueOpt for CheckoutPixPaymentMethodOptions {
107        fn from_value(v: Value) -> Option<Self> {
108            let Value::Object(obj) = v else {
109                return None;
110            };
111            let mut b = CheckoutPixPaymentMethodOptionsBuilder::deser_default();
112            for (k, v) in obj {
113                match k.as_str() {
114                    "amount_includes_iof" => b.amount_includes_iof = FromValueOpt::from_value(v),
115                    "expires_after_seconds" => {
116                        b.expires_after_seconds = FromValueOpt::from_value(v)
117                    }
118                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
119                    _ => {}
120                }
121            }
122            b.take_out()
123        }
124    }
125};
126/// Determines if the amount includes the IOF tax.
127#[derive(Copy, Clone, Eq, PartialEq)]
128pub enum CheckoutPixPaymentMethodOptionsAmountIncludesIof {
129    Always,
130    Never,
131}
132impl CheckoutPixPaymentMethodOptionsAmountIncludesIof {
133    pub fn as_str(self) -> &'static str {
134        use CheckoutPixPaymentMethodOptionsAmountIncludesIof::*;
135        match self {
136            Always => "always",
137            Never => "never",
138        }
139    }
140}
141
142impl std::str::FromStr for CheckoutPixPaymentMethodOptionsAmountIncludesIof {
143    type Err = stripe_types::StripeParseError;
144    fn from_str(s: &str) -> Result<Self, Self::Err> {
145        use CheckoutPixPaymentMethodOptionsAmountIncludesIof::*;
146        match s {
147            "always" => Ok(Always),
148            "never" => Ok(Never),
149            _ => Err(stripe_types::StripeParseError),
150        }
151    }
152}
153impl std::fmt::Display for CheckoutPixPaymentMethodOptionsAmountIncludesIof {
154    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155        f.write_str(self.as_str())
156    }
157}
158
159impl std::fmt::Debug for CheckoutPixPaymentMethodOptionsAmountIncludesIof {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164#[cfg(feature = "serialize")]
165impl serde::Serialize for CheckoutPixPaymentMethodOptionsAmountIncludesIof {
166    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
167    where
168        S: serde::Serializer,
169    {
170        serializer.serialize_str(self.as_str())
171    }
172}
173impl miniserde::Deserialize for CheckoutPixPaymentMethodOptionsAmountIncludesIof {
174    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
175        crate::Place::new(out)
176    }
177}
178
179impl miniserde::de::Visitor for crate::Place<CheckoutPixPaymentMethodOptionsAmountIncludesIof> {
180    fn string(&mut self, s: &str) -> miniserde::Result<()> {
181        use std::str::FromStr;
182        self.out = Some(
183            CheckoutPixPaymentMethodOptionsAmountIncludesIof::from_str(s)
184                .map_err(|_| miniserde::Error)?,
185        );
186        Ok(())
187    }
188}
189
190stripe_types::impl_from_val_with_from_str!(CheckoutPixPaymentMethodOptionsAmountIncludesIof);
191#[cfg(feature = "deserialize")]
192impl<'de> serde::Deserialize<'de> for CheckoutPixPaymentMethodOptionsAmountIncludesIof {
193    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
194        use std::str::FromStr;
195        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
196        Self::from_str(&s).map_err(|_| {
197            serde::de::Error::custom(
198                "Unknown value for CheckoutPixPaymentMethodOptionsAmountIncludesIof",
199            )
200        })
201    }
202}
203/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
204///
205/// 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.
206/// 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.
207///
208/// 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.
209///
210/// 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).
211#[derive(Copy, Clone, Eq, PartialEq)]
212pub enum CheckoutPixPaymentMethodOptionsSetupFutureUsage {
213    None,
214}
215impl CheckoutPixPaymentMethodOptionsSetupFutureUsage {
216    pub fn as_str(self) -> &'static str {
217        use CheckoutPixPaymentMethodOptionsSetupFutureUsage::*;
218        match self {
219            None => "none",
220        }
221    }
222}
223
224impl std::str::FromStr for CheckoutPixPaymentMethodOptionsSetupFutureUsage {
225    type Err = stripe_types::StripeParseError;
226    fn from_str(s: &str) -> Result<Self, Self::Err> {
227        use CheckoutPixPaymentMethodOptionsSetupFutureUsage::*;
228        match s {
229            "none" => Ok(None),
230            _ => Err(stripe_types::StripeParseError),
231        }
232    }
233}
234impl std::fmt::Display for CheckoutPixPaymentMethodOptionsSetupFutureUsage {
235    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236        f.write_str(self.as_str())
237    }
238}
239
240impl std::fmt::Debug for CheckoutPixPaymentMethodOptionsSetupFutureUsage {
241    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
242        f.write_str(self.as_str())
243    }
244}
245#[cfg(feature = "serialize")]
246impl serde::Serialize for CheckoutPixPaymentMethodOptionsSetupFutureUsage {
247    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
248    where
249        S: serde::Serializer,
250    {
251        serializer.serialize_str(self.as_str())
252    }
253}
254impl miniserde::Deserialize for CheckoutPixPaymentMethodOptionsSetupFutureUsage {
255    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
256        crate::Place::new(out)
257    }
258}
259
260impl miniserde::de::Visitor for crate::Place<CheckoutPixPaymentMethodOptionsSetupFutureUsage> {
261    fn string(&mut self, s: &str) -> miniserde::Result<()> {
262        use std::str::FromStr;
263        self.out = Some(
264            CheckoutPixPaymentMethodOptionsSetupFutureUsage::from_str(s)
265                .map_err(|_| miniserde::Error)?,
266        );
267        Ok(())
268    }
269}
270
271stripe_types::impl_from_val_with_from_str!(CheckoutPixPaymentMethodOptionsSetupFutureUsage);
272#[cfg(feature = "deserialize")]
273impl<'de> serde::Deserialize<'de> for CheckoutPixPaymentMethodOptionsSetupFutureUsage {
274    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
275        use std::str::FromStr;
276        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
277        Self::from_str(&s).map_err(|_| {
278            serde::de::Error::custom(
279                "Unknown value for CheckoutPixPaymentMethodOptionsSetupFutureUsage",
280            )
281        })
282    }
283}