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
113                _ => <dyn Visitor>::ignore(),
114            })
115        }
116
117        fn deser_default() -> Self {
118            Self {
119                address: Deserialize::default(),
120                dob: Deserialize::default(),
121                error: Deserialize::default(),
122                expiration_date: Deserialize::default(),
123                files: Deserialize::default(),
124                first_name: Deserialize::default(),
125                issued_date: Deserialize::default(),
126                issuing_country: Deserialize::default(),
127                last_name: Deserialize::default(),
128                number: Deserialize::default(),
129                sex: Deserialize::default(),
130                status: Deserialize::default(),
131                type_: Deserialize::default(),
132                unparsed_place_of_birth: Deserialize::default(),
133                unparsed_sex: Deserialize::default(),
134            }
135        }
136
137        fn take_out(&mut self) -> Option<Self::Out> {
138            let (
139                Some(address),
140                Some(dob),
141                Some(error),
142                Some(expiration_date),
143                Some(files),
144                Some(first_name),
145                Some(issued_date),
146                Some(issuing_country),
147                Some(last_name),
148                Some(number),
149                Some(sex),
150                Some(status),
151                Some(type_),
152                Some(unparsed_place_of_birth),
153                Some(unparsed_sex),
154            ) = (
155                self.address.take(),
156                self.dob,
157                self.error.take(),
158                self.expiration_date,
159                self.files.take(),
160                self.first_name.take(),
161                self.issued_date,
162                self.issuing_country.take(),
163                self.last_name.take(),
164                self.number.take(),
165                self.sex,
166                self.status,
167                self.type_,
168                self.unparsed_place_of_birth.take(),
169                self.unparsed_sex.take(),
170            )
171            else {
172                return None;
173            };
174            Some(Self::Out {
175                address,
176                dob,
177                error,
178                expiration_date,
179                files,
180                first_name,
181                issued_date,
182                issuing_country,
183                last_name,
184                number,
185                sex,
186                status,
187                type_,
188                unparsed_place_of_birth,
189                unparsed_sex,
190            })
191        }
192    }
193
194    impl Map for Builder<'_> {
195        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
196            self.builder.key(k)
197        }
198
199        fn finish(&mut self) -> Result<()> {
200            *self.out = self.builder.take_out();
201            Ok(())
202        }
203    }
204
205    impl ObjectDeser for GelatoDocumentReport {
206        type Builder = GelatoDocumentReportBuilder;
207    }
208
209    impl FromValueOpt for GelatoDocumentReport {
210        fn from_value(v: Value) -> Option<Self> {
211            let Value::Object(obj) = v else {
212                return None;
213            };
214            let mut b = GelatoDocumentReportBuilder::deser_default();
215            for (k, v) in obj {
216                match k.as_str() {
217                    "address" => b.address = FromValueOpt::from_value(v),
218                    "dob" => b.dob = FromValueOpt::from_value(v),
219                    "error" => b.error = FromValueOpt::from_value(v),
220                    "expiration_date" => b.expiration_date = FromValueOpt::from_value(v),
221                    "files" => b.files = FromValueOpt::from_value(v),
222                    "first_name" => b.first_name = FromValueOpt::from_value(v),
223                    "issued_date" => b.issued_date = FromValueOpt::from_value(v),
224                    "issuing_country" => b.issuing_country = FromValueOpt::from_value(v),
225                    "last_name" => b.last_name = FromValueOpt::from_value(v),
226                    "number" => b.number = FromValueOpt::from_value(v),
227                    "sex" => b.sex = FromValueOpt::from_value(v),
228                    "status" => b.status = FromValueOpt::from_value(v),
229                    "type" => b.type_ = FromValueOpt::from_value(v),
230                    "unparsed_place_of_birth" => {
231                        b.unparsed_place_of_birth = FromValueOpt::from_value(v)
232                    }
233                    "unparsed_sex" => b.unparsed_sex = FromValueOpt::from_value(v),
234
235                    _ => {}
236                }
237            }
238            b.take_out()
239        }
240    }
241};
242/// Sex of the person in the document.
243#[derive(Copy, Clone, Eq, PartialEq)]
244pub enum GelatoDocumentReportSex {
245    Redacted,
246    Female,
247    Male,
248    Unknown,
249}
250impl GelatoDocumentReportSex {
251    pub fn as_str(self) -> &'static str {
252        use GelatoDocumentReportSex::*;
253        match self {
254            Redacted => "[redacted]",
255            Female => "female",
256            Male => "male",
257            Unknown => "unknown",
258        }
259    }
260}
261
262impl std::str::FromStr for GelatoDocumentReportSex {
263    type Err = stripe_types::StripeParseError;
264    fn from_str(s: &str) -> Result<Self, Self::Err> {
265        use GelatoDocumentReportSex::*;
266        match s {
267            "[redacted]" => Ok(Redacted),
268            "female" => Ok(Female),
269            "male" => Ok(Male),
270            "unknown" => Ok(Unknown),
271            _ => Err(stripe_types::StripeParseError),
272        }
273    }
274}
275impl std::fmt::Display for GelatoDocumentReportSex {
276    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
277        f.write_str(self.as_str())
278    }
279}
280
281impl std::fmt::Debug for GelatoDocumentReportSex {
282    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
283        f.write_str(self.as_str())
284    }
285}
286#[cfg(feature = "serialize")]
287impl serde::Serialize for GelatoDocumentReportSex {
288    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
289    where
290        S: serde::Serializer,
291    {
292        serializer.serialize_str(self.as_str())
293    }
294}
295impl miniserde::Deserialize for GelatoDocumentReportSex {
296    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
297        crate::Place::new(out)
298    }
299}
300
301impl miniserde::de::Visitor for crate::Place<GelatoDocumentReportSex> {
302    fn string(&mut self, s: &str) -> miniserde::Result<()> {
303        use std::str::FromStr;
304        self.out = Some(GelatoDocumentReportSex::from_str(s).map_err(|_| miniserde::Error)?);
305        Ok(())
306    }
307}
308
309stripe_types::impl_from_val_with_from_str!(GelatoDocumentReportSex);
310#[cfg(feature = "deserialize")]
311impl<'de> serde::Deserialize<'de> for GelatoDocumentReportSex {
312    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
313        use std::str::FromStr;
314        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
315        Self::from_str(&s)
316            .map_err(|_| serde::de::Error::custom("Unknown value for GelatoDocumentReportSex"))
317    }
318}
319/// Status of this `document` check.
320#[derive(Copy, Clone, Eq, PartialEq)]
321pub enum GelatoDocumentReportStatus {
322    Unverified,
323    Verified,
324}
325impl GelatoDocumentReportStatus {
326    pub fn as_str(self) -> &'static str {
327        use GelatoDocumentReportStatus::*;
328        match self {
329            Unverified => "unverified",
330            Verified => "verified",
331        }
332    }
333}
334
335impl std::str::FromStr for GelatoDocumentReportStatus {
336    type Err = stripe_types::StripeParseError;
337    fn from_str(s: &str) -> Result<Self, Self::Err> {
338        use GelatoDocumentReportStatus::*;
339        match s {
340            "unverified" => Ok(Unverified),
341            "verified" => Ok(Verified),
342            _ => Err(stripe_types::StripeParseError),
343        }
344    }
345}
346impl std::fmt::Display for GelatoDocumentReportStatus {
347    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
348        f.write_str(self.as_str())
349    }
350}
351
352impl std::fmt::Debug for GelatoDocumentReportStatus {
353    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
354        f.write_str(self.as_str())
355    }
356}
357#[cfg(feature = "serialize")]
358impl serde::Serialize for GelatoDocumentReportStatus {
359    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
360    where
361        S: serde::Serializer,
362    {
363        serializer.serialize_str(self.as_str())
364    }
365}
366impl miniserde::Deserialize for GelatoDocumentReportStatus {
367    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
368        crate::Place::new(out)
369    }
370}
371
372impl miniserde::de::Visitor for crate::Place<GelatoDocumentReportStatus> {
373    fn string(&mut self, s: &str) -> miniserde::Result<()> {
374        use std::str::FromStr;
375        self.out = Some(GelatoDocumentReportStatus::from_str(s).map_err(|_| miniserde::Error)?);
376        Ok(())
377    }
378}
379
380stripe_types::impl_from_val_with_from_str!(GelatoDocumentReportStatus);
381#[cfg(feature = "deserialize")]
382impl<'de> serde::Deserialize<'de> for GelatoDocumentReportStatus {
383    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
384        use std::str::FromStr;
385        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
386        Self::from_str(&s)
387            .map_err(|_| serde::de::Error::custom("Unknown value for GelatoDocumentReportStatus"))
388    }
389}
390/// Type of the document.
391#[derive(Copy, Clone, Eq, PartialEq)]
392pub enum GelatoDocumentReportType {
393    DrivingLicense,
394    IdCard,
395    Passport,
396}
397impl GelatoDocumentReportType {
398    pub fn as_str(self) -> &'static str {
399        use GelatoDocumentReportType::*;
400        match self {
401            DrivingLicense => "driving_license",
402            IdCard => "id_card",
403            Passport => "passport",
404        }
405    }
406}
407
408impl std::str::FromStr for GelatoDocumentReportType {
409    type Err = stripe_types::StripeParseError;
410    fn from_str(s: &str) -> Result<Self, Self::Err> {
411        use GelatoDocumentReportType::*;
412        match s {
413            "driving_license" => Ok(DrivingLicense),
414            "id_card" => Ok(IdCard),
415            "passport" => Ok(Passport),
416            _ => Err(stripe_types::StripeParseError),
417        }
418    }
419}
420impl std::fmt::Display for GelatoDocumentReportType {
421    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
422        f.write_str(self.as_str())
423    }
424}
425
426impl std::fmt::Debug for GelatoDocumentReportType {
427    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
428        f.write_str(self.as_str())
429    }
430}
431#[cfg(feature = "serialize")]
432impl serde::Serialize for GelatoDocumentReportType {
433    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
434    where
435        S: serde::Serializer,
436    {
437        serializer.serialize_str(self.as_str())
438    }
439}
440impl miniserde::Deserialize for GelatoDocumentReportType {
441    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
442        crate::Place::new(out)
443    }
444}
445
446impl miniserde::de::Visitor for crate::Place<GelatoDocumentReportType> {
447    fn string(&mut self, s: &str) -> miniserde::Result<()> {
448        use std::str::FromStr;
449        self.out = Some(GelatoDocumentReportType::from_str(s).map_err(|_| miniserde::Error)?);
450        Ok(())
451    }
452}
453
454stripe_types::impl_from_val_with_from_str!(GelatoDocumentReportType);
455#[cfg(feature = "deserialize")]
456impl<'de> serde::Deserialize<'de> for GelatoDocumentReportType {
457    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
458        use std::str::FromStr;
459        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
460        Self::from_str(&s)
461            .map_err(|_| serde::de::Error::custom("Unknown value for GelatoDocumentReportType"))
462    }
463}