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