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