stripe_misc/
gelato_report_document_options.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct GelatoReportDocumentOptions {
5    /// Array of strings of allowed identity document types.
6    /// If the provided identity document isn’t one of the allowed types, the verification check will fail with a document_type_not_allowed error code.
7    pub allowed_types: Option<Vec<GelatoReportDocumentOptionsAllowedTypes>>,
8    /// Collect an ID number and perform an [ID number check](https://stripe.com/docs/identity/verification-checks?type=id-number) with the document’s extracted name and date of birth.
9    pub require_id_number: Option<bool>,
10    /// Disable image uploads, identity document images have to be captured using the device’s camera.
11    pub require_live_capture: Option<bool>,
12    /// Capture a face image and perform a [selfie check](https://stripe.com/docs/identity/verification-checks?type=selfie) comparing a photo ID and a picture of your user’s face.
13    /// [Learn more](https://stripe.com/docs/identity/selfie).
14    pub require_matching_selfie: Option<bool>,
15}
16#[doc(hidden)]
17pub struct GelatoReportDocumentOptionsBuilder {
18    allowed_types: Option<Option<Vec<GelatoReportDocumentOptionsAllowedTypes>>>,
19    require_id_number: Option<Option<bool>>,
20    require_live_capture: Option<Option<bool>>,
21    require_matching_selfie: Option<Option<bool>>,
22}
23
24#[allow(
25    unused_variables,
26    irrefutable_let_patterns,
27    clippy::let_unit_value,
28    clippy::match_single_binding,
29    clippy::single_match
30)]
31const _: () = {
32    use miniserde::de::{Map, Visitor};
33    use miniserde::json::Value;
34    use miniserde::{Deserialize, Result, make_place};
35    use stripe_types::miniserde_helpers::FromValueOpt;
36    use stripe_types::{MapBuilder, ObjectDeser};
37
38    make_place!(Place);
39
40    impl Deserialize for GelatoReportDocumentOptions {
41        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
42            Place::new(out)
43        }
44    }
45
46    struct Builder<'a> {
47        out: &'a mut Option<GelatoReportDocumentOptions>,
48        builder: GelatoReportDocumentOptionsBuilder,
49    }
50
51    impl Visitor for Place<GelatoReportDocumentOptions> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: GelatoReportDocumentOptionsBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for GelatoReportDocumentOptionsBuilder {
61        type Out = GelatoReportDocumentOptions;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "allowed_types" => Deserialize::begin(&mut self.allowed_types),
65                "require_id_number" => Deserialize::begin(&mut self.require_id_number),
66                "require_live_capture" => Deserialize::begin(&mut self.require_live_capture),
67                "require_matching_selfie" => Deserialize::begin(&mut self.require_matching_selfie),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self {
74                allowed_types: Deserialize::default(),
75                require_id_number: Deserialize::default(),
76                require_live_capture: Deserialize::default(),
77                require_matching_selfie: Deserialize::default(),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (
83                Some(allowed_types),
84                Some(require_id_number),
85                Some(require_live_capture),
86                Some(require_matching_selfie),
87            ) = (
88                self.allowed_types.take(),
89                self.require_id_number,
90                self.require_live_capture,
91                self.require_matching_selfie,
92            )
93            else {
94                return None;
95            };
96            Some(Self::Out {
97                allowed_types,
98                require_id_number,
99                require_live_capture,
100                require_matching_selfie,
101            })
102        }
103    }
104
105    impl Map for Builder<'_> {
106        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
107            self.builder.key(k)
108        }
109
110        fn finish(&mut self) -> Result<()> {
111            *self.out = self.builder.take_out();
112            Ok(())
113        }
114    }
115
116    impl ObjectDeser for GelatoReportDocumentOptions {
117        type Builder = GelatoReportDocumentOptionsBuilder;
118    }
119
120    impl FromValueOpt for GelatoReportDocumentOptions {
121        fn from_value(v: Value) -> Option<Self> {
122            let Value::Object(obj) = v else {
123                return None;
124            };
125            let mut b = GelatoReportDocumentOptionsBuilder::deser_default();
126            for (k, v) in obj {
127                match k.as_str() {
128                    "allowed_types" => b.allowed_types = FromValueOpt::from_value(v),
129                    "require_id_number" => b.require_id_number = FromValueOpt::from_value(v),
130                    "require_live_capture" => b.require_live_capture = FromValueOpt::from_value(v),
131                    "require_matching_selfie" => {
132                        b.require_matching_selfie = FromValueOpt::from_value(v)
133                    }
134                    _ => {}
135                }
136            }
137            b.take_out()
138        }
139    }
140};
141/// Array of strings of allowed identity document types.
142/// If the provided identity document isn’t one of the allowed types, the verification check will fail with a document_type_not_allowed error code.
143#[derive(Clone, Eq, PartialEq)]
144#[non_exhaustive]
145pub enum GelatoReportDocumentOptionsAllowedTypes {
146    DrivingLicense,
147    IdCard,
148    Passport,
149    /// An unrecognized value from Stripe. Should not be used as a request parameter.
150    Unknown(String),
151}
152impl GelatoReportDocumentOptionsAllowedTypes {
153    pub fn as_str(&self) -> &str {
154        use GelatoReportDocumentOptionsAllowedTypes::*;
155        match self {
156            DrivingLicense => "driving_license",
157            IdCard => "id_card",
158            Passport => "passport",
159            Unknown(v) => v,
160        }
161    }
162}
163
164impl std::str::FromStr for GelatoReportDocumentOptionsAllowedTypes {
165    type Err = std::convert::Infallible;
166    fn from_str(s: &str) -> Result<Self, Self::Err> {
167        use GelatoReportDocumentOptionsAllowedTypes::*;
168        match s {
169            "driving_license" => Ok(DrivingLicense),
170            "id_card" => Ok(IdCard),
171            "passport" => Ok(Passport),
172            v => {
173                tracing::warn!(
174                    "Unknown value '{}' for enum '{}'",
175                    v,
176                    "GelatoReportDocumentOptionsAllowedTypes"
177                );
178                Ok(Unknown(v.to_owned()))
179            }
180        }
181    }
182}
183impl std::fmt::Display for GelatoReportDocumentOptionsAllowedTypes {
184    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185        f.write_str(self.as_str())
186    }
187}
188
189impl std::fmt::Debug for GelatoReportDocumentOptionsAllowedTypes {
190    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
191        f.write_str(self.as_str())
192    }
193}
194#[cfg(feature = "serialize")]
195impl serde::Serialize for GelatoReportDocumentOptionsAllowedTypes {
196    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
197    where
198        S: serde::Serializer,
199    {
200        serializer.serialize_str(self.as_str())
201    }
202}
203impl miniserde::Deserialize for GelatoReportDocumentOptionsAllowedTypes {
204    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
205        crate::Place::new(out)
206    }
207}
208
209impl miniserde::de::Visitor for crate::Place<GelatoReportDocumentOptionsAllowedTypes> {
210    fn string(&mut self, s: &str) -> miniserde::Result<()> {
211        use std::str::FromStr;
212        self.out = Some(GelatoReportDocumentOptionsAllowedTypes::from_str(s).expect("infallible"));
213        Ok(())
214    }
215}
216
217stripe_types::impl_from_val_with_from_str!(GelatoReportDocumentOptionsAllowedTypes);
218#[cfg(feature = "deserialize")]
219impl<'de> serde::Deserialize<'de> for GelatoReportDocumentOptionsAllowedTypes {
220    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
221        use std::str::FromStr;
222        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
223        Ok(Self::from_str(&s).expect("infallible"))
224    }
225}