Skip to main content

stripe_shared/
issuing_authorization_fraud_challenge.rs

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