stripe_shared/
issuing_card_fraud_warning.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingCardFraudWarning {
5    /// Timestamp of the most recent fraud warning.
6    pub started_at: Option<stripe_types::Timestamp>,
7    /// The type of fraud warning that most recently took place on this card.
8    /// This field updates with every new fraud warning, so the value changes over time.
9    /// If populated, cancel and reissue the card.
10    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
11    pub type_: Option<IssuingCardFraudWarningType>,
12}
13#[doc(hidden)]
14pub struct IssuingCardFraudWarningBuilder {
15    started_at: Option<Option<stripe_types::Timestamp>>,
16    type_: Option<Option<IssuingCardFraudWarningType>>,
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 IssuingCardFraudWarning {
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<IssuingCardFraudWarning>,
43        builder: IssuingCardFraudWarningBuilder,
44    }
45
46    impl Visitor for Place<IssuingCardFraudWarning> {
47        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48            Ok(Box::new(Builder {
49                out: &mut self.out,
50                builder: IssuingCardFraudWarningBuilder::deser_default(),
51            }))
52        }
53    }
54
55    impl MapBuilder for IssuingCardFraudWarningBuilder {
56        type Out = IssuingCardFraudWarning;
57        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58            Ok(match k {
59                "started_at" => Deserialize::begin(&mut self.started_at),
60                "type" => Deserialize::begin(&mut self.type_),
61                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self { started_at: Deserialize::default(), type_: Deserialize::default() }
67        }
68
69        fn take_out(&mut self) -> Option<Self::Out> {
70            let (Some(started_at), Some(type_)) = (self.started_at, self.type_) else {
71                return None;
72            };
73            Some(Self::Out { started_at, type_ })
74        }
75    }
76
77    impl Map for Builder<'_> {
78        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
79            self.builder.key(k)
80        }
81
82        fn finish(&mut self) -> Result<()> {
83            *self.out = self.builder.take_out();
84            Ok(())
85        }
86    }
87
88    impl ObjectDeser for IssuingCardFraudWarning {
89        type Builder = IssuingCardFraudWarningBuilder;
90    }
91
92    impl FromValueOpt for IssuingCardFraudWarning {
93        fn from_value(v: Value) -> Option<Self> {
94            let Value::Object(obj) = v else {
95                return None;
96            };
97            let mut b = IssuingCardFraudWarningBuilder::deser_default();
98            for (k, v) in obj {
99                match k.as_str() {
100                    "started_at" => b.started_at = FromValueOpt::from_value(v),
101                    "type" => b.type_ = FromValueOpt::from_value(v),
102                    _ => {}
103                }
104            }
105            b.take_out()
106        }
107    }
108};
109/// The type of fraud warning that most recently took place on this card.
110/// This field updates with every new fraud warning, so the value changes over time.
111/// If populated, cancel and reissue the card.
112#[derive(Copy, Clone, Eq, PartialEq)]
113pub enum IssuingCardFraudWarningType {
114    CardTestingExposure,
115    FraudDisputeFiled,
116    ThirdPartyReported,
117    UserIndicatedFraud,
118}
119impl IssuingCardFraudWarningType {
120    pub fn as_str(self) -> &'static str {
121        use IssuingCardFraudWarningType::*;
122        match self {
123            CardTestingExposure => "card_testing_exposure",
124            FraudDisputeFiled => "fraud_dispute_filed",
125            ThirdPartyReported => "third_party_reported",
126            UserIndicatedFraud => "user_indicated_fraud",
127        }
128    }
129}
130
131impl std::str::FromStr for IssuingCardFraudWarningType {
132    type Err = stripe_types::StripeParseError;
133    fn from_str(s: &str) -> Result<Self, Self::Err> {
134        use IssuingCardFraudWarningType::*;
135        match s {
136            "card_testing_exposure" => Ok(CardTestingExposure),
137            "fraud_dispute_filed" => Ok(FraudDisputeFiled),
138            "third_party_reported" => Ok(ThirdPartyReported),
139            "user_indicated_fraud" => Ok(UserIndicatedFraud),
140            _ => Err(stripe_types::StripeParseError),
141        }
142    }
143}
144impl std::fmt::Display for IssuingCardFraudWarningType {
145    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
146        f.write_str(self.as_str())
147    }
148}
149
150impl std::fmt::Debug for IssuingCardFraudWarningType {
151    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152        f.write_str(self.as_str())
153    }
154}
155#[cfg(feature = "serialize")]
156impl serde::Serialize for IssuingCardFraudWarningType {
157    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
158    where
159        S: serde::Serializer,
160    {
161        serializer.serialize_str(self.as_str())
162    }
163}
164impl miniserde::Deserialize for IssuingCardFraudWarningType {
165    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
166        crate::Place::new(out)
167    }
168}
169
170impl miniserde::de::Visitor for crate::Place<IssuingCardFraudWarningType> {
171    fn string(&mut self, s: &str) -> miniserde::Result<()> {
172        use std::str::FromStr;
173        self.out = Some(IssuingCardFraudWarningType::from_str(s).map_err(|_| miniserde::Error)?);
174        Ok(())
175    }
176}
177
178stripe_types::impl_from_val_with_from_str!(IssuingCardFraudWarningType);
179#[cfg(feature = "deserialize")]
180impl<'de> serde::Deserialize<'de> for IssuingCardFraudWarningType {
181    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
182        use std::str::FromStr;
183        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
184        Self::from_str(&s)
185            .map_err(|_| serde::de::Error::custom("Unknown value for IssuingCardFraudWarningType"))
186    }
187}