Skip to main content

stripe_shared/
setup_intent_payment_method_options_card.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 SetupIntentPaymentMethodOptionsCard {
6    /// Configuration options for setting up an eMandate for cards issued in India.
7    pub mandate_options: Option<stripe_shared::SetupIntentPaymentMethodOptionsCardMandateOptions>,
8    /// Selected network to process this SetupIntent on.
9    /// Depends on the available networks of the card attached to the setup intent.
10    /// Can be only set confirm-time.
11    pub network: Option<SetupIntentPaymentMethodOptionsCardNetwork>,
12    /// We strongly recommend that you rely on our SCA Engine to automatically prompt your customers for authentication based on risk level and [other requirements](https://docs.stripe.com/strong-customer-authentication).
13    /// However, if you wish to request 3D Secure based on logic from your own fraud engine, provide this option.
14    /// If not provided, this value defaults to `automatic`.
15    /// Read our guide on [manually requesting 3D Secure](https://docs.stripe.com/payments/3d-secure/authentication-flow#manual-three-ds) for more information on how this configuration interacts with Radar and our SCA Engine.
16    pub request_three_d_secure: Option<SetupIntentPaymentMethodOptionsCardRequestThreeDSecure>,
17}
18#[cfg(feature = "redact-generated-debug")]
19impl std::fmt::Debug for SetupIntentPaymentMethodOptionsCard {
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        f.debug_struct("SetupIntentPaymentMethodOptionsCard").finish_non_exhaustive()
22    }
23}
24#[doc(hidden)]
25pub struct SetupIntentPaymentMethodOptionsCardBuilder {
26    mandate_options:
27        Option<Option<stripe_shared::SetupIntentPaymentMethodOptionsCardMandateOptions>>,
28    network: Option<Option<SetupIntentPaymentMethodOptionsCardNetwork>>,
29    request_three_d_secure: Option<Option<SetupIntentPaymentMethodOptionsCardRequestThreeDSecure>>,
30}
31
32#[allow(
33    unused_variables,
34    irrefutable_let_patterns,
35    clippy::let_unit_value,
36    clippy::match_single_binding,
37    clippy::single_match
38)]
39const _: () = {
40    use miniserde::de::{Map, Visitor};
41    use miniserde::json::Value;
42    use miniserde::{Deserialize, Result, make_place};
43    use stripe_types::miniserde_helpers::FromValueOpt;
44    use stripe_types::{MapBuilder, ObjectDeser};
45
46    make_place!(Place);
47
48    impl Deserialize for SetupIntentPaymentMethodOptionsCard {
49        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50            Place::new(out)
51        }
52    }
53
54    struct Builder<'a> {
55        out: &'a mut Option<SetupIntentPaymentMethodOptionsCard>,
56        builder: SetupIntentPaymentMethodOptionsCardBuilder,
57    }
58
59    impl Visitor for Place<SetupIntentPaymentMethodOptionsCard> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: SetupIntentPaymentMethodOptionsCardBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for SetupIntentPaymentMethodOptionsCardBuilder {
69        type Out = SetupIntentPaymentMethodOptionsCard;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
73                "network" => Deserialize::begin(&mut self.network),
74                "request_three_d_secure" => Deserialize::begin(&mut self.request_three_d_secure),
75                _ => <dyn Visitor>::ignore(),
76            })
77        }
78
79        fn deser_default() -> Self {
80            Self {
81                mandate_options: Deserialize::default(),
82                network: Deserialize::default(),
83                request_three_d_secure: Deserialize::default(),
84            }
85        }
86
87        fn take_out(&mut self) -> Option<Self::Out> {
88            let (Some(mandate_options), Some(network), Some(request_three_d_secure)) = (
89                self.mandate_options.take(),
90                self.network.take(),
91                self.request_three_d_secure.take(),
92            ) else {
93                return None;
94            };
95            Some(Self::Out { mandate_options, network, request_three_d_secure })
96        }
97    }
98
99    impl Map for Builder<'_> {
100        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
101            self.builder.key(k)
102        }
103
104        fn finish(&mut self) -> Result<()> {
105            *self.out = self.builder.take_out();
106            Ok(())
107        }
108    }
109
110    impl ObjectDeser for SetupIntentPaymentMethodOptionsCard {
111        type Builder = SetupIntentPaymentMethodOptionsCardBuilder;
112    }
113
114    impl FromValueOpt for SetupIntentPaymentMethodOptionsCard {
115        fn from_value(v: Value) -> Option<Self> {
116            let Value::Object(obj) = v else {
117                return None;
118            };
119            let mut b = SetupIntentPaymentMethodOptionsCardBuilder::deser_default();
120            for (k, v) in obj {
121                match k.as_str() {
122                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
123                    "network" => b.network = FromValueOpt::from_value(v),
124                    "request_three_d_secure" => {
125                        b.request_three_d_secure = FromValueOpt::from_value(v)
126                    }
127                    _ => {}
128                }
129            }
130            b.take_out()
131        }
132    }
133};
134/// Selected network to process this SetupIntent on.
135/// Depends on the available networks of the card attached to the setup intent.
136/// Can be only set confirm-time.
137#[derive(Clone, Eq, PartialEq)]
138#[non_exhaustive]
139pub enum SetupIntentPaymentMethodOptionsCardNetwork {
140    Amex,
141    CartesBancaires,
142    Diners,
143    Discover,
144    EftposAu,
145    Girocard,
146    Interac,
147    Jcb,
148    Link,
149    Mastercard,
150    Unionpay,
151    Unknown,
152    Visa,
153    /// An unrecognized value from Stripe. Should not be used as a request parameter.
154    /// This variant is prefixed with an underscore to avoid conflicts with Stripe's 'Unknown' variant.
155    _Unknown(String),
156}
157impl SetupIntentPaymentMethodOptionsCardNetwork {
158    pub fn as_str(&self) -> &str {
159        use SetupIntentPaymentMethodOptionsCardNetwork::*;
160        match self {
161            Amex => "amex",
162            CartesBancaires => "cartes_bancaires",
163            Diners => "diners",
164            Discover => "discover",
165            EftposAu => "eftpos_au",
166            Girocard => "girocard",
167            Interac => "interac",
168            Jcb => "jcb",
169            Link => "link",
170            Mastercard => "mastercard",
171            Unionpay => "unionpay",
172            Unknown => "unknown",
173            Visa => "visa",
174            _Unknown(v) => v,
175        }
176    }
177}
178
179impl std::str::FromStr for SetupIntentPaymentMethodOptionsCardNetwork {
180    type Err = std::convert::Infallible;
181    fn from_str(s: &str) -> Result<Self, Self::Err> {
182        use SetupIntentPaymentMethodOptionsCardNetwork::*;
183        match s {
184            "amex" => Ok(Amex),
185            "cartes_bancaires" => Ok(CartesBancaires),
186            "diners" => Ok(Diners),
187            "discover" => Ok(Discover),
188            "eftpos_au" => Ok(EftposAu),
189            "girocard" => Ok(Girocard),
190            "interac" => Ok(Interac),
191            "jcb" => Ok(Jcb),
192            "link" => Ok(Link),
193            "mastercard" => Ok(Mastercard),
194            "unionpay" => Ok(Unionpay),
195            "unknown" => Ok(Unknown),
196            "visa" => Ok(Visa),
197            v => {
198                tracing::warn!(
199                    "Unknown value '{}' for enum '{}'",
200                    v,
201                    "SetupIntentPaymentMethodOptionsCardNetwork"
202                );
203                Ok(_Unknown(v.to_owned()))
204            }
205        }
206    }
207}
208impl std::fmt::Display for SetupIntentPaymentMethodOptionsCardNetwork {
209    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
210        f.write_str(self.as_str())
211    }
212}
213
214#[cfg(not(feature = "redact-generated-debug"))]
215impl std::fmt::Debug for SetupIntentPaymentMethodOptionsCardNetwork {
216    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
217        f.write_str(self.as_str())
218    }
219}
220#[cfg(feature = "redact-generated-debug")]
221impl std::fmt::Debug for SetupIntentPaymentMethodOptionsCardNetwork {
222    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
223        f.debug_struct(stringify!(SetupIntentPaymentMethodOptionsCardNetwork))
224            .finish_non_exhaustive()
225    }
226}
227#[cfg(feature = "serialize")]
228impl serde::Serialize for SetupIntentPaymentMethodOptionsCardNetwork {
229    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
230    where
231        S: serde::Serializer,
232    {
233        serializer.serialize_str(self.as_str())
234    }
235}
236impl miniserde::Deserialize for SetupIntentPaymentMethodOptionsCardNetwork {
237    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
238        crate::Place::new(out)
239    }
240}
241
242impl miniserde::de::Visitor for crate::Place<SetupIntentPaymentMethodOptionsCardNetwork> {
243    fn string(&mut self, s: &str) -> miniserde::Result<()> {
244        use std::str::FromStr;
245        self.out =
246            Some(SetupIntentPaymentMethodOptionsCardNetwork::from_str(s).expect("infallible"));
247        Ok(())
248    }
249}
250
251stripe_types::impl_from_val_with_from_str!(SetupIntentPaymentMethodOptionsCardNetwork);
252#[cfg(feature = "deserialize")]
253impl<'de> serde::Deserialize<'de> for SetupIntentPaymentMethodOptionsCardNetwork {
254    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
255        use std::str::FromStr;
256        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
257        Ok(Self::from_str(&s).expect("infallible"))
258    }
259}
260/// We strongly recommend that you rely on our SCA Engine to automatically prompt your customers for authentication based on risk level and [other requirements](https://docs.stripe.com/strong-customer-authentication).
261/// However, if you wish to request 3D Secure based on logic from your own fraud engine, provide this option.
262/// If not provided, this value defaults to `automatic`.
263/// Read our guide on [manually requesting 3D Secure](https://docs.stripe.com/payments/3d-secure/authentication-flow#manual-three-ds) for more information on how this configuration interacts with Radar and our SCA Engine.
264#[derive(Clone, Eq, PartialEq)]
265#[non_exhaustive]
266pub enum SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
267    Any,
268    Automatic,
269    Challenge,
270    /// An unrecognized value from Stripe. Should not be used as a request parameter.
271    Unknown(String),
272}
273impl SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
274    pub fn as_str(&self) -> &str {
275        use SetupIntentPaymentMethodOptionsCardRequestThreeDSecure::*;
276        match self {
277            Any => "any",
278            Automatic => "automatic",
279            Challenge => "challenge",
280            Unknown(v) => v,
281        }
282    }
283}
284
285impl std::str::FromStr for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
286    type Err = std::convert::Infallible;
287    fn from_str(s: &str) -> Result<Self, Self::Err> {
288        use SetupIntentPaymentMethodOptionsCardRequestThreeDSecure::*;
289        match s {
290            "any" => Ok(Any),
291            "automatic" => Ok(Automatic),
292            "challenge" => Ok(Challenge),
293            v => {
294                tracing::warn!(
295                    "Unknown value '{}' for enum '{}'",
296                    v,
297                    "SetupIntentPaymentMethodOptionsCardRequestThreeDSecure"
298                );
299                Ok(Unknown(v.to_owned()))
300            }
301        }
302    }
303}
304impl std::fmt::Display for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
305    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
306        f.write_str(self.as_str())
307    }
308}
309
310#[cfg(not(feature = "redact-generated-debug"))]
311impl std::fmt::Debug for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
312    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
313        f.write_str(self.as_str())
314    }
315}
316#[cfg(feature = "redact-generated-debug")]
317impl std::fmt::Debug for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
318    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
319        f.debug_struct(stringify!(SetupIntentPaymentMethodOptionsCardRequestThreeDSecure))
320            .finish_non_exhaustive()
321    }
322}
323#[cfg(feature = "serialize")]
324impl serde::Serialize for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
325    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
326    where
327        S: serde::Serializer,
328    {
329        serializer.serialize_str(self.as_str())
330    }
331}
332impl miniserde::Deserialize for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
333    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
334        crate::Place::new(out)
335    }
336}
337
338impl miniserde::de::Visitor
339    for crate::Place<SetupIntentPaymentMethodOptionsCardRequestThreeDSecure>
340{
341    fn string(&mut self, s: &str) -> miniserde::Result<()> {
342        use std::str::FromStr;
343        self.out = Some(
344            SetupIntentPaymentMethodOptionsCardRequestThreeDSecure::from_str(s)
345                .expect("infallible"),
346        );
347        Ok(())
348    }
349}
350
351stripe_types::impl_from_val_with_from_str!(SetupIntentPaymentMethodOptionsCardRequestThreeDSecure);
352#[cfg(feature = "deserialize")]
353impl<'de> serde::Deserialize<'de> for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure {
354    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
355        use std::str::FromStr;
356        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
357        Ok(Self::from_str(&s).expect("infallible"))
358    }
359}