stripe_shared/
checkout_oxxo_payment_method_options.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CheckoutOxxoPaymentMethodOptions {
5    /// The number of calendar days before an OXXO invoice expires.
6    /// For example, if you create an OXXO invoice on Monday and you set expires_after_days to 2, the OXXO invoice will expire on Wednesday at 23:59 America/Mexico_City time.
7    pub expires_after_days: u32,
8    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
9    ///
10    /// 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.
11    /// 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.
12    ///
13    /// 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.
14    ///
15    /// 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).
16    pub setup_future_usage: Option<CheckoutOxxoPaymentMethodOptionsSetupFutureUsage>,
17}
18#[doc(hidden)]
19pub struct CheckoutOxxoPaymentMethodOptionsBuilder {
20    expires_after_days: Option<u32>,
21    setup_future_usage: Option<Option<CheckoutOxxoPaymentMethodOptionsSetupFutureUsage>>,
22}
23
24#[allow(
25    unused_variables,
26    irrefutable_let_patterns,
27    clippy::let_unit_value,
28    clippy::match_single_binding,
29    clippy::single_match
30)]
31const _: () = {
32    use miniserde::de::{Map, Visitor};
33    use miniserde::json::Value;
34    use miniserde::{Deserialize, Result, make_place};
35    use stripe_types::miniserde_helpers::FromValueOpt;
36    use stripe_types::{MapBuilder, ObjectDeser};
37
38    make_place!(Place);
39
40    impl Deserialize for CheckoutOxxoPaymentMethodOptions {
41        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
42            Place::new(out)
43        }
44    }
45
46    struct Builder<'a> {
47        out: &'a mut Option<CheckoutOxxoPaymentMethodOptions>,
48        builder: CheckoutOxxoPaymentMethodOptionsBuilder,
49    }
50
51    impl Visitor for Place<CheckoutOxxoPaymentMethodOptions> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: CheckoutOxxoPaymentMethodOptionsBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for CheckoutOxxoPaymentMethodOptionsBuilder {
61        type Out = CheckoutOxxoPaymentMethodOptions;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "expires_after_days" => Deserialize::begin(&mut self.expires_after_days),
65                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
66                _ => <dyn Visitor>::ignore(),
67            })
68        }
69
70        fn deser_default() -> Self {
71            Self {
72                expires_after_days: Deserialize::default(),
73                setup_future_usage: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(expires_after_days), Some(setup_future_usage)) =
79                (self.expires_after_days, self.setup_future_usage.take())
80            else {
81                return None;
82            };
83            Some(Self::Out { expires_after_days, setup_future_usage })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for CheckoutOxxoPaymentMethodOptions {
99        type Builder = CheckoutOxxoPaymentMethodOptionsBuilder;
100    }
101
102    impl FromValueOpt for CheckoutOxxoPaymentMethodOptions {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = CheckoutOxxoPaymentMethodOptionsBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "expires_after_days" => b.expires_after_days = FromValueOpt::from_value(v),
111                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
120///
121/// 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.
122/// 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.
123///
124/// 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.
125///
126/// 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).
127#[derive(Clone, Eq, PartialEq)]
128#[non_exhaustive]
129pub enum CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
130    None,
131    /// An unrecognized value from Stripe. Should not be used as a request parameter.
132    Unknown(String),
133}
134impl CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
135    pub fn as_str(&self) -> &str {
136        use CheckoutOxxoPaymentMethodOptionsSetupFutureUsage::*;
137        match self {
138            None => "none",
139            Unknown(v) => v,
140        }
141    }
142}
143
144impl std::str::FromStr for CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
145    type Err = std::convert::Infallible;
146    fn from_str(s: &str) -> Result<Self, Self::Err> {
147        use CheckoutOxxoPaymentMethodOptionsSetupFutureUsage::*;
148        match s {
149            "none" => Ok(None),
150            v => {
151                tracing::warn!(
152                    "Unknown value '{}' for enum '{}'",
153                    v,
154                    "CheckoutOxxoPaymentMethodOptionsSetupFutureUsage"
155                );
156                Ok(Unknown(v.to_owned()))
157            }
158        }
159    }
160}
161impl std::fmt::Display for CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
162    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
163        f.write_str(self.as_str())
164    }
165}
166
167impl std::fmt::Debug for CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
168    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169        f.write_str(self.as_str())
170    }
171}
172#[cfg(feature = "serialize")]
173impl serde::Serialize for CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
174    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
175    where
176        S: serde::Serializer,
177    {
178        serializer.serialize_str(self.as_str())
179    }
180}
181impl miniserde::Deserialize for CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
182    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
183        crate::Place::new(out)
184    }
185}
186
187impl miniserde::de::Visitor for crate::Place<CheckoutOxxoPaymentMethodOptionsSetupFutureUsage> {
188    fn string(&mut self, s: &str) -> miniserde::Result<()> {
189        use std::str::FromStr;
190        self.out = Some(
191            CheckoutOxxoPaymentMethodOptionsSetupFutureUsage::from_str(s).expect("infallible"),
192        );
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(CheckoutOxxoPaymentMethodOptionsSetupFutureUsage);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for CheckoutOxxoPaymentMethodOptionsSetupFutureUsage {
200    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
201        use std::str::FromStr;
202        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
203        Ok(Self::from_str(&s).expect("infallible"))
204    }
205}