stripe_shared/
payment_intent_payment_method_options_link.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentPaymentMethodOptionsLink {
5    /// Controls when the funds will be captured from the customer's account.
6    pub capture_method: Option<PaymentIntentPaymentMethodOptionsLinkCaptureMethod>,
7    /// \[Deprecated\] This is a legacy parameter that no longer has any function.
8    pub persistent_token: Option<String>,
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<PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage>,
18}
19#[doc(hidden)]
20pub struct PaymentIntentPaymentMethodOptionsLinkBuilder {
21    capture_method: Option<Option<PaymentIntentPaymentMethodOptionsLinkCaptureMethod>>,
22    persistent_token: Option<Option<String>>,
23    setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage>>,
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::{Deserialize, Result, make_place};
37    use stripe_types::miniserde_helpers::FromValueOpt;
38    use stripe_types::{MapBuilder, ObjectDeser};
39
40    make_place!(Place);
41
42    impl Deserialize for PaymentIntentPaymentMethodOptionsLink {
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<PaymentIntentPaymentMethodOptionsLink>,
50        builder: PaymentIntentPaymentMethodOptionsLinkBuilder,
51    }
52
53    impl Visitor for Place<PaymentIntentPaymentMethodOptionsLink> {
54        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55            Ok(Box::new(Builder {
56                out: &mut self.out,
57                builder: PaymentIntentPaymentMethodOptionsLinkBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for PaymentIntentPaymentMethodOptionsLinkBuilder {
63        type Out = PaymentIntentPaymentMethodOptionsLink;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "capture_method" => Deserialize::begin(&mut self.capture_method),
67                "persistent_token" => Deserialize::begin(&mut self.persistent_token),
68                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
69                _ => <dyn Visitor>::ignore(),
70            })
71        }
72
73        fn deser_default() -> Self {
74            Self {
75                capture_method: Deserialize::default(),
76                persistent_token: Deserialize::default(),
77                setup_future_usage: Deserialize::default(),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (Some(capture_method), Some(persistent_token), Some(setup_future_usage)) = (
83                self.capture_method.take(),
84                self.persistent_token.take(),
85                self.setup_future_usage.take(),
86            ) else {
87                return None;
88            };
89            Some(Self::Out { capture_method, persistent_token, setup_future_usage })
90        }
91    }
92
93    impl Map for Builder<'_> {
94        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
95            self.builder.key(k)
96        }
97
98        fn finish(&mut self) -> Result<()> {
99            *self.out = self.builder.take_out();
100            Ok(())
101        }
102    }
103
104    impl ObjectDeser for PaymentIntentPaymentMethodOptionsLink {
105        type Builder = PaymentIntentPaymentMethodOptionsLinkBuilder;
106    }
107
108    impl FromValueOpt for PaymentIntentPaymentMethodOptionsLink {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = PaymentIntentPaymentMethodOptionsLinkBuilder::deser_default();
114            for (k, v) in obj {
115                match k.as_str() {
116                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
117                    "persistent_token" => b.persistent_token = FromValueOpt::from_value(v),
118                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
119                    _ => {}
120                }
121            }
122            b.take_out()
123        }
124    }
125};
126/// Controls when the funds will be captured from the customer's account.
127#[derive(Clone, Eq, PartialEq)]
128#[non_exhaustive]
129pub enum PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
130    Manual,
131    /// An unrecognized value from Stripe. Should not be used as a request parameter.
132    Unknown(String),
133}
134impl PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
135    pub fn as_str(&self) -> &str {
136        use PaymentIntentPaymentMethodOptionsLinkCaptureMethod::*;
137        match self {
138            Manual => "manual",
139            Unknown(v) => v,
140        }
141    }
142}
143
144impl std::str::FromStr for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
145    type Err = std::convert::Infallible;
146    fn from_str(s: &str) -> Result<Self, Self::Err> {
147        use PaymentIntentPaymentMethodOptionsLinkCaptureMethod::*;
148        match s {
149            "manual" => Ok(Manual),
150            v => {
151                tracing::warn!(
152                    "Unknown value '{}' for enum '{}'",
153                    v,
154                    "PaymentIntentPaymentMethodOptionsLinkCaptureMethod"
155                );
156                Ok(Unknown(v.to_owned()))
157            }
158        }
159    }
160}
161impl std::fmt::Display for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
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 PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
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 PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
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 PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
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<PaymentIntentPaymentMethodOptionsLinkCaptureMethod> {
188    fn string(&mut self, s: &str) -> miniserde::Result<()> {
189        use std::str::FromStr;
190        self.out = Some(
191            PaymentIntentPaymentMethodOptionsLinkCaptureMethod::from_str(s).expect("infallible"),
192        );
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsLinkCaptureMethod);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
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}
206/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
207///
208/// 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.
209/// 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.
210///
211/// 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.
212///
213/// 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).
214#[derive(Clone, Eq, PartialEq)]
215#[non_exhaustive]
216pub enum PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
217    None,
218    OffSession,
219    /// An unrecognized value from Stripe. Should not be used as a request parameter.
220    Unknown(String),
221}
222impl PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
223    pub fn as_str(&self) -> &str {
224        use PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::*;
225        match self {
226            None => "none",
227            OffSession => "off_session",
228            Unknown(v) => v,
229        }
230    }
231}
232
233impl std::str::FromStr for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
234    type Err = std::convert::Infallible;
235    fn from_str(s: &str) -> Result<Self, Self::Err> {
236        use PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::*;
237        match s {
238            "none" => Ok(None),
239            "off_session" => Ok(OffSession),
240            v => {
241                tracing::warn!(
242                    "Unknown value '{}' for enum '{}'",
243                    v,
244                    "PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage"
245                );
246                Ok(Unknown(v.to_owned()))
247            }
248        }
249    }
250}
251impl std::fmt::Display for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
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 PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
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 PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
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 PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
272    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
273        crate::Place::new(out)
274    }
275}
276
277impl miniserde::de::Visitor
278    for crate::Place<PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage>
279{
280    fn string(&mut self, s: &str) -> miniserde::Result<()> {
281        use std::str::FromStr;
282        self.out = Some(
283            PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::from_str(s).expect("infallible"),
284        );
285        Ok(())
286    }
287}
288
289stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage);
290#[cfg(feature = "deserialize")]
291impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
292    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
293        use std::str::FromStr;
294        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
295        Ok(Self::from_str(&s).expect("infallible"))
296    }
297}