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, self.persistent_token.take(), self.setup_future_usage)
84            else {
85                return None;
86            };
87            Some(Self::Out { capture_method, persistent_token, setup_future_usage })
88        }
89    }
90
91    impl Map for Builder<'_> {
92        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93            self.builder.key(k)
94        }
95
96        fn finish(&mut self) -> Result<()> {
97            *self.out = self.builder.take_out();
98            Ok(())
99        }
100    }
101
102    impl ObjectDeser for PaymentIntentPaymentMethodOptionsLink {
103        type Builder = PaymentIntentPaymentMethodOptionsLinkBuilder;
104    }
105
106    impl FromValueOpt for PaymentIntentPaymentMethodOptionsLink {
107        fn from_value(v: Value) -> Option<Self> {
108            let Value::Object(obj) = v else {
109                return None;
110            };
111            let mut b = PaymentIntentPaymentMethodOptionsLinkBuilder::deser_default();
112            for (k, v) in obj {
113                match k.as_str() {
114                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
115                    "persistent_token" => b.persistent_token = FromValueOpt::from_value(v),
116                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
117                    _ => {}
118                }
119            }
120            b.take_out()
121        }
122    }
123};
124/// Controls when the funds will be captured from the customer's account.
125#[derive(Copy, Clone, Eq, PartialEq)]
126pub enum PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
127    Manual,
128}
129impl PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
130    pub fn as_str(self) -> &'static str {
131        use PaymentIntentPaymentMethodOptionsLinkCaptureMethod::*;
132        match self {
133            Manual => "manual",
134        }
135    }
136}
137
138impl std::str::FromStr for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
139    type Err = stripe_types::StripeParseError;
140    fn from_str(s: &str) -> Result<Self, Self::Err> {
141        use PaymentIntentPaymentMethodOptionsLinkCaptureMethod::*;
142        match s {
143            "manual" => Ok(Manual),
144            _ => Err(stripe_types::StripeParseError),
145        }
146    }
147}
148impl std::fmt::Display for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
149    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
150        f.write_str(self.as_str())
151    }
152}
153
154impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
155    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156        f.write_str(self.as_str())
157    }
158}
159#[cfg(feature = "serialize")]
160impl serde::Serialize for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
161    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
162    where
163        S: serde::Serializer,
164    {
165        serializer.serialize_str(self.as_str())
166    }
167}
168impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
169    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
170        crate::Place::new(out)
171    }
172}
173
174impl miniserde::de::Visitor for crate::Place<PaymentIntentPaymentMethodOptionsLinkCaptureMethod> {
175    fn string(&mut self, s: &str) -> miniserde::Result<()> {
176        use std::str::FromStr;
177        self.out = Some(
178            PaymentIntentPaymentMethodOptionsLinkCaptureMethod::from_str(s)
179                .map_err(|_| miniserde::Error)?,
180        );
181        Ok(())
182    }
183}
184
185stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsLinkCaptureMethod);
186#[cfg(feature = "deserialize")]
187impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsLinkCaptureMethod {
188    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
189        use std::str::FromStr;
190        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
191        Self::from_str(&s).map_err(|_| {
192            serde::de::Error::custom(
193                "Unknown value for PaymentIntentPaymentMethodOptionsLinkCaptureMethod",
194            )
195        })
196    }
197}
198/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
199///
200/// 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.
201/// 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.
202///
203/// 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.
204///
205/// 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).
206#[derive(Copy, Clone, Eq, PartialEq)]
207pub enum PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
208    None,
209    OffSession,
210}
211impl PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
212    pub fn as_str(self) -> &'static str {
213        use PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::*;
214        match self {
215            None => "none",
216            OffSession => "off_session",
217        }
218    }
219}
220
221impl std::str::FromStr for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
222    type Err = stripe_types::StripeParseError;
223    fn from_str(s: &str) -> Result<Self, Self::Err> {
224        use PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::*;
225        match s {
226            "none" => Ok(None),
227            "off_session" => Ok(OffSession),
228            _ => Err(stripe_types::StripeParseError),
229        }
230    }
231}
232impl std::fmt::Display for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
233    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
234        f.write_str(self.as_str())
235    }
236}
237
238impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
239    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
240        f.write_str(self.as_str())
241    }
242}
243#[cfg(feature = "serialize")]
244impl serde::Serialize for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
245    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
246    where
247        S: serde::Serializer,
248    {
249        serializer.serialize_str(self.as_str())
250    }
251}
252impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
253    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
254        crate::Place::new(out)
255    }
256}
257
258impl miniserde::de::Visitor
259    for crate::Place<PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage>
260{
261    fn string(&mut self, s: &str) -> miniserde::Result<()> {
262        use std::str::FromStr;
263        self.out = Some(
264            PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage::from_str(s)
265                .map_err(|_| miniserde::Error)?,
266        );
267        Ok(())
268    }
269}
270
271stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage);
272#[cfg(feature = "deserialize")]
273impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage {
274    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
275        use std::str::FromStr;
276        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
277        Self::from_str(&s).map_err(|_| {
278            serde::de::Error::custom(
279                "Unknown value for PaymentIntentPaymentMethodOptionsLinkSetupFutureUsage",
280            )
281        })
282    }
283}