stripe_misc/
gelato_document_report.rs

1/// Result from a document check
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct GelatoDocumentReport {
6    /// Address as it appears in the document.
7    pub address: Option<stripe_shared::Address>,
8    /// Date of birth as it appears in the document.
9    pub dob: Option<stripe_misc::GelatoDataDocumentReportDateOfBirth>,
10    /// Details on the verification error. Present when status is `unverified`.
11    pub error: Option<stripe_misc::GelatoDocumentReportError>,
12    /// Expiration date of the document.
13    pub expiration_date: Option<stripe_misc::GelatoDataDocumentReportExpirationDate>,
14    /// Array of [File](https://stripe.com/docs/api/files) ids containing images for this document.
15    pub files: Option<Vec<String>>,
16    /// First name as it appears in the document.
17    pub first_name: Option<String>,
18    /// Issued date of the document.
19    pub issued_date: Option<stripe_misc::GelatoDataDocumentReportIssuedDate>,
20    /// Issuing country of the document.
21    pub issuing_country: Option<String>,
22    /// Last name as it appears in the document.
23    pub last_name: Option<String>,
24    /// Document ID number.
25    pub number: Option<String>,
26    /// Sex of the person in the document.
27    pub sex: Option<GelatoDocumentReportSex>,
28    /// Status of this `document` check.
29    pub status: GelatoDocumentReportStatus,
30    /// Type of the document.
31    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
32    pub type_: Option<GelatoDocumentReportType>,
33    /// Place of birth as it appears in the document.
34    pub unparsed_place_of_birth: Option<String>,
35    /// Sex as it appears in the document.
36    pub unparsed_sex: Option<String>,
37}
38#[doc(hidden)]
39pub struct GelatoDocumentReportBuilder {
40    address: Option<Option<stripe_shared::Address>>,
41    dob: Option<Option<stripe_misc::GelatoDataDocumentReportDateOfBirth>>,
42    error: Option<Option<stripe_misc::GelatoDocumentReportError>>,
43    expiration_date: Option<Option<stripe_misc::GelatoDataDocumentReportExpirationDate>>,
44    files: Option<Option<Vec<String>>>,
45    first_name: Option<Option<String>>,
46    issued_date: Option<Option<stripe_misc::GelatoDataDocumentReportIssuedDate>>,
47    issuing_country: Option<Option<String>>,
48    last_name: Option<Option<String>>,
49    number: Option<Option<String>>,
50    sex: Option<Option<GelatoDocumentReportSex>>,
51    status: Option<GelatoDocumentReportStatus>,
52    type_: Option<Option<GelatoDocumentReportType>>,
53    unparsed_place_of_birth: Option<Option<String>>,
54    unparsed_sex: Option<Option<String>>,
55}
56
57#[allow(
58    unused_variables,
59    irrefutable_let_patterns,
60    clippy::let_unit_value,
61    clippy::match_single_binding,
62    clippy::single_match
63)]
64const _: () = {
65    use miniserde::de::{Map, Visitor};
66    use miniserde::json::Value;
67    use miniserde::{Deserialize, Result, make_place};
68    use stripe_types::miniserde_helpers::FromValueOpt;
69    use stripe_types::{MapBuilder, ObjectDeser};
70
71    make_place!(Place);
72
73    impl Deserialize for GelatoDocumentReport {
74        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
75            Place::new(out)
76        }
77    }
78
79    struct Builder<'a> {
80        out: &'a mut Option<GelatoDocumentReport>,
81        builder: GelatoDocumentReportBuilder,
82    }
83
84    impl Visitor for Place<GelatoDocumentReport> {
85        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
86            Ok(Box::new(Builder {
87                out: &mut self.out,
88                builder: GelatoDocumentReportBuilder::deser_default(),
89            }))
90        }
91    }
92
93    impl MapBuilder for GelatoDocumentReportBuilder {
94        type Out = GelatoDocumentReport;
95        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96            Ok(match k {
97                "address" => Deserialize::begin(&mut self.address),
98                "dob" => Deserialize::begin(&mut self.dob),
99                "error" => Deserialize::begin(&mut self.error),
100                "expiration_date" => Deserialize::begin(&mut self.expiration_date),
101                "files" => Deserialize::begin(&mut self.files),
102                "first_name" => Deserialize::begin(&mut self.first_name),
103                "issued_date" => Deserialize::begin(&mut self.issued_date),
104                "issuing_country" => Deserialize::begin(&mut self.issuing_country),
105                "last_name" => Deserialize::begin(&mut self.last_name),
106                "number" => Deserialize::begin(&mut self.number),
107                "sex" => Deserialize::begin(&mut self.sex),
108                "status" => Deserialize::begin(&mut self.status),
109                "type" => Deserialize::begin(&mut self.type_),
110                "unparsed_place_of_birth" => Deserialize::begin(&mut self.unparsed_place_of_birth),
111                "unparsed_sex" => Deserialize::begin(&mut self.unparsed_sex),
112                _ => <dyn Visitor>::ignore(),
113            })
114        }
115
116        fn deser_default() -> Self {
117            Self {
118                address: Deserialize::default(),
119                dob: Deserialize::default(),
120                error: Deserialize::default(),
121                expiration_date: Deserialize::default(),
122                files: Deserialize::default(),
123                first_name: Deserialize::default(),
124                issued_date: Deserialize::default(),
125                issuing_country: Deserialize::default(),
126                last_name: Deserialize::default(),
127                number: Deserialize::default(),
128                sex: Deserialize::default(),
129                status: Deserialize::default(),
130                type_: Deserialize::default(),
131                unparsed_place_of_birth: Deserialize::default(),
132                unparsed_sex: Deserialize::default(),
133            }
134        }
135
136        fn take_out(&mut self) -> Option<Self::Out> {
137            let (
138                Some(address),
139                Some(dob),
140                Some(error),
141                Some(expiration_date),
142                Some(files),
143                Some(first_name),
144                Some(issued_date),
145                Some(issuing_country),
146                Some(last_name),
147                Some(number),
148                Some(sex),
149                Some(status),
150                Some(type_),
151                Some(unparsed_place_of_birth),
152                Some(unparsed_sex),
153            ) = (
154                self.address.take(),
155                self.dob,
156                self.error.take(),
157                self.expiration_date,
158                self.files.take(),
159                self.first_name.take(),
160                self.issued_date,
161                self.issuing_country.take(),
162                self.last_name.take(),
163                self.number.take(),
164                self.sex,
165                self.status,
166                self.type_,
167                self.unparsed_place_of_birth.take(),
168                self.unparsed_sex.take(),
169            )
170            else {
171                return None;
172            };
173            Some(Self::Out {
174                address,
175                dob,
176                error,
177                expiration_date,
178                files,
179                first_name,
180                issued_date,
181                issuing_country,
182                last_name,
183                number,
184                sex,
185                status,
186                type_,
187                unparsed_place_of_birth,
188                unparsed_sex,
189            })
190        }
191    }
192
193    impl Map for Builder<'_> {
194        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
195            self.builder.key(k)
196        }
197
198        fn finish(&mut self) -> Result<()> {
199            *self.out = self.builder.take_out();
200            Ok(())
201        }
202    }
203
204    impl ObjectDeser for GelatoDocumentReport {
205        type Builder = GelatoDocumentReportBuilder;
206    }
207
208    impl FromValueOpt for GelatoDocumentReport {
209        fn from_value(v: Value) -> Option<Self> {
210            let Value::Object(obj) = v else {
211                return None;
212            };
213            let mut b = GelatoDocumentReportBuilder::deser_default();
214            for (k, v) in obj {
215                match k.as_str() {
216                    "address" => b.address = FromValueOpt::from_value(v),
217                    "dob" => b.dob = FromValueOpt::from_value(v),
218                    "error" => b.error = FromValueOpt::from_value(v),
219                    "expiration_date" => b.expiration_date = FromValueOpt::from_value(v),
220                    "files" => b.files = FromValueOpt::from_value(v),
221                    "first_name" => b.first_name = FromValueOpt::from_value(v),
222                    "issued_date" => b.issued_date = FromValueOpt::from_value(v),
223                    "issuing_country" => b.issuing_country = FromValueOpt::from_value(v),
224                    "last_name" => b.last_name = FromValueOpt::from_value(v),
225                    "number" => b.number = FromValueOpt::from_value(v),
226                    "sex" => b.sex = FromValueOpt::from_value(v),
227                    "status" => b.status = FromValueOpt::from_value(v),
228                    "type" => b.type_ = FromValueOpt::from_value(v),
229                    "unparsed_place_of_birth" => {
230                        b.unparsed_place_of_birth = FromValueOpt::from_value(v)
231                    }
232                    "unparsed_sex" => b.unparsed_sex = FromValueOpt::from_value(v),
233                    _ => {}
234                }
235            }
236            b.take_out()
237        }
238    }
239};
240/// Sex of the person in the document.
241#[derive(Copy, Clone, Eq, PartialEq)]
242pub enum GelatoDocumentReportSex {
243    Redacted,
244    Female,
245    Male,
246    Unknown,
247}
248impl GelatoDocumentReportSex {
249    pub fn as_str(self) -> &'static str {
250        use GelatoDocumentReportSex::*;
251        match self {
252            Redacted => "[redacted]",
253            Female => "female",
254            Male => "male",
255            Unknown => "unknown",
256        }
257    }
258}
259
260impl std::str::FromStr for GelatoDocumentReportSex {
261    type Err = stripe_types::StripeParseError;
262    fn from_str(s: &str) -> Result<Self, Self::Err> {
263        use GelatoDocumentReportSex::*;
264        match s {
265            "[redacted]" => Ok(Redacted),
266            "female" => Ok(Female),
267            "male" => Ok(Male),
268            "unknown" => Ok(Unknown),
269            _ => Err(stripe_types::StripeParseError),
270        }
271    }
272}
273impl std::fmt::Display for GelatoDocumentReportSex {
274    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
275        f.write_str(self.as_str())
276    }
277}
278
279impl std::fmt::Debug for GelatoDocumentReportSex {
280    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
281        f.write_str(self.as_str())
282    }
283}
284#[cfg(feature = "serialize")]
285impl serde::Serialize for GelatoDocumentReportSex {
286    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
287    where
288        S: serde::Serializer,
289    {
290        serializer.serialize_str(self.as_str())
291    }
292}
293impl miniserde::Deserialize for GelatoDocumentReportSex {
294    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
295        crate::Place::new(out)
296    }
297}
298
299impl miniserde::de::Visitor for crate::Place<GelatoDocumentReportSex> {
300    fn string(&mut self, s: &str) -> miniserde::Result<()> {
301        use std::str::FromStr;
302        self.out = Some(GelatoDocumentReportSex::from_str(s).map_err(|_| miniserde::Error)?);
303        Ok(())
304    }
305}
306
307stripe_types::impl_from_val_with_from_str!(GelatoDocumentReportSex);
308#[cfg(feature = "deserialize")]
309impl<'de> serde::Deserialize<'de> for GelatoDocumentReportSex {
310    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
311        use std::str::FromStr;
312        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
313        Self::from_str(&s)
314            .map_err(|_| serde::de::Error::custom("Unknown value for GelatoDocumentReportSex"))
315    }
316}
317/// Status of this `document` check.
318#[derive(Copy, Clone, Eq, PartialEq)]
319pub enum GelatoDocumentReportStatus {
320    Unverified,
321    Verified,
322}
323impl GelatoDocumentReportStatus {
324    pub fn as_str(self) -> &'static str {
325        use GelatoDocumentReportStatus::*;
326        match self {
327            Unverified => "unverified",
328            Verified => "verified",
329        }
330    }
331}
332
333impl std::str::FromStr for GelatoDocumentReportStatus {
334    type Err = stripe_types::StripeParseError;
335    fn from_str(s: &str) -> Result<Self, Self::Err> {
336        use GelatoDocumentReportStatus::*;
337        match s {
338            "unverified" => Ok(Unverified),
339            "verified" => Ok(Verified),
340            _ => Err(stripe_types::StripeParseError),
341        }
342    }
343}
344impl std::fmt::Display for GelatoDocumentReportStatus {
345    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
346        f.write_str(self.as_str())
347    }
348}
349
350impl std::fmt::Debug for GelatoDocumentReportStatus {
351    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
352        f.write_str(self.as_str())
353    }
354}
355#[cfg(feature = "serialize")]
356impl serde::Serialize for GelatoDocumentReportStatus {
357    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
358    where
359        S: serde::Serializer,
360    {
361        serializer.serialize_str(self.as_str())
362    }
363}
364impl miniserde::Deserialize for GelatoDocumentReportStatus {
365    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
366        crate::Place::new(out)
367    }
368}
369
370impl miniserde::de::Visitor for crate::Place<GelatoDocumentReportStatus> {
371    fn string(&mut self, s: &str) -> miniserde::Result<()> {
372        use std::str::FromStr;
373        self.out = Some(GelatoDocumentReportStatus::from_str(s).map_err(|_| miniserde::Error)?);
374        Ok(())
375    }
376}
377
378stripe_types::impl_from_val_with_from_str!(GelatoDocumentReportStatus);
379#[cfg(feature = "deserialize")]
380impl<'de> serde::Deserialize<'de> for GelatoDocumentReportStatus {
381    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
382        use std::str::FromStr;
383        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
384        Self::from_str(&s)
385            .map_err(|_| serde::de::Error::custom("Unknown value for GelatoDocumentReportStatus"))
386    }
387}
388/// Type of the document.
389#[derive(Copy, Clone, Eq, PartialEq)]
390pub enum GelatoDocumentReportType {
391    DrivingLicense,
392    IdCard,
393    Passport,
394}
395impl GelatoDocumentReportType {
396    pub fn as_str(self) -> &'static str {
397        use GelatoDocumentReportType::*;
398        match self {
399            DrivingLicense => "driving_license",
400            IdCard => "id_card",
401            Passport => "passport",
402        }
403    }
404}
405
406impl std::str::FromStr for GelatoDocumentReportType {
407    type Err = stripe_types::StripeParseError;
408    fn from_str(s: &str) -> Result<Self, Self::Err> {
409        use GelatoDocumentReportType::*;
410        match s {
411            "driving_license" => Ok(DrivingLicense),
412            "id_card" => Ok(IdCard),
413            "passport" => Ok(Passport),
414            _ => Err(stripe_types::StripeParseError),
415        }
416    }
417}
418impl std::fmt::Display for GelatoDocumentReportType {
419    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
420        f.write_str(self.as_str())
421    }
422}
423
424impl std::fmt::Debug for GelatoDocumentReportType {
425    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
426        f.write_str(self.as_str())
427    }
428}
429#[cfg(feature = "serialize")]
430impl serde::Serialize for GelatoDocumentReportType {
431    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
432    where
433        S: serde::Serializer,
434    {
435        serializer.serialize_str(self.as_str())
436    }
437}
438impl miniserde::Deserialize for GelatoDocumentReportType {
439    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
440        crate::Place::new(out)
441    }
442}
443
444impl miniserde::de::Visitor for crate::Place<GelatoDocumentReportType> {
445    fn string(&mut self, s: &str) -> miniserde::Result<()> {
446        use std::str::FromStr;
447        self.out = Some(GelatoDocumentReportType::from_str(s).map_err(|_| miniserde::Error)?);
448        Ok(())
449    }
450}
451
452stripe_types::impl_from_val_with_from_str!(GelatoDocumentReportType);
453#[cfg(feature = "deserialize")]
454impl<'de> serde::Deserialize<'de> for GelatoDocumentReportType {
455    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
456        use std::str::FromStr;
457        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
458        Self::from_str(&s)
459            .map_err(|_| serde::de::Error::custom("Unknown value for GelatoDocumentReportType"))
460    }
461}