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