1#[derive(Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct GelatoSessionLastError {
6 pub code: Option<GelatoSessionLastErrorCode>,
8 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
60 _ => <dyn Visitor>::ignore(),
61 })
62 }
63
64 fn deser_default() -> Self {
65 Self { code: Deserialize::default(), reason: Deserialize::default() }
66 }
67
68 fn take_out(&mut self) -> Option<Self::Out> {
69 let (Some(code), Some(reason)) = (self.code.take(), self.reason.take()) else {
70 return None;
71 };
72 Some(Self::Out { code, reason })
73 }
74 }
75
76 impl Map for Builder<'_> {
77 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78 self.builder.key(k)
79 }
80
81 fn finish(&mut self) -> Result<()> {
82 *self.out = self.builder.take_out();
83 Ok(())
84 }
85 }
86
87 impl ObjectDeser for GelatoSessionLastError {
88 type Builder = GelatoSessionLastErrorBuilder;
89 }
90
91 impl FromValueOpt for GelatoSessionLastError {
92 fn from_value(v: Value) -> Option<Self> {
93 let Value::Object(obj) = v else {
94 return None;
95 };
96 let mut b = GelatoSessionLastErrorBuilder::deser_default();
97 for (k, v) in obj {
98 match k.as_str() {
99 "code" => b.code = FromValueOpt::from_value(v),
100 "reason" => b.reason = FromValueOpt::from_value(v),
101
102 _ => {}
103 }
104 }
105 b.take_out()
106 }
107 }
108};
109#[derive(Clone, Eq, PartialEq)]
111#[non_exhaustive]
112pub enum GelatoSessionLastErrorCode {
113 Abandoned,
114 ConsentDeclined,
115 CountryNotSupported,
116 DeviceNotSupported,
117 DocumentExpired,
118 DocumentTypeNotSupported,
119 DocumentUnverifiedOther,
120 EmailUnverifiedOther,
121 EmailVerificationDeclined,
122 IdNumberInsufficientDocumentData,
123 IdNumberMismatch,
124 IdNumberUnverifiedOther,
125 PhoneUnverifiedOther,
126 PhoneVerificationDeclined,
127 SelfieDocumentMissingPhoto,
128 SelfieFaceMismatch,
129 SelfieManipulated,
130 SelfieUnverifiedOther,
131 UnderSupportedAge,
132 Unknown(String),
134}
135impl GelatoSessionLastErrorCode {
136 pub fn as_str(&self) -> &str {
137 use GelatoSessionLastErrorCode::*;
138 match self {
139 Abandoned => "abandoned",
140 ConsentDeclined => "consent_declined",
141 CountryNotSupported => "country_not_supported",
142 DeviceNotSupported => "device_not_supported",
143 DocumentExpired => "document_expired",
144 DocumentTypeNotSupported => "document_type_not_supported",
145 DocumentUnverifiedOther => "document_unverified_other",
146 EmailUnverifiedOther => "email_unverified_other",
147 EmailVerificationDeclined => "email_verification_declined",
148 IdNumberInsufficientDocumentData => "id_number_insufficient_document_data",
149 IdNumberMismatch => "id_number_mismatch",
150 IdNumberUnverifiedOther => "id_number_unverified_other",
151 PhoneUnverifiedOther => "phone_unverified_other",
152 PhoneVerificationDeclined => "phone_verification_declined",
153 SelfieDocumentMissingPhoto => "selfie_document_missing_photo",
154 SelfieFaceMismatch => "selfie_face_mismatch",
155 SelfieManipulated => "selfie_manipulated",
156 SelfieUnverifiedOther => "selfie_unverified_other",
157 UnderSupportedAge => "under_supported_age",
158 Unknown(v) => v,
159 }
160 }
161}
162
163impl std::str::FromStr for GelatoSessionLastErrorCode {
164 type Err = std::convert::Infallible;
165 fn from_str(s: &str) -> Result<Self, Self::Err> {
166 use GelatoSessionLastErrorCode::*;
167 match s {
168 "abandoned" => Ok(Abandoned),
169 "consent_declined" => Ok(ConsentDeclined),
170 "country_not_supported" => Ok(CountryNotSupported),
171 "device_not_supported" => Ok(DeviceNotSupported),
172 "document_expired" => Ok(DocumentExpired),
173 "document_type_not_supported" => Ok(DocumentTypeNotSupported),
174 "document_unverified_other" => Ok(DocumentUnverifiedOther),
175 "email_unverified_other" => Ok(EmailUnverifiedOther),
176 "email_verification_declined" => Ok(EmailVerificationDeclined),
177 "id_number_insufficient_document_data" => Ok(IdNumberInsufficientDocumentData),
178 "id_number_mismatch" => Ok(IdNumberMismatch),
179 "id_number_unverified_other" => Ok(IdNumberUnverifiedOther),
180 "phone_unverified_other" => Ok(PhoneUnverifiedOther),
181 "phone_verification_declined" => Ok(PhoneVerificationDeclined),
182 "selfie_document_missing_photo" => Ok(SelfieDocumentMissingPhoto),
183 "selfie_face_mismatch" => Ok(SelfieFaceMismatch),
184 "selfie_manipulated" => Ok(SelfieManipulated),
185 "selfie_unverified_other" => Ok(SelfieUnverifiedOther),
186 "under_supported_age" => Ok(UnderSupportedAge),
187 v => Ok(Unknown(v.to_owned())),
188 }
189 }
190}
191impl std::fmt::Display for GelatoSessionLastErrorCode {
192 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
193 f.write_str(self.as_str())
194 }
195}
196
197impl std::fmt::Debug for GelatoSessionLastErrorCode {
198 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
199 f.write_str(self.as_str())
200 }
201}
202#[cfg(feature = "serialize")]
203impl serde::Serialize for GelatoSessionLastErrorCode {
204 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
205 where
206 S: serde::Serializer,
207 {
208 serializer.serialize_str(self.as_str())
209 }
210}
211impl miniserde::Deserialize for GelatoSessionLastErrorCode {
212 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
213 crate::Place::new(out)
214 }
215}
216
217impl miniserde::de::Visitor for crate::Place<GelatoSessionLastErrorCode> {
218 fn string(&mut self, s: &str) -> miniserde::Result<()> {
219 use std::str::FromStr;
220 self.out = Some(GelatoSessionLastErrorCode::from_str(s).unwrap());
221 Ok(())
222 }
223}
224
225stripe_types::impl_from_val_with_from_str!(GelatoSessionLastErrorCode);
226#[cfg(feature = "deserialize")]
227impl<'de> serde::Deserialize<'de> for GelatoSessionLastErrorCode {
228 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
229 use std::str::FromStr;
230 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
231 Ok(Self::from_str(&s).unwrap())
232 }
233}