stripe_shared/
three_d_secure_details_charge.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct ThreeDSecureDetailsCharge {
5    /// For authenticated transactions: how the customer was authenticated by
6    /// the issuing bank.
7    pub authentication_flow: Option<ThreeDSecureDetailsChargeAuthenticationFlow>,
8    /// The Electronic Commerce Indicator (ECI). A protocol-level field
9    /// indicating what degree of authentication was performed.
10    pub electronic_commerce_indicator: Option<ThreeDSecureDetailsChargeElectronicCommerceIndicator>,
11    /// The exemption requested via 3DS and accepted by the issuer at authentication time.
12    pub exemption_indicator: Option<ThreeDSecureDetailsChargeExemptionIndicator>,
13    /// Whether Stripe requested the value of `exemption_indicator` in the transaction. This will depend on
14    /// the outcome of Stripe's internal risk assessment.
15    pub exemption_indicator_applied: Option<bool>,
16    /// Indicates the outcome of 3D Secure authentication.
17    pub result: Option<ThreeDSecureDetailsChargeResult>,
18    /// Additional information about why 3D Secure succeeded or failed based
19    /// on the `result`.
20    pub result_reason: Option<ThreeDSecureDetailsChargeResultReason>,
21    /// The 3D Secure 1 XID or 3D Secure 2 Directory Server Transaction ID
22    /// (dsTransId) for this payment.
23    pub transaction_id: Option<String>,
24    /// The version of 3D Secure that was used.
25    pub version: Option<ThreeDSecureDetailsChargeVersion>,
26}
27#[doc(hidden)]
28pub struct ThreeDSecureDetailsChargeBuilder {
29    authentication_flow: Option<Option<ThreeDSecureDetailsChargeAuthenticationFlow>>,
30    electronic_commerce_indicator:
31        Option<Option<ThreeDSecureDetailsChargeElectronicCommerceIndicator>>,
32    exemption_indicator: Option<Option<ThreeDSecureDetailsChargeExemptionIndicator>>,
33    exemption_indicator_applied: Option<Option<bool>>,
34    result: Option<Option<ThreeDSecureDetailsChargeResult>>,
35    result_reason: Option<Option<ThreeDSecureDetailsChargeResultReason>>,
36    transaction_id: Option<Option<String>>,
37    version: Option<Option<ThreeDSecureDetailsChargeVersion>>,
38}
39
40#[allow(
41    unused_variables,
42    irrefutable_let_patterns,
43    clippy::let_unit_value,
44    clippy::match_single_binding,
45    clippy::single_match
46)]
47const _: () = {
48    use miniserde::de::{Map, Visitor};
49    use miniserde::json::Value;
50    use miniserde::{Deserialize, Result, make_place};
51    use stripe_types::miniserde_helpers::FromValueOpt;
52    use stripe_types::{MapBuilder, ObjectDeser};
53
54    make_place!(Place);
55
56    impl Deserialize for ThreeDSecureDetailsCharge {
57        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
58            Place::new(out)
59        }
60    }
61
62    struct Builder<'a> {
63        out: &'a mut Option<ThreeDSecureDetailsCharge>,
64        builder: ThreeDSecureDetailsChargeBuilder,
65    }
66
67    impl Visitor for Place<ThreeDSecureDetailsCharge> {
68        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
69            Ok(Box::new(Builder {
70                out: &mut self.out,
71                builder: ThreeDSecureDetailsChargeBuilder::deser_default(),
72            }))
73        }
74    }
75
76    impl MapBuilder for ThreeDSecureDetailsChargeBuilder {
77        type Out = ThreeDSecureDetailsCharge;
78        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
79            Ok(match k {
80                "authentication_flow" => Deserialize::begin(&mut self.authentication_flow),
81                "electronic_commerce_indicator" => {
82                    Deserialize::begin(&mut self.electronic_commerce_indicator)
83                }
84                "exemption_indicator" => Deserialize::begin(&mut self.exemption_indicator),
85                "exemption_indicator_applied" => {
86                    Deserialize::begin(&mut self.exemption_indicator_applied)
87                }
88                "result" => Deserialize::begin(&mut self.result),
89                "result_reason" => Deserialize::begin(&mut self.result_reason),
90                "transaction_id" => Deserialize::begin(&mut self.transaction_id),
91                "version" => Deserialize::begin(&mut self.version),
92                _ => <dyn Visitor>::ignore(),
93            })
94        }
95
96        fn deser_default() -> Self {
97            Self {
98                authentication_flow: Deserialize::default(),
99                electronic_commerce_indicator: Deserialize::default(),
100                exemption_indicator: Deserialize::default(),
101                exemption_indicator_applied: Deserialize::default(),
102                result: Deserialize::default(),
103                result_reason: Deserialize::default(),
104                transaction_id: Deserialize::default(),
105                version: Deserialize::default(),
106            }
107        }
108
109        fn take_out(&mut self) -> Option<Self::Out> {
110            let (
111                Some(authentication_flow),
112                Some(electronic_commerce_indicator),
113                Some(exemption_indicator),
114                Some(exemption_indicator_applied),
115                Some(result),
116                Some(result_reason),
117                Some(transaction_id),
118                Some(version),
119            ) = (
120                self.authentication_flow,
121                self.electronic_commerce_indicator,
122                self.exemption_indicator,
123                self.exemption_indicator_applied,
124                self.result,
125                self.result_reason,
126                self.transaction_id.take(),
127                self.version,
128            )
129            else {
130                return None;
131            };
132            Some(Self::Out {
133                authentication_flow,
134                electronic_commerce_indicator,
135                exemption_indicator,
136                exemption_indicator_applied,
137                result,
138                result_reason,
139                transaction_id,
140                version,
141            })
142        }
143    }
144
145    impl Map for Builder<'_> {
146        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
147            self.builder.key(k)
148        }
149
150        fn finish(&mut self) -> Result<()> {
151            *self.out = self.builder.take_out();
152            Ok(())
153        }
154    }
155
156    impl ObjectDeser for ThreeDSecureDetailsCharge {
157        type Builder = ThreeDSecureDetailsChargeBuilder;
158    }
159
160    impl FromValueOpt for ThreeDSecureDetailsCharge {
161        fn from_value(v: Value) -> Option<Self> {
162            let Value::Object(obj) = v else {
163                return None;
164            };
165            let mut b = ThreeDSecureDetailsChargeBuilder::deser_default();
166            for (k, v) in obj {
167                match k.as_str() {
168                    "authentication_flow" => b.authentication_flow = FromValueOpt::from_value(v),
169                    "electronic_commerce_indicator" => {
170                        b.electronic_commerce_indicator = FromValueOpt::from_value(v)
171                    }
172                    "exemption_indicator" => b.exemption_indicator = FromValueOpt::from_value(v),
173                    "exemption_indicator_applied" => {
174                        b.exemption_indicator_applied = FromValueOpt::from_value(v)
175                    }
176                    "result" => b.result = FromValueOpt::from_value(v),
177                    "result_reason" => b.result_reason = FromValueOpt::from_value(v),
178                    "transaction_id" => b.transaction_id = FromValueOpt::from_value(v),
179                    "version" => b.version = FromValueOpt::from_value(v),
180                    _ => {}
181                }
182            }
183            b.take_out()
184        }
185    }
186};
187/// For authenticated transactions: how the customer was authenticated by
188/// the issuing bank.
189#[derive(Copy, Clone, Eq, PartialEq)]
190pub enum ThreeDSecureDetailsChargeAuthenticationFlow {
191    Challenge,
192    Frictionless,
193}
194impl ThreeDSecureDetailsChargeAuthenticationFlow {
195    pub fn as_str(self) -> &'static str {
196        use ThreeDSecureDetailsChargeAuthenticationFlow::*;
197        match self {
198            Challenge => "challenge",
199            Frictionless => "frictionless",
200        }
201    }
202}
203
204impl std::str::FromStr for ThreeDSecureDetailsChargeAuthenticationFlow {
205    type Err = stripe_types::StripeParseError;
206    fn from_str(s: &str) -> Result<Self, Self::Err> {
207        use ThreeDSecureDetailsChargeAuthenticationFlow::*;
208        match s {
209            "challenge" => Ok(Challenge),
210            "frictionless" => Ok(Frictionless),
211            _ => Err(stripe_types::StripeParseError),
212        }
213    }
214}
215impl std::fmt::Display for ThreeDSecureDetailsChargeAuthenticationFlow {
216    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
217        f.write_str(self.as_str())
218    }
219}
220
221impl std::fmt::Debug for ThreeDSecureDetailsChargeAuthenticationFlow {
222    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
223        f.write_str(self.as_str())
224    }
225}
226#[cfg(feature = "serialize")]
227impl serde::Serialize for ThreeDSecureDetailsChargeAuthenticationFlow {
228    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
229    where
230        S: serde::Serializer,
231    {
232        serializer.serialize_str(self.as_str())
233    }
234}
235impl miniserde::Deserialize for ThreeDSecureDetailsChargeAuthenticationFlow {
236    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
237        crate::Place::new(out)
238    }
239}
240
241impl miniserde::de::Visitor for crate::Place<ThreeDSecureDetailsChargeAuthenticationFlow> {
242    fn string(&mut self, s: &str) -> miniserde::Result<()> {
243        use std::str::FromStr;
244        self.out = Some(
245            ThreeDSecureDetailsChargeAuthenticationFlow::from_str(s)
246                .map_err(|_| miniserde::Error)?,
247        );
248        Ok(())
249    }
250}
251
252stripe_types::impl_from_val_with_from_str!(ThreeDSecureDetailsChargeAuthenticationFlow);
253#[cfg(feature = "deserialize")]
254impl<'de> serde::Deserialize<'de> for ThreeDSecureDetailsChargeAuthenticationFlow {
255    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
256        use std::str::FromStr;
257        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
258        Self::from_str(&s).map_err(|_| {
259            serde::de::Error::custom(
260                "Unknown value for ThreeDSecureDetailsChargeAuthenticationFlow",
261            )
262        })
263    }
264}
265/// The Electronic Commerce Indicator (ECI). A protocol-level field
266/// indicating what degree of authentication was performed.
267#[derive(Copy, Clone, Eq, PartialEq)]
268pub enum ThreeDSecureDetailsChargeElectronicCommerceIndicator {
269    V01,
270    V02,
271    V05,
272    V06,
273    V07,
274}
275impl ThreeDSecureDetailsChargeElectronicCommerceIndicator {
276    pub fn as_str(self) -> &'static str {
277        use ThreeDSecureDetailsChargeElectronicCommerceIndicator::*;
278        match self {
279            V01 => "01",
280            V02 => "02",
281            V05 => "05",
282            V06 => "06",
283            V07 => "07",
284        }
285    }
286}
287
288impl std::str::FromStr for ThreeDSecureDetailsChargeElectronicCommerceIndicator {
289    type Err = stripe_types::StripeParseError;
290    fn from_str(s: &str) -> Result<Self, Self::Err> {
291        use ThreeDSecureDetailsChargeElectronicCommerceIndicator::*;
292        match s {
293            "01" => Ok(V01),
294            "02" => Ok(V02),
295            "05" => Ok(V05),
296            "06" => Ok(V06),
297            "07" => Ok(V07),
298            _ => Err(stripe_types::StripeParseError),
299        }
300    }
301}
302impl std::fmt::Display for ThreeDSecureDetailsChargeElectronicCommerceIndicator {
303    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
304        f.write_str(self.as_str())
305    }
306}
307
308impl std::fmt::Debug for ThreeDSecureDetailsChargeElectronicCommerceIndicator {
309    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
310        f.write_str(self.as_str())
311    }
312}
313#[cfg(feature = "serialize")]
314impl serde::Serialize for ThreeDSecureDetailsChargeElectronicCommerceIndicator {
315    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
316    where
317        S: serde::Serializer,
318    {
319        serializer.serialize_str(self.as_str())
320    }
321}
322impl miniserde::Deserialize for ThreeDSecureDetailsChargeElectronicCommerceIndicator {
323    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
324        crate::Place::new(out)
325    }
326}
327
328impl miniserde::de::Visitor for crate::Place<ThreeDSecureDetailsChargeElectronicCommerceIndicator> {
329    fn string(&mut self, s: &str) -> miniserde::Result<()> {
330        use std::str::FromStr;
331        self.out = Some(
332            ThreeDSecureDetailsChargeElectronicCommerceIndicator::from_str(s)
333                .map_err(|_| miniserde::Error)?,
334        );
335        Ok(())
336    }
337}
338
339stripe_types::impl_from_val_with_from_str!(ThreeDSecureDetailsChargeElectronicCommerceIndicator);
340#[cfg(feature = "deserialize")]
341impl<'de> serde::Deserialize<'de> for ThreeDSecureDetailsChargeElectronicCommerceIndicator {
342    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
343        use std::str::FromStr;
344        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
345        Self::from_str(&s).map_err(|_| {
346            serde::de::Error::custom(
347                "Unknown value for ThreeDSecureDetailsChargeElectronicCommerceIndicator",
348            )
349        })
350    }
351}
352/// The exemption requested via 3DS and accepted by the issuer at authentication time.
353#[derive(Copy, Clone, Eq, PartialEq)]
354pub enum ThreeDSecureDetailsChargeExemptionIndicator {
355    LowRisk,
356    None,
357}
358impl ThreeDSecureDetailsChargeExemptionIndicator {
359    pub fn as_str(self) -> &'static str {
360        use ThreeDSecureDetailsChargeExemptionIndicator::*;
361        match self {
362            LowRisk => "low_risk",
363            None => "none",
364        }
365    }
366}
367
368impl std::str::FromStr for ThreeDSecureDetailsChargeExemptionIndicator {
369    type Err = stripe_types::StripeParseError;
370    fn from_str(s: &str) -> Result<Self, Self::Err> {
371        use ThreeDSecureDetailsChargeExemptionIndicator::*;
372        match s {
373            "low_risk" => Ok(LowRisk),
374            "none" => Ok(None),
375            _ => Err(stripe_types::StripeParseError),
376        }
377    }
378}
379impl std::fmt::Display for ThreeDSecureDetailsChargeExemptionIndicator {
380    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
381        f.write_str(self.as_str())
382    }
383}
384
385impl std::fmt::Debug for ThreeDSecureDetailsChargeExemptionIndicator {
386    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
387        f.write_str(self.as_str())
388    }
389}
390#[cfg(feature = "serialize")]
391impl serde::Serialize for ThreeDSecureDetailsChargeExemptionIndicator {
392    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
393    where
394        S: serde::Serializer,
395    {
396        serializer.serialize_str(self.as_str())
397    }
398}
399impl miniserde::Deserialize for ThreeDSecureDetailsChargeExemptionIndicator {
400    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
401        crate::Place::new(out)
402    }
403}
404
405impl miniserde::de::Visitor for crate::Place<ThreeDSecureDetailsChargeExemptionIndicator> {
406    fn string(&mut self, s: &str) -> miniserde::Result<()> {
407        use std::str::FromStr;
408        self.out = Some(
409            ThreeDSecureDetailsChargeExemptionIndicator::from_str(s)
410                .map_err(|_| miniserde::Error)?,
411        );
412        Ok(())
413    }
414}
415
416stripe_types::impl_from_val_with_from_str!(ThreeDSecureDetailsChargeExemptionIndicator);
417#[cfg(feature = "deserialize")]
418impl<'de> serde::Deserialize<'de> for ThreeDSecureDetailsChargeExemptionIndicator {
419    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
420        use std::str::FromStr;
421        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
422        Self::from_str(&s).map_err(|_| {
423            serde::de::Error::custom(
424                "Unknown value for ThreeDSecureDetailsChargeExemptionIndicator",
425            )
426        })
427    }
428}
429/// Indicates the outcome of 3D Secure authentication.
430#[derive(Copy, Clone, Eq, PartialEq)]
431pub enum ThreeDSecureDetailsChargeResult {
432    AttemptAcknowledged,
433    Authenticated,
434    Exempted,
435    Failed,
436    NotSupported,
437    ProcessingError,
438}
439impl ThreeDSecureDetailsChargeResult {
440    pub fn as_str(self) -> &'static str {
441        use ThreeDSecureDetailsChargeResult::*;
442        match self {
443            AttemptAcknowledged => "attempt_acknowledged",
444            Authenticated => "authenticated",
445            Exempted => "exempted",
446            Failed => "failed",
447            NotSupported => "not_supported",
448            ProcessingError => "processing_error",
449        }
450    }
451}
452
453impl std::str::FromStr for ThreeDSecureDetailsChargeResult {
454    type Err = stripe_types::StripeParseError;
455    fn from_str(s: &str) -> Result<Self, Self::Err> {
456        use ThreeDSecureDetailsChargeResult::*;
457        match s {
458            "attempt_acknowledged" => Ok(AttemptAcknowledged),
459            "authenticated" => Ok(Authenticated),
460            "exempted" => Ok(Exempted),
461            "failed" => Ok(Failed),
462            "not_supported" => Ok(NotSupported),
463            "processing_error" => Ok(ProcessingError),
464            _ => Err(stripe_types::StripeParseError),
465        }
466    }
467}
468impl std::fmt::Display for ThreeDSecureDetailsChargeResult {
469    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
470        f.write_str(self.as_str())
471    }
472}
473
474impl std::fmt::Debug for ThreeDSecureDetailsChargeResult {
475    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
476        f.write_str(self.as_str())
477    }
478}
479#[cfg(feature = "serialize")]
480impl serde::Serialize for ThreeDSecureDetailsChargeResult {
481    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
482    where
483        S: serde::Serializer,
484    {
485        serializer.serialize_str(self.as_str())
486    }
487}
488impl miniserde::Deserialize for ThreeDSecureDetailsChargeResult {
489    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
490        crate::Place::new(out)
491    }
492}
493
494impl miniserde::de::Visitor for crate::Place<ThreeDSecureDetailsChargeResult> {
495    fn string(&mut self, s: &str) -> miniserde::Result<()> {
496        use std::str::FromStr;
497        self.out =
498            Some(ThreeDSecureDetailsChargeResult::from_str(s).map_err(|_| miniserde::Error)?);
499        Ok(())
500    }
501}
502
503stripe_types::impl_from_val_with_from_str!(ThreeDSecureDetailsChargeResult);
504#[cfg(feature = "deserialize")]
505impl<'de> serde::Deserialize<'de> for ThreeDSecureDetailsChargeResult {
506    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
507        use std::str::FromStr;
508        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
509        Self::from_str(&s).map_err(|_| {
510            serde::de::Error::custom("Unknown value for ThreeDSecureDetailsChargeResult")
511        })
512    }
513}
514/// Additional information about why 3D Secure succeeded or failed based
515/// on the `result`.
516#[derive(Copy, Clone, Eq, PartialEq)]
517pub enum ThreeDSecureDetailsChargeResultReason {
518    Abandoned,
519    Bypassed,
520    Canceled,
521    CardNotEnrolled,
522    NetworkNotSupported,
523    ProtocolError,
524    Rejected,
525}
526impl ThreeDSecureDetailsChargeResultReason {
527    pub fn as_str(self) -> &'static str {
528        use ThreeDSecureDetailsChargeResultReason::*;
529        match self {
530            Abandoned => "abandoned",
531            Bypassed => "bypassed",
532            Canceled => "canceled",
533            CardNotEnrolled => "card_not_enrolled",
534            NetworkNotSupported => "network_not_supported",
535            ProtocolError => "protocol_error",
536            Rejected => "rejected",
537        }
538    }
539}
540
541impl std::str::FromStr for ThreeDSecureDetailsChargeResultReason {
542    type Err = stripe_types::StripeParseError;
543    fn from_str(s: &str) -> Result<Self, Self::Err> {
544        use ThreeDSecureDetailsChargeResultReason::*;
545        match s {
546            "abandoned" => Ok(Abandoned),
547            "bypassed" => Ok(Bypassed),
548            "canceled" => Ok(Canceled),
549            "card_not_enrolled" => Ok(CardNotEnrolled),
550            "network_not_supported" => Ok(NetworkNotSupported),
551            "protocol_error" => Ok(ProtocolError),
552            "rejected" => Ok(Rejected),
553            _ => Err(stripe_types::StripeParseError),
554        }
555    }
556}
557impl std::fmt::Display for ThreeDSecureDetailsChargeResultReason {
558    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
559        f.write_str(self.as_str())
560    }
561}
562
563impl std::fmt::Debug for ThreeDSecureDetailsChargeResultReason {
564    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
565        f.write_str(self.as_str())
566    }
567}
568#[cfg(feature = "serialize")]
569impl serde::Serialize for ThreeDSecureDetailsChargeResultReason {
570    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
571    where
572        S: serde::Serializer,
573    {
574        serializer.serialize_str(self.as_str())
575    }
576}
577impl miniserde::Deserialize for ThreeDSecureDetailsChargeResultReason {
578    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
579        crate::Place::new(out)
580    }
581}
582
583impl miniserde::de::Visitor for crate::Place<ThreeDSecureDetailsChargeResultReason> {
584    fn string(&mut self, s: &str) -> miniserde::Result<()> {
585        use std::str::FromStr;
586        self.out =
587            Some(ThreeDSecureDetailsChargeResultReason::from_str(s).map_err(|_| miniserde::Error)?);
588        Ok(())
589    }
590}
591
592stripe_types::impl_from_val_with_from_str!(ThreeDSecureDetailsChargeResultReason);
593#[cfg(feature = "deserialize")]
594impl<'de> serde::Deserialize<'de> for ThreeDSecureDetailsChargeResultReason {
595    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
596        use std::str::FromStr;
597        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
598        Self::from_str(&s).map_err(|_| {
599            serde::de::Error::custom("Unknown value for ThreeDSecureDetailsChargeResultReason")
600        })
601    }
602}
603/// The version of 3D Secure that was used.
604#[derive(Copy, Clone, Eq, PartialEq)]
605pub enum ThreeDSecureDetailsChargeVersion {
606    V1_0_2,
607    V2_1_0,
608    V2_2_0,
609}
610impl ThreeDSecureDetailsChargeVersion {
611    pub fn as_str(self) -> &'static str {
612        use ThreeDSecureDetailsChargeVersion::*;
613        match self {
614            V1_0_2 => "1.0.2",
615            V2_1_0 => "2.1.0",
616            V2_2_0 => "2.2.0",
617        }
618    }
619}
620
621impl std::str::FromStr for ThreeDSecureDetailsChargeVersion {
622    type Err = stripe_types::StripeParseError;
623    fn from_str(s: &str) -> Result<Self, Self::Err> {
624        use ThreeDSecureDetailsChargeVersion::*;
625        match s {
626            "1.0.2" => Ok(V1_0_2),
627            "2.1.0" => Ok(V2_1_0),
628            "2.2.0" => Ok(V2_2_0),
629            _ => Err(stripe_types::StripeParseError),
630        }
631    }
632}
633impl std::fmt::Display for ThreeDSecureDetailsChargeVersion {
634    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
635        f.write_str(self.as_str())
636    }
637}
638
639impl std::fmt::Debug for ThreeDSecureDetailsChargeVersion {
640    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
641        f.write_str(self.as_str())
642    }
643}
644#[cfg(feature = "serialize")]
645impl serde::Serialize for ThreeDSecureDetailsChargeVersion {
646    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
647    where
648        S: serde::Serializer,
649    {
650        serializer.serialize_str(self.as_str())
651    }
652}
653impl miniserde::Deserialize for ThreeDSecureDetailsChargeVersion {
654    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
655        crate::Place::new(out)
656    }
657}
658
659impl miniserde::de::Visitor for crate::Place<ThreeDSecureDetailsChargeVersion> {
660    fn string(&mut self, s: &str) -> miniserde::Result<()> {
661        use std::str::FromStr;
662        self.out =
663            Some(ThreeDSecureDetailsChargeVersion::from_str(s).map_err(|_| miniserde::Error)?);
664        Ok(())
665    }
666}
667
668stripe_types::impl_from_val_with_from_str!(ThreeDSecureDetailsChargeVersion);
669#[cfg(feature = "deserialize")]
670impl<'de> serde::Deserialize<'de> for ThreeDSecureDetailsChargeVersion {
671    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
672        use std::str::FromStr;
673        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
674        Self::from_str(&s).map_err(|_| {
675            serde::de::Error::custom("Unknown value for ThreeDSecureDetailsChargeVersion")
676        })
677    }
678}