stripe_misc/
gelato_phone_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 GelatoPhoneReportError {
5    /// A short machine-readable string giving the reason for the verification failure.
6    pub code: Option<GelatoPhoneReportErrorCode>,
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 GelatoPhoneReportErrorBuilder {
13    code: Option<Option<GelatoPhoneReportErrorCode>>,
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 GelatoPhoneReportError {
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<GelatoPhoneReportError>,
41        builder: GelatoPhoneReportErrorBuilder,
42    }
43
44    impl Visitor for Place<GelatoPhoneReportError> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: GelatoPhoneReportErrorBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for GelatoPhoneReportErrorBuilder {
54        type Out = GelatoPhoneReportError;
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 GelatoPhoneReportError {
87        type Builder = GelatoPhoneReportErrorBuilder;
88    }
89
90    impl FromValueOpt for GelatoPhoneReportError {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = GelatoPhoneReportErrorBuilder::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 GelatoPhoneReportErrorCode {
111    PhoneUnverifiedOther,
112    PhoneVerificationDeclined,
113    /// An unrecognized value from Stripe. Should not be used as a request parameter.
114    Unknown(String),
115}
116impl GelatoPhoneReportErrorCode {
117    pub fn as_str(&self) -> &str {
118        use GelatoPhoneReportErrorCode::*;
119        match self {
120            PhoneUnverifiedOther => "phone_unverified_other",
121            PhoneVerificationDeclined => "phone_verification_declined",
122            Unknown(v) => v,
123        }
124    }
125}
126
127impl std::str::FromStr for GelatoPhoneReportErrorCode {
128    type Err = std::convert::Infallible;
129    fn from_str(s: &str) -> Result<Self, Self::Err> {
130        use GelatoPhoneReportErrorCode::*;
131        match s {
132            "phone_unverified_other" => Ok(PhoneUnverifiedOther),
133            "phone_verification_declined" => Ok(PhoneVerificationDeclined),
134            v => {
135                tracing::warn!("Unknown value '{}' for enum '{}'", v, "GelatoPhoneReportErrorCode");
136                Ok(Unknown(v.to_owned()))
137            }
138        }
139    }
140}
141impl std::fmt::Display for GelatoPhoneReportErrorCode {
142    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
143        f.write_str(self.as_str())
144    }
145}
146
147impl std::fmt::Debug for GelatoPhoneReportErrorCode {
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.write_str(self.as_str())
150    }
151}
152#[cfg(feature = "serialize")]
153impl serde::Serialize for GelatoPhoneReportErrorCode {
154    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
155    where
156        S: serde::Serializer,
157    {
158        serializer.serialize_str(self.as_str())
159    }
160}
161impl miniserde::Deserialize for GelatoPhoneReportErrorCode {
162    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
163        crate::Place::new(out)
164    }
165}
166
167impl miniserde::de::Visitor for crate::Place<GelatoPhoneReportErrorCode> {
168    fn string(&mut self, s: &str) -> miniserde::Result<()> {
169        use std::str::FromStr;
170        self.out = Some(GelatoPhoneReportErrorCode::from_str(s).expect("infallible"));
171        Ok(())
172    }
173}
174
175stripe_types::impl_from_val_with_from_str!(GelatoPhoneReportErrorCode);
176#[cfg(feature = "deserialize")]
177impl<'de> serde::Deserialize<'de> for GelatoPhoneReportErrorCode {
178    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
179        use std::str::FromStr;
180        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
181        Ok(Self::from_str(&s).expect("infallible"))
182    }
183}