stripe_shared/
payment_method_options_pix.rs

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