Skip to main content

stripe_shared/
issuing_authorization_three_d_secure.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 IssuingAuthorizationThreeDSecure {
6    /// The outcome of the 3D Secure authentication request.
7    pub result: IssuingAuthorizationThreeDSecureResult,
8}
9#[cfg(feature = "redact-generated-debug")]
10impl std::fmt::Debug for IssuingAuthorizationThreeDSecure {
11    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
12        f.debug_struct("IssuingAuthorizationThreeDSecure").finish_non_exhaustive()
13    }
14}
15#[doc(hidden)]
16pub struct IssuingAuthorizationThreeDSecureBuilder {
17    result: Option<IssuingAuthorizationThreeDSecureResult>,
18}
19
20#[allow(
21    unused_variables,
22    irrefutable_let_patterns,
23    clippy::let_unit_value,
24    clippy::match_single_binding,
25    clippy::single_match
26)]
27const _: () = {
28    use miniserde::de::{Map, Visitor};
29    use miniserde::json::Value;
30    use miniserde::{Deserialize, Result, make_place};
31    use stripe_types::miniserde_helpers::FromValueOpt;
32    use stripe_types::{MapBuilder, ObjectDeser};
33
34    make_place!(Place);
35
36    impl Deserialize for IssuingAuthorizationThreeDSecure {
37        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
38            Place::new(out)
39        }
40    }
41
42    struct Builder<'a> {
43        out: &'a mut Option<IssuingAuthorizationThreeDSecure>,
44        builder: IssuingAuthorizationThreeDSecureBuilder,
45    }
46
47    impl Visitor for Place<IssuingAuthorizationThreeDSecure> {
48        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
49            Ok(Box::new(Builder {
50                out: &mut self.out,
51                builder: IssuingAuthorizationThreeDSecureBuilder::deser_default(),
52            }))
53        }
54    }
55
56    impl MapBuilder for IssuingAuthorizationThreeDSecureBuilder {
57        type Out = IssuingAuthorizationThreeDSecure;
58        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
59            Ok(match k {
60                "result" => Deserialize::begin(&mut self.result),
61                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self { result: None }
67        }
68
69        fn take_out(&mut self) -> Option<Self::Out> {
70            let (Some(result),) = (self.result.take(),) else {
71                return None;
72            };
73            Some(Self::Out { result })
74        }
75    }
76
77    impl Map for Builder<'_> {
78        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
79            self.builder.key(k)
80        }
81
82        fn finish(&mut self) -> Result<()> {
83            *self.out = self.builder.take_out();
84            Ok(())
85        }
86    }
87
88    impl ObjectDeser for IssuingAuthorizationThreeDSecure {
89        type Builder = IssuingAuthorizationThreeDSecureBuilder;
90    }
91
92    impl FromValueOpt for IssuingAuthorizationThreeDSecure {
93        fn from_value(v: Value) -> Option<Self> {
94            let Value::Object(obj) = v else {
95                return None;
96            };
97            let mut b = IssuingAuthorizationThreeDSecureBuilder::deser_default();
98            for (k, v) in obj {
99                match k.as_str() {
100                    "result" => b.result = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// The outcome of the 3D Secure authentication request.
109#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum IssuingAuthorizationThreeDSecureResult {
112    AttemptAcknowledged,
113    Authenticated,
114    Failed,
115    Required,
116    /// An unrecognized value from Stripe. Should not be used as a request parameter.
117    Unknown(String),
118}
119impl IssuingAuthorizationThreeDSecureResult {
120    pub fn as_str(&self) -> &str {
121        use IssuingAuthorizationThreeDSecureResult::*;
122        match self {
123            AttemptAcknowledged => "attempt_acknowledged",
124            Authenticated => "authenticated",
125            Failed => "failed",
126            Required => "required",
127            Unknown(v) => v,
128        }
129    }
130}
131
132impl std::str::FromStr for IssuingAuthorizationThreeDSecureResult {
133    type Err = std::convert::Infallible;
134    fn from_str(s: &str) -> Result<Self, Self::Err> {
135        use IssuingAuthorizationThreeDSecureResult::*;
136        match s {
137            "attempt_acknowledged" => Ok(AttemptAcknowledged),
138            "authenticated" => Ok(Authenticated),
139            "failed" => Ok(Failed),
140            "required" => Ok(Required),
141            v => {
142                tracing::warn!(
143                    "Unknown value '{}' for enum '{}'",
144                    v,
145                    "IssuingAuthorizationThreeDSecureResult"
146                );
147                Ok(Unknown(v.to_owned()))
148            }
149        }
150    }
151}
152impl std::fmt::Display for IssuingAuthorizationThreeDSecureResult {
153    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154        f.write_str(self.as_str())
155    }
156}
157
158#[cfg(not(feature = "redact-generated-debug"))]
159impl std::fmt::Debug for IssuingAuthorizationThreeDSecureResult {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164#[cfg(feature = "redact-generated-debug")]
165impl std::fmt::Debug for IssuingAuthorizationThreeDSecureResult {
166    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167        f.debug_struct(stringify!(IssuingAuthorizationThreeDSecureResult)).finish_non_exhaustive()
168    }
169}
170#[cfg(feature = "serialize")]
171impl serde::Serialize for IssuingAuthorizationThreeDSecureResult {
172    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
173    where
174        S: serde::Serializer,
175    {
176        serializer.serialize_str(self.as_str())
177    }
178}
179impl miniserde::Deserialize for IssuingAuthorizationThreeDSecureResult {
180    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
181        crate::Place::new(out)
182    }
183}
184
185impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationThreeDSecureResult> {
186    fn string(&mut self, s: &str) -> miniserde::Result<()> {
187        use std::str::FromStr;
188        self.out = Some(IssuingAuthorizationThreeDSecureResult::from_str(s).expect("infallible"));
189        Ok(())
190    }
191}
192
193stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationThreeDSecureResult);
194#[cfg(feature = "deserialize")]
195impl<'de> serde::Deserialize<'de> for IssuingAuthorizationThreeDSecureResult {
196    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
197        use std::str::FromStr;
198        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
199        Ok(Self::from_str(&s).expect("infallible"))
200    }
201}