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::{make_place, Deserialize, Result};
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
63                _ => <dyn Visitor>::ignore(),
64            })
65        }
66
67        fn deser_default() -> Self {
68            Self {
69                channel: Deserialize::default(),
70                status: Deserialize::default(),
71                undeliverable_reason: Deserialize::default(),
72            }
73        }
74
75        fn take_out(&mut self) -> Option<Self::Out> {
76            let (Some(channel), Some(status), Some(undeliverable_reason)) =
77                (self.channel, self.status, self.undeliverable_reason)
78            else {
79                return None;
80            };
81            Some(Self::Out { channel, status, undeliverable_reason })
82        }
83    }
84
85    impl<'a> Map for Builder<'a> {
86        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
87            self.builder.key(k)
88        }
89
90        fn finish(&mut self) -> Result<()> {
91            *self.out = self.builder.take_out();
92            Ok(())
93        }
94    }
95
96    impl ObjectDeser for IssuingAuthorizationFraudChallenge {
97        type Builder = IssuingAuthorizationFraudChallengeBuilder;
98    }
99
100    impl FromValueOpt for IssuingAuthorizationFraudChallenge {
101        fn from_value(v: Value) -> Option<Self> {
102            let Value::Object(obj) = v else {
103                return None;
104            };
105            let mut b = IssuingAuthorizationFraudChallengeBuilder::deser_default();
106            for (k, v) in obj {
107                match k.as_str() {
108                    "channel" => b.channel = FromValueOpt::from_value(v),
109                    "status" => b.status = FromValueOpt::from_value(v),
110                    "undeliverable_reason" => b.undeliverable_reason = FromValueOpt::from_value(v),
111
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// The method by which the fraud challenge was delivered to the cardholder.
120#[derive(Copy, Clone, Eq, PartialEq)]
121pub enum IssuingAuthorizationFraudChallengeChannel {
122    Sms,
123}
124impl IssuingAuthorizationFraudChallengeChannel {
125    pub fn as_str(self) -> &'static str {
126        use IssuingAuthorizationFraudChallengeChannel::*;
127        match self {
128            Sms => "sms",
129        }
130    }
131}
132
133impl std::str::FromStr for IssuingAuthorizationFraudChallengeChannel {
134    type Err = stripe_types::StripeParseError;
135    fn from_str(s: &str) -> Result<Self, Self::Err> {
136        use IssuingAuthorizationFraudChallengeChannel::*;
137        match s {
138            "sms" => Ok(Sms),
139            _ => Err(stripe_types::StripeParseError),
140        }
141    }
142}
143impl std::fmt::Display for IssuingAuthorizationFraudChallengeChannel {
144    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
145        f.write_str(self.as_str())
146    }
147}
148
149impl std::fmt::Debug for IssuingAuthorizationFraudChallengeChannel {
150    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151        f.write_str(self.as_str())
152    }
153}
154#[cfg(feature = "serialize")]
155impl serde::Serialize for IssuingAuthorizationFraudChallengeChannel {
156    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
157    where
158        S: serde::Serializer,
159    {
160        serializer.serialize_str(self.as_str())
161    }
162}
163impl miniserde::Deserialize for IssuingAuthorizationFraudChallengeChannel {
164    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
165        crate::Place::new(out)
166    }
167}
168
169impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFraudChallengeChannel> {
170    fn string(&mut self, s: &str) -> miniserde::Result<()> {
171        use std::str::FromStr;
172        self.out = Some(
173            IssuingAuthorizationFraudChallengeChannel::from_str(s).map_err(|_| miniserde::Error)?,
174        );
175        Ok(())
176    }
177}
178
179stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFraudChallengeChannel);
180#[cfg(feature = "deserialize")]
181impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFraudChallengeChannel {
182    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
183        use std::str::FromStr;
184        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
185        Self::from_str(&s).map_err(|_| {
186            serde::de::Error::custom("Unknown value for IssuingAuthorizationFraudChallengeChannel")
187        })
188    }
189}
190/// The status of the fraud challenge.
191#[derive(Copy, Clone, Eq, PartialEq)]
192pub enum IssuingAuthorizationFraudChallengeStatus {
193    Expired,
194    Pending,
195    Rejected,
196    Undeliverable,
197    Verified,
198}
199impl IssuingAuthorizationFraudChallengeStatus {
200    pub fn as_str(self) -> &'static str {
201        use IssuingAuthorizationFraudChallengeStatus::*;
202        match self {
203            Expired => "expired",
204            Pending => "pending",
205            Rejected => "rejected",
206            Undeliverable => "undeliverable",
207            Verified => "verified",
208        }
209    }
210}
211
212impl std::str::FromStr for IssuingAuthorizationFraudChallengeStatus {
213    type Err = stripe_types::StripeParseError;
214    fn from_str(s: &str) -> Result<Self, Self::Err> {
215        use IssuingAuthorizationFraudChallengeStatus::*;
216        match s {
217            "expired" => Ok(Expired),
218            "pending" => Ok(Pending),
219            "rejected" => Ok(Rejected),
220            "undeliverable" => Ok(Undeliverable),
221            "verified" => Ok(Verified),
222            _ => Err(stripe_types::StripeParseError),
223        }
224    }
225}
226impl std::fmt::Display for IssuingAuthorizationFraudChallengeStatus {
227    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
228        f.write_str(self.as_str())
229    }
230}
231
232impl std::fmt::Debug for IssuingAuthorizationFraudChallengeStatus {
233    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
234        f.write_str(self.as_str())
235    }
236}
237#[cfg(feature = "serialize")]
238impl serde::Serialize for IssuingAuthorizationFraudChallengeStatus {
239    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
240    where
241        S: serde::Serializer,
242    {
243        serializer.serialize_str(self.as_str())
244    }
245}
246impl miniserde::Deserialize for IssuingAuthorizationFraudChallengeStatus {
247    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
248        crate::Place::new(out)
249    }
250}
251
252impl miniserde::de::Visitor for crate::Place<IssuingAuthorizationFraudChallengeStatus> {
253    fn string(&mut self, s: &str) -> miniserde::Result<()> {
254        use std::str::FromStr;
255        self.out = Some(
256            IssuingAuthorizationFraudChallengeStatus::from_str(s).map_err(|_| miniserde::Error)?,
257        );
258        Ok(())
259    }
260}
261
262stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFraudChallengeStatus);
263#[cfg(feature = "deserialize")]
264impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFraudChallengeStatus {
265    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
266        use std::str::FromStr;
267        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
268        Self::from_str(&s).map_err(|_| {
269            serde::de::Error::custom("Unknown value for IssuingAuthorizationFraudChallengeStatus")
270        })
271    }
272}
273/// If the challenge is not deliverable, the reason why.
274#[derive(Copy, Clone, Eq, PartialEq)]
275pub enum IssuingAuthorizationFraudChallengeUndeliverableReason {
276    NoPhoneNumber,
277    UnsupportedPhoneNumber,
278}
279impl IssuingAuthorizationFraudChallengeUndeliverableReason {
280    pub fn as_str(self) -> &'static str {
281        use IssuingAuthorizationFraudChallengeUndeliverableReason::*;
282        match self {
283            NoPhoneNumber => "no_phone_number",
284            UnsupportedPhoneNumber => "unsupported_phone_number",
285        }
286    }
287}
288
289impl std::str::FromStr for IssuingAuthorizationFraudChallengeUndeliverableReason {
290    type Err = stripe_types::StripeParseError;
291    fn from_str(s: &str) -> Result<Self, Self::Err> {
292        use IssuingAuthorizationFraudChallengeUndeliverableReason::*;
293        match s {
294            "no_phone_number" => Ok(NoPhoneNumber),
295            "unsupported_phone_number" => Ok(UnsupportedPhoneNumber),
296            _ => Err(stripe_types::StripeParseError),
297        }
298    }
299}
300impl std::fmt::Display for IssuingAuthorizationFraudChallengeUndeliverableReason {
301    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
302        f.write_str(self.as_str())
303    }
304}
305
306impl std::fmt::Debug for IssuingAuthorizationFraudChallengeUndeliverableReason {
307    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308        f.write_str(self.as_str())
309    }
310}
311#[cfg(feature = "serialize")]
312impl serde::Serialize for IssuingAuthorizationFraudChallengeUndeliverableReason {
313    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
314    where
315        S: serde::Serializer,
316    {
317        serializer.serialize_str(self.as_str())
318    }
319}
320impl miniserde::Deserialize for IssuingAuthorizationFraudChallengeUndeliverableReason {
321    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
322        crate::Place::new(out)
323    }
324}
325
326impl miniserde::de::Visitor
327    for crate::Place<IssuingAuthorizationFraudChallengeUndeliverableReason>
328{
329    fn string(&mut self, s: &str) -> miniserde::Result<()> {
330        use std::str::FromStr;
331        self.out = Some(
332            IssuingAuthorizationFraudChallengeUndeliverableReason::from_str(s)
333                .map_err(|_| miniserde::Error)?,
334        );
335        Ok(())
336    }
337}
338
339stripe_types::impl_from_val_with_from_str!(IssuingAuthorizationFraudChallengeUndeliverableReason);
340#[cfg(feature = "deserialize")]
341impl<'de> serde::Deserialize<'de> for IssuingAuthorizationFraudChallengeUndeliverableReason {
342    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
343        use std::str::FromStr;
344        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
345        Self::from_str(&s).map_err(|_| {
346            serde::de::Error::custom(
347                "Unknown value for IssuingAuthorizationFraudChallengeUndeliverableReason",
348            )
349        })
350    }
351}