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