stripe_misc/
gelato_session_last_error.rs

1/// Shows last VerificationSession error
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct GelatoSessionLastError {
6    /// A short machine-readable string giving the reason for the verification or user-session failure.
7    pub code: Option<GelatoSessionLastErrorCode>,
8    /// A message that explains the reason for verification or user-session failure.
9    pub reason: Option<String>,
10}
11#[doc(hidden)]
12pub struct GelatoSessionLastErrorBuilder {
13    code: Option<Option<GelatoSessionLastErrorCode>>,
14    reason: Option<Option<String>>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{Deserialize, Result, make_place};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for GelatoSessionLastError {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<GelatoSessionLastError>,
41        builder: GelatoSessionLastErrorBuilder,
42    }
43
44    impl Visitor for Place<GelatoSessionLastError> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: GelatoSessionLastErrorBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for GelatoSessionLastErrorBuilder {
54        type Out = GelatoSessionLastError;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "code" => Deserialize::begin(&mut self.code),
58                "reason" => Deserialize::begin(&mut self.reason),
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { code: Deserialize::default(), reason: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(code), Some(reason)) = (self.code.take(), self.reason.take()) else {
69                return None;
70            };
71            Some(Self::Out { code, reason })
72        }
73    }
74
75    impl Map for Builder<'_> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for GelatoSessionLastError {
87        type Builder = GelatoSessionLastErrorBuilder;
88    }
89
90    impl FromValueOpt for GelatoSessionLastError {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = GelatoSessionLastErrorBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "code" => b.code = FromValueOpt::from_value(v),
99                    "reason" => b.reason = FromValueOpt::from_value(v),
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};
107/// A short machine-readable string giving the reason for the verification or user-session failure.
108#[derive(Clone, Eq, PartialEq)]
109#[non_exhaustive]
110pub enum GelatoSessionLastErrorCode {
111    Abandoned,
112    ConsentDeclined,
113    CountryNotSupported,
114    DeviceNotSupported,
115    DocumentExpired,
116    DocumentTypeNotSupported,
117    DocumentUnverifiedOther,
118    EmailUnverifiedOther,
119    EmailVerificationDeclined,
120    IdNumberInsufficientDocumentData,
121    IdNumberMismatch,
122    IdNumberUnverifiedOther,
123    PhoneUnverifiedOther,
124    PhoneVerificationDeclined,
125    SelfieDocumentMissingPhoto,
126    SelfieFaceMismatch,
127    SelfieManipulated,
128    SelfieUnverifiedOther,
129    UnderSupportedAge,
130    /// An unrecognized value from Stripe. Should not be used as a request parameter.
131    Unknown(String),
132}
133impl GelatoSessionLastErrorCode {
134    pub fn as_str(&self) -> &str {
135        use GelatoSessionLastErrorCode::*;
136        match self {
137            Abandoned => "abandoned",
138            ConsentDeclined => "consent_declined",
139            CountryNotSupported => "country_not_supported",
140            DeviceNotSupported => "device_not_supported",
141            DocumentExpired => "document_expired",
142            DocumentTypeNotSupported => "document_type_not_supported",
143            DocumentUnverifiedOther => "document_unverified_other",
144            EmailUnverifiedOther => "email_unverified_other",
145            EmailVerificationDeclined => "email_verification_declined",
146            IdNumberInsufficientDocumentData => "id_number_insufficient_document_data",
147            IdNumberMismatch => "id_number_mismatch",
148            IdNumberUnverifiedOther => "id_number_unverified_other",
149            PhoneUnverifiedOther => "phone_unverified_other",
150            PhoneVerificationDeclined => "phone_verification_declined",
151            SelfieDocumentMissingPhoto => "selfie_document_missing_photo",
152            SelfieFaceMismatch => "selfie_face_mismatch",
153            SelfieManipulated => "selfie_manipulated",
154            SelfieUnverifiedOther => "selfie_unverified_other",
155            UnderSupportedAge => "under_supported_age",
156            Unknown(v) => v,
157        }
158    }
159}
160
161impl std::str::FromStr for GelatoSessionLastErrorCode {
162    type Err = std::convert::Infallible;
163    fn from_str(s: &str) -> Result<Self, Self::Err> {
164        use GelatoSessionLastErrorCode::*;
165        match s {
166            "abandoned" => Ok(Abandoned),
167            "consent_declined" => Ok(ConsentDeclined),
168            "country_not_supported" => Ok(CountryNotSupported),
169            "device_not_supported" => Ok(DeviceNotSupported),
170            "document_expired" => Ok(DocumentExpired),
171            "document_type_not_supported" => Ok(DocumentTypeNotSupported),
172            "document_unverified_other" => Ok(DocumentUnverifiedOther),
173            "email_unverified_other" => Ok(EmailUnverifiedOther),
174            "email_verification_declined" => Ok(EmailVerificationDeclined),
175            "id_number_insufficient_document_data" => Ok(IdNumberInsufficientDocumentData),
176            "id_number_mismatch" => Ok(IdNumberMismatch),
177            "id_number_unverified_other" => Ok(IdNumberUnverifiedOther),
178            "phone_unverified_other" => Ok(PhoneUnverifiedOther),
179            "phone_verification_declined" => Ok(PhoneVerificationDeclined),
180            "selfie_document_missing_photo" => Ok(SelfieDocumentMissingPhoto),
181            "selfie_face_mismatch" => Ok(SelfieFaceMismatch),
182            "selfie_manipulated" => Ok(SelfieManipulated),
183            "selfie_unverified_other" => Ok(SelfieUnverifiedOther),
184            "under_supported_age" => Ok(UnderSupportedAge),
185            v => Ok(Unknown(v.to_owned())),
186        }
187    }
188}
189impl std::fmt::Display for GelatoSessionLastErrorCode {
190    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
191        f.write_str(self.as_str())
192    }
193}
194
195impl std::fmt::Debug for GelatoSessionLastErrorCode {
196    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
197        f.write_str(self.as_str())
198    }
199}
200#[cfg(feature = "serialize")]
201impl serde::Serialize for GelatoSessionLastErrorCode {
202    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
203    where
204        S: serde::Serializer,
205    {
206        serializer.serialize_str(self.as_str())
207    }
208}
209impl miniserde::Deserialize for GelatoSessionLastErrorCode {
210    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
211        crate::Place::new(out)
212    }
213}
214
215impl miniserde::de::Visitor for crate::Place<GelatoSessionLastErrorCode> {
216    fn string(&mut self, s: &str) -> miniserde::Result<()> {
217        use std::str::FromStr;
218        self.out = Some(GelatoSessionLastErrorCode::from_str(s).unwrap());
219        Ok(())
220    }
221}
222
223stripe_types::impl_from_val_with_from_str!(GelatoSessionLastErrorCode);
224#[cfg(feature = "deserialize")]
225impl<'de> serde::Deserialize<'de> for GelatoSessionLastErrorCode {
226    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
227        use std::str::FromStr;
228        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
229        Ok(Self::from_str(&s).unwrap())
230    }
231}