stripe_misc/
gelato_selfie_report_error.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct GelatoSelfieReportError {
5    /// A short machine-readable string giving the reason for the verification failure.
6    pub code: Option<GelatoSelfieReportErrorCode>,
7    /// A human-readable message giving the reason for the failure.
8    /// These messages can be shown to your users.
9    pub reason: Option<String>,
10}
11#[doc(hidden)]
12pub struct GelatoSelfieReportErrorBuilder {
13    code: Option<Option<GelatoSelfieReportErrorCode>>,
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 GelatoSelfieReportError {
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<GelatoSelfieReportError>,
41        builder: GelatoSelfieReportErrorBuilder,
42    }
43
44    impl Visitor for Place<GelatoSelfieReportError> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: GelatoSelfieReportErrorBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for GelatoSelfieReportErrorBuilder {
54        type Out = GelatoSelfieReportError;
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 GelatoSelfieReportError {
87        type Builder = GelatoSelfieReportErrorBuilder;
88    }
89
90    impl FromValueOpt for GelatoSelfieReportError {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = GelatoSelfieReportErrorBuilder::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 failure.
108#[derive(Clone, Eq, PartialEq)]
109#[non_exhaustive]
110pub enum GelatoSelfieReportErrorCode {
111    SelfieDocumentMissingPhoto,
112    SelfieFaceMismatch,
113    SelfieManipulated,
114    SelfieUnverifiedOther,
115    /// An unrecognized value from Stripe. Should not be used as a request parameter.
116    Unknown(String),
117}
118impl GelatoSelfieReportErrorCode {
119    pub fn as_str(&self) -> &str {
120        use GelatoSelfieReportErrorCode::*;
121        match self {
122            SelfieDocumentMissingPhoto => "selfie_document_missing_photo",
123            SelfieFaceMismatch => "selfie_face_mismatch",
124            SelfieManipulated => "selfie_manipulated",
125            SelfieUnverifiedOther => "selfie_unverified_other",
126            Unknown(v) => v,
127        }
128    }
129}
130
131impl std::str::FromStr for GelatoSelfieReportErrorCode {
132    type Err = std::convert::Infallible;
133    fn from_str(s: &str) -> Result<Self, Self::Err> {
134        use GelatoSelfieReportErrorCode::*;
135        match s {
136            "selfie_document_missing_photo" => Ok(SelfieDocumentMissingPhoto),
137            "selfie_face_mismatch" => Ok(SelfieFaceMismatch),
138            "selfie_manipulated" => Ok(SelfieManipulated),
139            "selfie_unverified_other" => Ok(SelfieUnverifiedOther),
140            v => {
141                tracing::warn!(
142                    "Unknown value '{}' for enum '{}'",
143                    v,
144                    "GelatoSelfieReportErrorCode"
145                );
146                Ok(Unknown(v.to_owned()))
147            }
148        }
149    }
150}
151impl std::fmt::Display for GelatoSelfieReportErrorCode {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156
157impl std::fmt::Debug for GelatoSelfieReportErrorCode {
158    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159        f.write_str(self.as_str())
160    }
161}
162#[cfg(feature = "serialize")]
163impl serde::Serialize for GelatoSelfieReportErrorCode {
164    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
165    where
166        S: serde::Serializer,
167    {
168        serializer.serialize_str(self.as_str())
169    }
170}
171impl miniserde::Deserialize for GelatoSelfieReportErrorCode {
172    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
173        crate::Place::new(out)
174    }
175}
176
177impl miniserde::de::Visitor for crate::Place<GelatoSelfieReportErrorCode> {
178    fn string(&mut self, s: &str) -> miniserde::Result<()> {
179        use std::str::FromStr;
180        self.out = Some(GelatoSelfieReportErrorCode::from_str(s).expect("infallible"));
181        Ok(())
182    }
183}
184
185stripe_types::impl_from_val_with_from_str!(GelatoSelfieReportErrorCode);
186#[cfg(feature = "deserialize")]
187impl<'de> serde::Deserialize<'de> for GelatoSelfieReportErrorCode {
188    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
189        use std::str::FromStr;
190        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
191        Ok(Self::from_str(&s).expect("infallible"))
192    }
193}