Skip to main content

stripe_shared/
issuing_card_fraud_warning.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 IssuingCardFraudWarning {
6    /// Timestamp of the most recent fraud warning.
7    pub started_at: Option<stripe_types::Timestamp>,
8    /// The type of fraud warning that most recently took place on this card.
9    /// This field updates with every new fraud warning, so the value changes over time.
10    /// If populated, cancel and reissue the card.
11    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
12    pub type_: Option<IssuingCardFraudWarningType>,
13}
14#[cfg(feature = "redact-generated-debug")]
15impl std::fmt::Debug for IssuingCardFraudWarning {
16    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17        f.debug_struct("IssuingCardFraudWarning").finish_non_exhaustive()
18    }
19}
20#[doc(hidden)]
21pub struct IssuingCardFraudWarningBuilder {
22    started_at: Option<Option<stripe_types::Timestamp>>,
23    type_: Option<Option<IssuingCardFraudWarningType>>,
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 IssuingCardFraudWarning {
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<IssuingCardFraudWarning>,
50        builder: IssuingCardFraudWarningBuilder,
51    }
52
53    impl Visitor for Place<IssuingCardFraudWarning> {
54        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55            Ok(Box::new(Builder {
56                out: &mut self.out,
57                builder: IssuingCardFraudWarningBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for IssuingCardFraudWarningBuilder {
63        type Out = IssuingCardFraudWarning;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "started_at" => Deserialize::begin(&mut self.started_at),
67                "type" => Deserialize::begin(&mut self.type_),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self { started_at: Deserialize::default(), type_: Deserialize::default() }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(started_at), Some(type_)) = (self.started_at, self.type_.take()) else {
78                return None;
79            };
80            Some(Self::Out { started_at, type_ })
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 IssuingCardFraudWarning {
96        type Builder = IssuingCardFraudWarningBuilder;
97    }
98
99    impl FromValueOpt for IssuingCardFraudWarning {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = IssuingCardFraudWarningBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "started_at" => b.started_at = FromValueOpt::from_value(v),
108                    "type" => b.type_ = FromValueOpt::from_value(v),
109                    _ => {}
110                }
111            }
112            b.take_out()
113        }
114    }
115};
116/// The type of fraud warning that most recently took place on this card.
117/// This field updates with every new fraud warning, so the value changes over time.
118/// If populated, cancel and reissue the card.
119#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum IssuingCardFraudWarningType {
122    CardTestingExposure,
123    FraudDisputeFiled,
124    ThirdPartyReported,
125    UserIndicatedFraud,
126    /// An unrecognized value from Stripe. Should not be used as a request parameter.
127    Unknown(String),
128}
129impl IssuingCardFraudWarningType {
130    pub fn as_str(&self) -> &str {
131        use IssuingCardFraudWarningType::*;
132        match self {
133            CardTestingExposure => "card_testing_exposure",
134            FraudDisputeFiled => "fraud_dispute_filed",
135            ThirdPartyReported => "third_party_reported",
136            UserIndicatedFraud => "user_indicated_fraud",
137            Unknown(v) => v,
138        }
139    }
140}
141
142impl std::str::FromStr for IssuingCardFraudWarningType {
143    type Err = std::convert::Infallible;
144    fn from_str(s: &str) -> Result<Self, Self::Err> {
145        use IssuingCardFraudWarningType::*;
146        match s {
147            "card_testing_exposure" => Ok(CardTestingExposure),
148            "fraud_dispute_filed" => Ok(FraudDisputeFiled),
149            "third_party_reported" => Ok(ThirdPartyReported),
150            "user_indicated_fraud" => Ok(UserIndicatedFraud),
151            v => {
152                tracing::warn!(
153                    "Unknown value '{}' for enum '{}'",
154                    v,
155                    "IssuingCardFraudWarningType"
156                );
157                Ok(Unknown(v.to_owned()))
158            }
159        }
160    }
161}
162impl std::fmt::Display for IssuingCardFraudWarningType {
163    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164        f.write_str(self.as_str())
165    }
166}
167
168#[cfg(not(feature = "redact-generated-debug"))]
169impl std::fmt::Debug for IssuingCardFraudWarningType {
170    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171        f.write_str(self.as_str())
172    }
173}
174#[cfg(feature = "redact-generated-debug")]
175impl std::fmt::Debug for IssuingCardFraudWarningType {
176    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177        f.debug_struct(stringify!(IssuingCardFraudWarningType)).finish_non_exhaustive()
178    }
179}
180#[cfg(feature = "serialize")]
181impl serde::Serialize for IssuingCardFraudWarningType {
182    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
183    where
184        S: serde::Serializer,
185    {
186        serializer.serialize_str(self.as_str())
187    }
188}
189impl miniserde::Deserialize for IssuingCardFraudWarningType {
190    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
191        crate::Place::new(out)
192    }
193}
194
195impl miniserde::de::Visitor for crate::Place<IssuingCardFraudWarningType> {
196    fn string(&mut self, s: &str) -> miniserde::Result<()> {
197        use std::str::FromStr;
198        self.out = Some(IssuingCardFraudWarningType::from_str(s).expect("infallible"));
199        Ok(())
200    }
201}
202
203stripe_types::impl_from_val_with_from_str!(IssuingCardFraudWarningType);
204#[cfg(feature = "deserialize")]
205impl<'de> serde::Deserialize<'de> for IssuingCardFraudWarningType {
206    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
207        use std::str::FromStr;
208        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
209        Ok(Self::from_str(&s).expect("infallible"))
210    }
211}