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    /// The number of seconds (between 10 and 1209600) after which Pix payment will expire.
6    pub expires_after_seconds: Option<i64>,
7    /// The timestamp at which the Pix expires.
8    pub expires_at: 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<PaymentMethodOptionsPixSetupFutureUsage>,
18}
19#[doc(hidden)]
20pub struct PaymentMethodOptionsPixBuilder {
21    expires_after_seconds: Option<Option<i64>>,
22    expires_at: Option<Option<i64>>,
23    setup_future_usage: Option<Option<PaymentMethodOptionsPixSetupFutureUsage>>,
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 PaymentMethodOptionsPix {
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<PaymentMethodOptionsPix>,
50        builder: PaymentMethodOptionsPixBuilder,
51    }
52
53    impl Visitor for Place<PaymentMethodOptionsPix> {
54        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55            Ok(Box::new(Builder {
56                out: &mut self.out,
57                builder: PaymentMethodOptionsPixBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for PaymentMethodOptionsPixBuilder {
63        type Out = PaymentMethodOptionsPix;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "expires_after_seconds" => Deserialize::begin(&mut self.expires_after_seconds),
67                "expires_at" => Deserialize::begin(&mut self.expires_at),
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                expires_after_seconds: Deserialize::default(),
77                expires_at: Deserialize::default(),
78                setup_future_usage: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (Some(expires_after_seconds), Some(expires_at), Some(setup_future_usage)) =
84                (self.expires_after_seconds, self.expires_at, self.setup_future_usage)
85            else {
86                return None;
87            };
88            Some(Self::Out { expires_after_seconds, expires_at, setup_future_usage })
89        }
90    }
91
92    impl<'a> Map for Builder<'a> {
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 PaymentMethodOptionsPix {
104        type Builder = PaymentMethodOptionsPixBuilder;
105    }
106
107    impl FromValueOpt for PaymentMethodOptionsPix {
108        fn from_value(v: Value) -> Option<Self> {
109            let Value::Object(obj) = v else {
110                return None;
111            };
112            let mut b = PaymentMethodOptionsPixBuilder::deser_default();
113            for (k, v) in obj {
114                match k.as_str() {
115                    "expires_after_seconds" => {
116                        b.expires_after_seconds = FromValueOpt::from_value(v)
117                    }
118                    "expires_at" => b.expires_at = FromValueOpt::from_value(v),
119                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
120
121                    _ => {}
122                }
123            }
124            b.take_out()
125        }
126    }
127};
128/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
129///
130/// 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.
131/// 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.
132///
133/// 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.
134///
135/// 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).
136#[derive(Copy, Clone, Eq, PartialEq)]
137pub enum PaymentMethodOptionsPixSetupFutureUsage {
138    None,
139}
140impl PaymentMethodOptionsPixSetupFutureUsage {
141    pub fn as_str(self) -> &'static str {
142        use PaymentMethodOptionsPixSetupFutureUsage::*;
143        match self {
144            None => "none",
145        }
146    }
147}
148
149impl std::str::FromStr for PaymentMethodOptionsPixSetupFutureUsage {
150    type Err = stripe_types::StripeParseError;
151    fn from_str(s: &str) -> Result<Self, Self::Err> {
152        use PaymentMethodOptionsPixSetupFutureUsage::*;
153        match s {
154            "none" => Ok(None),
155            _ => Err(stripe_types::StripeParseError),
156        }
157    }
158}
159impl std::fmt::Display for PaymentMethodOptionsPixSetupFutureUsage {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164
165impl std::fmt::Debug for PaymentMethodOptionsPixSetupFutureUsage {
166    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167        f.write_str(self.as_str())
168    }
169}
170#[cfg(feature = "serialize")]
171impl serde::Serialize for PaymentMethodOptionsPixSetupFutureUsage {
172    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
173    where
174        S: serde::Serializer,
175    {
176        serializer.serialize_str(self.as_str())
177    }
178}
179impl miniserde::Deserialize for PaymentMethodOptionsPixSetupFutureUsage {
180    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
181        crate::Place::new(out)
182    }
183}
184
185impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsPixSetupFutureUsage> {
186    fn string(&mut self, s: &str) -> miniserde::Result<()> {
187        use std::str::FromStr;
188        self.out = Some(
189            PaymentMethodOptionsPixSetupFutureUsage::from_str(s).map_err(|_| miniserde::Error)?,
190        );
191        Ok(())
192    }
193}
194
195stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsPixSetupFutureUsage);
196#[cfg(feature = "deserialize")]
197impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsPixSetupFutureUsage {
198    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199        use std::str::FromStr;
200        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201        Self::from_str(&s).map_err(|_| {
202            serde::de::Error::custom("Unknown value for PaymentMethodOptionsPixSetupFutureUsage")
203        })
204    }
205}