stripe_shared/
issuing_authorization_fraud_challenge.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingAuthorizationFraudChallenge {
5    /// The method by which the fraud challenge was delivered to the cardholder.
6    pub channel: IssuingAuthorizationFraudChallengeChannel,
7    /// The status of the fraud challenge.
8    pub status: IssuingAuthorizationFraudChallengeStatus,
9    /// If the challenge is not deliverable, the reason why.
10    pub undeliverable_reason: Option<IssuingAuthorizationFraudChallengeUndeliverableReason>,
11}
12#[doc(hidden)]
13pub struct IssuingAuthorizationFraudChallengeBuilder {
14    channel: Option<IssuingAuthorizationFraudChallengeChannel>,
15    status: Option<IssuingAuthorizationFraudChallengeStatus>,
16    undeliverable_reason: Option<Option<IssuingAuthorizationFraudChallengeUndeliverableReason>>,
17}
18
19#[allow(
20    unused_variables,
21    irrefutable_let_patterns,
22    clippy::let_unit_value,
23    clippy::match_single_binding,
24    clippy::single_match
25)]
26const _: () = {
27    use miniserde::de::{Map, Visitor};
28    use miniserde::json::Value;
29    use miniserde::{Deserialize, Result, make_place};
30    use stripe_types::miniserde_helpers::FromValueOpt;
31    use stripe_types::{MapBuilder, ObjectDeser};
32
33    make_place!(Place);
34
35    impl Deserialize for IssuingAuthorizationFraudChallenge {
36        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
37            Place::new(out)
38        }
39    }
40
41    struct Builder<'a> {
42        out: &'a mut Option<IssuingAuthorizationFraudChallenge>,
43        builder: IssuingAuthorizationFraudChallengeBuilder,
44    }
45
46    impl Visitor for Place<IssuingAuthorizationFraudChallenge> {
47        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48            Ok(Box::new(Builder {
49                out: &mut self.out,
50                builder: IssuingAuthorizationFraudChallengeBuilder::deser_default(),
51            }))
52        }
53    }
54
55    impl MapBuilder for IssuingAuthorizationFraudChallengeBuilder {
56        type Out = IssuingAuthorizationFraudChallenge;
57        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58            Ok(match k {
59                "channel" => Deserialize::begin(&mut self.channel),
60                "status" => Deserialize::begin(&mut self.status),
61                "undeliverable_reason" => Deserialize::begin(&mut self.undeliverable_reason),
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self {
68                channel: Deserialize::default(),
69                status: Deserialize::default(),
70                undeliverable_reason: Deserialize::default(),
71            }
72        }
73
74        fn take_out(&mut self) -> Option<Self::Out> {
75            let (Some(channel), Some(status), Some(undeliverable_reason)) =
76                (self.channel, self.status, self.undeliverable_reason)
77            else {
78                return None;
79            };
80            Some(Self::Out { channel, status, undeliverable_reason })
81        }
82    }
83
84    impl Map for Builder<'_> {
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            self.builder.key(k)
87        }
88
89        fn finish(&mut self) -> Result<()> {
90            *self.out = self.builder.take_out();
91            Ok(())
92        }
93    }
94
95    impl ObjectDeser for IssuingAuthorizationFraudChallenge {
96        type Builder = IssuingAuthorizationFraudChallengeBuilder;
97    }
98
99    impl FromValueOpt for IssuingAuthorizationFraudChallenge {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = IssuingAuthorizationFraudChallengeBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "channel" => b.channel = FromValueOpt::from_value(v),
108                    "status" => b.status = FromValueOpt::from_value(v),
109                    "undeliverable_reason" => b.undeliverable_reason = FromValueOpt::from_value(v),
110                    _ => {}
111                }
112            }
113            b.take_out()
114        }
115    }
116};
117/// The method by which the fraud challenge was delivered to the cardholder.
118#[derive(Copy, Clone, Eq, PartialEq)]
119pub enum IssuingAuthorizationFraudChallengeChannel {
120    Sms,
121}
122impl IssuingAuthorizationFraudChallengeChannel {
123    pub fn as_str(self) -> &'static str {
124        use IssuingAuthorizationFraudChallengeChannel::*;
125        match self {
126            Sms => "sms",
127        }
128    }
129}
130
131impl std::str::FromStr for IssuingAuthorizationFraudChallengeChannel {
132    type Err = stripe_types::StripeParseError;
133    fn from_str(s: &str) -> Result<Self, Self::Err> {
134        use IssuingAuthorizationFraudChallengeChannel::*;
135        match s {
136            "sms" => Ok(Sms),
137            _ => Err(stripe_types::StripeParseError),
138        }
139    }
140}
141impl std::fmt::Display for IssuingAuthorizationFraudChallengeChannel {
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 IssuingAuthorizationFraudChallengeChannel {
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 IssuingAuthorizationFraudChallengeChannel {
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 IssuingAuthorizationFraudChallengeChannel {
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<IssuingAuthorizationFraudChallengeChannel> {
168    fn string(&mut self, s: &str) -> miniserde::Result<()> {
169        use std::str::FromStr;
170        self.out = Some(
171            IssuingAuthorizationFraudChallengeChannel::from_str(s).map_err(|_| miniserde::Error)?,
172        );
173        Ok(())
174    }
175}
176
177stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFraudChallengeChannel);
178#[cfg(feature = "deserialize")]
179impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFraudChallengeChannel {
180    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
181        use std::str::FromStr;
182        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
183        Self::from_str(&s).map_err(|_| {
184            serde::de::Error::custom("Unknown value for IssuingAuthorizationFraudChallengeChannel")
185        })
186    }
187}
188/// The status of the fraud challenge.
189#[derive(Copy, Clone, Eq, PartialEq)]
190pub enum IssuingAuthorizationFraudChallengeStatus {
191    Expired,
192    Pending,
193    Rejected,
194    Undeliverable,
195    Verified,
196}
197impl IssuingAuthorizationFraudChallengeStatus {
198    pub fn as_str(self) -> &'static str {
199        use IssuingAuthorizationFraudChallengeStatus::*;
200        match self {
201            Expired => "expired",
202            Pending => "pending",
203            Rejected => "rejected",
204            Undeliverable => "undeliverable",
205            Verified => "verified",
206        }
207    }
208}
209
210impl std::str::FromStr for IssuingAuthorizationFraudChallengeStatus {
211    type Err = stripe_types::StripeParseError;
212    fn from_str(s: &str) -> Result<Self, Self::Err> {
213        use IssuingAuthorizationFraudChallengeStatus::*;
214        match s {
215            "expired" => Ok(Expired),
216            "pending" => Ok(Pending),
217            "rejected" => Ok(Rejected),
218            "undeliverable" => Ok(Undeliverable),
219            "verified" => Ok(Verified),
220            _ => Err(stripe_types::StripeParseError),
221        }
222    }
223}
224impl std::fmt::Display for IssuingAuthorizationFraudChallengeStatus {
225    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
226        f.write_str(self.as_str())
227    }
228}
229
230impl std::fmt::Debug for IssuingAuthorizationFraudChallengeStatus {
231    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232        f.write_str(self.as_str())
233    }
234}
235#[cfg(feature = "serialize")]
236impl serde::Serialize for IssuingAuthorizationFraudChallengeStatus {
237    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
238    where
239        S: serde::Serializer,
240    {
241        serializer.serialize_str(self.as_str())
242    }
243}
244impl miniserde::Deserialize for IssuingAuthorizationFraudChallengeStatus {
245    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
246        crate::Place::new(out)
247    }
248}
249
250impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFraudChallengeStatus> {
251    fn string(&mut self, s: &str) -> miniserde::Result<()> {
252        use std::str::FromStr;
253        self.out = Some(
254            IssuingAuthorizationFraudChallengeStatus::from_str(s).map_err(|_| miniserde::Error)?,
255        );
256        Ok(())
257    }
258}
259
260stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFraudChallengeStatus);
261#[cfg(feature = "deserialize")]
262impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFraudChallengeStatus {
263    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
264        use std::str::FromStr;
265        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
266        Self::from_str(&s).map_err(|_| {
267            serde::de::Error::custom("Unknown value for IssuingAuthorizationFraudChallengeStatus")
268        })
269    }
270}
271/// If the challenge is not deliverable, the reason why.
272#[derive(Copy, Clone, Eq, PartialEq)]
273pub enum IssuingAuthorizationFraudChallengeUndeliverableReason {
274    NoPhoneNumber,
275    UnsupportedPhoneNumber,
276}
277impl IssuingAuthorizationFraudChallengeUndeliverableReason {
278    pub fn as_str(self) -> &'static str {
279        use IssuingAuthorizationFraudChallengeUndeliverableReason::*;
280        match self {
281            NoPhoneNumber => "no_phone_number",
282            UnsupportedPhoneNumber => "unsupported_phone_number",
283        }
284    }
285}
286
287impl std::str::FromStr for IssuingAuthorizationFraudChallengeUndeliverableReason {
288    type Err = stripe_types::StripeParseError;
289    fn from_str(s: &str) -> Result<Self, Self::Err> {
290        use IssuingAuthorizationFraudChallengeUndeliverableReason::*;
291        match s {
292            "no_phone_number" => Ok(NoPhoneNumber),
293            "unsupported_phone_number" => Ok(UnsupportedPhoneNumber),
294            _ => Err(stripe_types::StripeParseError),
295        }
296    }
297}
298impl std::fmt::Display for IssuingAuthorizationFraudChallengeUndeliverableReason {
299    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
300        f.write_str(self.as_str())
301    }
302}
303
304impl std::fmt::Debug for IssuingAuthorizationFraudChallengeUndeliverableReason {
305    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
306        f.write_str(self.as_str())
307    }
308}
309#[cfg(feature = "serialize")]
310impl serde::Serialize for IssuingAuthorizationFraudChallengeUndeliverableReason {
311    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
312    where
313        S: serde::Serializer,
314    {
315        serializer.serialize_str(self.as_str())
316    }
317}
318impl miniserde::Deserialize for IssuingAuthorizationFraudChallengeUndeliverableReason {
319    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
320        crate::Place::new(out)
321    }
322}
323
324impl miniserde::de::Visitor
325    for crate::Place<IssuingAuthorizationFraudChallengeUndeliverableReason>
326{
327    fn string(&mut self, s: &str) -> miniserde::Result<()> {
328        use std::str::FromStr;
329        self.out = Some(
330            IssuingAuthorizationFraudChallengeUndeliverableReason::from_str(s)
331                .map_err(|_| miniserde::Error)?,
332        );
333        Ok(())
334    }
335}
336
337stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFraudChallengeUndeliverableReason);
338#[cfg(feature = "deserialize")]
339impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFraudChallengeUndeliverableReason {
340    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
341        use std::str::FromStr;
342        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
343        Self::from_str(&s).map_err(|_| {
344            serde::de::Error::custom(
345                "Unknown value for IssuingAuthorizationFraudChallengeUndeliverableReason",
346            )
347        })
348    }
349}