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::{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,
94                self.expires_after_seconds,
95                self.expires_at,
96                self.setup_future_usage,
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(Copy, Clone, Eq, PartialEq)]
148pub enum PaymentMethodOptionsPixAmountIncludesIof {
149    Always,
150    Never,
151}
152impl PaymentMethodOptionsPixAmountIncludesIof {
153    pub fn as_str(self) -> &'static str {
154        use PaymentMethodOptionsPixAmountIncludesIof::*;
155        match self {
156            Always => "always",
157            Never => "never",
158        }
159    }
160}
161
162impl std::str::FromStr for PaymentMethodOptionsPixAmountIncludesIof {
163    type Err = stripe_types::StripeParseError;
164    fn from_str(s: &str) -> Result<Self, Self::Err> {
165        use PaymentMethodOptionsPixAmountIncludesIof::*;
166        match s {
167            "always" => Ok(Always),
168            "never" => Ok(Never),
169            _ => Err(stripe_types::StripeParseError),
170        }
171    }
172}
173impl std::fmt::Display for PaymentMethodOptionsPixAmountIncludesIof {
174    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
175        f.write_str(self.as_str())
176    }
177}
178
179impl std::fmt::Debug for PaymentMethodOptionsPixAmountIncludesIof {
180    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
181        f.write_str(self.as_str())
182    }
183}
184#[cfg(feature = "serialize")]
185impl serde::Serialize for PaymentMethodOptionsPixAmountIncludesIof {
186    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
187    where
188        S: serde::Serializer,
189    {
190        serializer.serialize_str(self.as_str())
191    }
192}
193impl miniserde::Deserialize for PaymentMethodOptionsPixAmountIncludesIof {
194    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
195        crate::Place::new(out)
196    }
197}
198
199impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsPixAmountIncludesIof> {
200    fn string(&mut self, s: &str) -> miniserde::Result<()> {
201        use std::str::FromStr;
202        self.out = Some(
203            PaymentMethodOptionsPixAmountIncludesIof::from_str(s).map_err(|_| miniserde::Error)?,
204        );
205        Ok(())
206    }
207}
208
209stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsPixAmountIncludesIof);
210#[cfg(feature = "deserialize")]
211impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsPixAmountIncludesIof {
212    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
213        use std::str::FromStr;
214        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
215        Self::from_str(&s).map_err(|_| {
216            serde::de::Error::custom("Unknown value for PaymentMethodOptionsPixAmountIncludesIof")
217        })
218    }
219}
220/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
221///
222/// 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.
223/// 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.
224///
225/// 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.
226///
227/// 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).
228#[derive(Copy, Clone, Eq, PartialEq)]
229pub enum PaymentMethodOptionsPixSetupFutureUsage {
230    None,
231}
232impl PaymentMethodOptionsPixSetupFutureUsage {
233    pub fn as_str(self) -> &'static str {
234        use PaymentMethodOptionsPixSetupFutureUsage::*;
235        match self {
236            None => "none",
237        }
238    }
239}
240
241impl std::str::FromStr for PaymentMethodOptionsPixSetupFutureUsage {
242    type Err = stripe_types::StripeParseError;
243    fn from_str(s: &str) -> Result<Self, Self::Err> {
244        use PaymentMethodOptionsPixSetupFutureUsage::*;
245        match s {
246            "none" => Ok(None),
247            _ => Err(stripe_types::StripeParseError),
248        }
249    }
250}
251impl std::fmt::Display for PaymentMethodOptionsPixSetupFutureUsage {
252    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
253        f.write_str(self.as_str())
254    }
255}
256
257impl std::fmt::Debug for PaymentMethodOptionsPixSetupFutureUsage {
258    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
259        f.write_str(self.as_str())
260    }
261}
262#[cfg(feature = "serialize")]
263impl serde::Serialize for PaymentMethodOptionsPixSetupFutureUsage {
264    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
265    where
266        S: serde::Serializer,
267    {
268        serializer.serialize_str(self.as_str())
269    }
270}
271impl miniserde::Deserialize for PaymentMethodOptionsPixSetupFutureUsage {
272    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
273        crate::Place::new(out)
274    }
275}
276
277impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsPixSetupFutureUsage> {
278    fn string(&mut self, s: &str) -> miniserde::Result<()> {
279        use std::str::FromStr;
280        self.out = Some(
281            PaymentMethodOptionsPixSetupFutureUsage::from_str(s).map_err(|_| miniserde::Error)?,
282        );
283        Ok(())
284    }
285}
286
287stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsPixSetupFutureUsage);
288#[cfg(feature = "deserialize")]
289impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsPixSetupFutureUsage {
290    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
291        use std::str::FromStr;
292        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
293        Self::from_str(&s).map_err(|_| {
294            serde::de::Error::custom("Unknown value for PaymentMethodOptionsPixSetupFutureUsage")
295        })
296    }
297}