Skip to main content

stripe_shared/
payment_intent_payment_method_options_link.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentIntentPaymentMethodOptionsLink {
6    /// Controls when the funds will be captured from the customer's account.
7    pub capture_method: Option<PaymentIntentPaymentMethodOptionsLinkCaptureMethod>,
8    /// \[Deprecated\] This is a legacy parameter that no longer has any function.
9    pub persistent_token: Option<String>,
10    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
11    ///
12    /// 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.
13    /// 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.
14    ///
15    /// 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.
16    ///
17    /// 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).
18    pub setup_future_usage: Option<PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage>,
19}
20#[cfg(feature = "redact-generated-debug")]
21impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsLink {
22    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23        f.debug_struct("PaymentIntentPaymentMethodOptionsLink").finish_non_exhaustive()
24    }
25}
26#[doc(hidden)]
27pub struct PaymentIntentPaymentMethodOptionsLinkBuilder {
28    capture_method: Option<Option<PaymentIntentPaymentMethodOptionsLinkCaptureMethod>>,
29    persistent_token: Option<Option<String>>,
30    setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage>>,
31}
32
33#[allow(
34    unused_variables,
35    irrefutable_let_patterns,
36    clippy::let_unit_value,
37    clippy::match_single_binding,
38    clippy::single_match
39)]
40const _: () = {
41    use miniserde::de::{Map, Visitor};
42    use miniserde::json::Value;
43    use miniserde::{Deserialize, Result, make_place};
44    use stripe_types::miniserde_helpers::FromValueOpt;
45    use stripe_types::{MapBuilder, ObjectDeser};
46
47    make_place!(Place);
48
49    impl Deserialize for PaymentIntentPaymentMethodOptionsLink {
50        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
51            Place::new(out)
52        }
53    }
54
55    struct Builder<'a> {
56        out: &'a mut Option<PaymentIntentPaymentMethodOptionsLink>,
57        builder: PaymentIntentPaymentMethodOptionsLinkBuilder,
58    }
59
60    impl Visitor for Place<PaymentIntentPaymentMethodOptionsLink> {
61        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
62            Ok(Box::new(Builder {
63                out: &mut self.out,
64                builder: PaymentIntentPaymentMethodOptionsLinkBuilder::deser_default(),
65            }))
66        }
67    }
68
69    impl MapBuilder for PaymentIntentPaymentMethodOptionsLinkBuilder {
70        type Out = PaymentIntentPaymentMethodOptionsLink;
71        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
72            Ok(match k {
73                "capture_method" => Deserialize::begin(&mut self.capture_method),
74                "persistent_token" => Deserialize::begin(&mut self.persistent_token),
75                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
76                _ => <dyn Visitor>::ignore(),
77            })
78        }
79
80        fn deser_default() -> Self {
81            Self {
82                capture_method: Deserialize::default(),
83                persistent_token: Deserialize::default(),
84                setup_future_usage: Deserialize::default(),
85            }
86        }
87
88        fn take_out(&mut self) -> Option<Self::Out> {
89            let (Some(capture_method), Some(persistent_token), Some(setup_future_usage)) = (
90                self.capture_method.take(),
91                self.persistent_token.take(),
92                self.setup_future_usage.take(),
93            ) else {
94                return None;
95            };
96            Some(Self::Out { capture_method, persistent_token, setup_future_usage })
97        }
98    }
99
100    impl Map for Builder<'_> {
101        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
102            self.builder.key(k)
103        }
104
105        fn finish(&mut self) -> Result<()> {
106            *self.out = self.builder.take_out();
107            Ok(())
108        }
109    }
110
111    impl ObjectDeser for PaymentIntentPaymentMethodOptionsLink {
112        type Builder = PaymentIntentPaymentMethodOptionsLinkBuilder;
113    }
114
115    impl FromValueOpt for PaymentIntentPaymentMethodOptionsLink {
116        fn from_value(v: Value) -> Option<Self> {
117            let Value::Object(obj) = v else {
118                return None;
119            };
120            let mut b = PaymentIntentPaymentMethodOptionsLinkBuilder::deser_default();
121            for (k, v) in obj {
122                match k.as_str() {
123                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
124                    "persistent_token" => b.persistent_token = FromValueOpt::from_value(v),
125                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
126                    _ => {}
127                }
128            }
129            b.take_out()
130        }
131    }
132};
133/// Controls when the funds will be captured from the customer's account.
134#[derive(Clone, Eq, PartialEq)]
135#[non_exhaustive]
136pub enum PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
137    Manual,
138    /// An unrecognized value from Stripe. Should not be used as a request parameter.
139    Unknown(String),
140}
141impl PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
142    pub fn as_str(&self) -> &str {
143        use PaymentIntentPaymentMethodOptionsLinkCaptureMethod::*;
144        match self {
145            Manual => "manual",
146            Unknown(v) => v,
147        }
148    }
149}
150
151impl std::str::FromStr for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
152    type Err = std::convert::Infallible;
153    fn from_str(s: &str) -> Result<Self, Self::Err> {
154        use PaymentIntentPaymentMethodOptionsLinkCaptureMethod::*;
155        match s {
156            "manual" => Ok(Manual),
157            v => {
158                tracing::warn!(
159                    "Unknown value '{}' for enum '{}'",
160                    v,
161                    "PaymentIntentPaymentMethodOptionsLinkCaptureMethod"
162                );
163                Ok(Unknown(v.to_owned()))
164            }
165        }
166    }
167}
168impl std::fmt::Display for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
169    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170        f.write_str(self.as_str())
171    }
172}
173
174#[cfg(not(feature = "redact-generated-debug"))]
175impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
176    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177        f.write_str(self.as_str())
178    }
179}
180#[cfg(feature = "redact-generated-debug")]
181impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.debug_struct(stringify!(PaymentIntentPaymentMethodOptionsLinkCaptureMethod))
184            .finish_non_exhaustive()
185    }
186}
187#[cfg(feature = "serialize")]
188impl serde::Serialize for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
189    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
190    where
191        S: serde::Serializer,
192    {
193        serializer.serialize_str(self.as_str())
194    }
195}
196impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
197    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
198        crate::Place::new(out)
199    }
200}
201
202impl miniserde::de::Visitor for crate::Place<PaymentIntentPaymentMethodOptionsLinkCaptureMethod> {
203    fn string(&mut self, s: &str) -> miniserde::Result<()> {
204        use std::str::FromStr;
205        self.out = Some(
206            PaymentIntentPaymentMethodOptionsLinkCaptureMethod::from_str(s).expect("infallible"),
207        );
208        Ok(())
209    }
210}
211
212stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsLinkCaptureMethod);
213#[cfg(feature = "deserialize")]
214impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
215    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
216        use std::str::FromStr;
217        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
218        Ok(Self::from_str(&s).expect("infallible"))
219    }
220}
221/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
222///
223/// 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.
224/// 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.
225///
226/// 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.
227///
228/// 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).
229#[derive(Clone, Eq, PartialEq)]
230#[non_exhaustive]
231pub enum PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
232    None,
233    OffSession,
234    /// An unrecognized value from Stripe. Should not be used as a request parameter.
235    Unknown(String),
236}
237impl PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
238    pub fn as_str(&self) -> &str {
239        use PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::*;
240        match self {
241            None => "none",
242            OffSession => "off_session",
243            Unknown(v) => v,
244        }
245    }
246}
247
248impl std::str::FromStr for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
249    type Err = std::convert::Infallible;
250    fn from_str(s: &str) -> Result<Self, Self::Err> {
251        use PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::*;
252        match s {
253            "none" => Ok(None),
254            "off_session" => Ok(OffSession),
255            v => {
256                tracing::warn!(
257                    "Unknown value '{}' for enum '{}'",
258                    v,
259                    "PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage"
260                );
261                Ok(Unknown(v.to_owned()))
262            }
263        }
264    }
265}
266impl std::fmt::Display for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
267    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
268        f.write_str(self.as_str())
269    }
270}
271
272#[cfg(not(feature = "redact-generated-debug"))]
273impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
274    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
275        f.write_str(self.as_str())
276    }
277}
278#[cfg(feature = "redact-generated-debug")]
279impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
280    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
281        f.debug_struct(stringify!(PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage))
282            .finish_non_exhaustive()
283    }
284}
285#[cfg(feature = "serialize")]
286impl serde::Serialize for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
287    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
288    where
289        S: serde::Serializer,
290    {
291        serializer.serialize_str(self.as_str())
292    }
293}
294impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
295    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
296        crate::Place::new(out)
297    }
298}
299
300impl miniserde::de::Visitor
301    for crate::Place<PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage>
302{
303    fn string(&mut self, s: &str) -> miniserde::Result<()> {
304        use std::str::FromStr;
305        self.out = Some(
306            PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::from_str(s).expect("infallible"),
307        );
308        Ok(())
309    }
310}
311
312stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage);
313#[cfg(feature = "deserialize")]
314impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
315    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
316        use std::str::FromStr;
317        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
318        Ok(Self::from_str(&s).expect("infallible"))
319    }
320}