stripe_shared/
issuing_card_fraud_warning.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingCardFraudWarning {
5 pub started_at: Option<stripe_types::Timestamp>,
7 #[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_.take()) 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#[derive(Clone, Eq, PartialEq)]
113#[non_exhaustive]
114pub enum IssuingCardFraudWarningType {
115 CardTestingExposure,
116 FraudDisputeFiled,
117 ThirdPartyReported,
118 UserIndicatedFraud,
119 Unknown(String),
121}
122impl IssuingCardFraudWarningType {
123 pub fn as_str(&self) -> &str {
124 use IssuingCardFraudWarningType::*;
125 match self {
126 CardTestingExposure => "card_testing_exposure",
127 FraudDisputeFiled => "fraud_dispute_filed",
128 ThirdPartyReported => "third_party_reported",
129 UserIndicatedFraud => "user_indicated_fraud",
130 Unknown(v) => v,
131 }
132 }
133}
134
135impl std::str::FromStr for IssuingCardFraudWarningType {
136 type Err = std::convert::Infallible;
137 fn from_str(s: &str) -> Result<Self, Self::Err> {
138 use IssuingCardFraudWarningType::*;
139 match s {
140 "card_testing_exposure" => Ok(CardTestingExposure),
141 "fraud_dispute_filed" => Ok(FraudDisputeFiled),
142 "third_party_reported" => Ok(ThirdPartyReported),
143 "user_indicated_fraud" => Ok(UserIndicatedFraud),
144 v => {
145 tracing::warn!(
146 "Unknown value '{}' for enum '{}'",
147 v,
148 "IssuingCardFraudWarningType"
149 );
150 Ok(Unknown(v.to_owned()))
151 }
152 }
153 }
154}
155impl std::fmt::Display for IssuingCardFraudWarningType {
156 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
157 f.write_str(self.as_str())
158 }
159}
160
161impl std::fmt::Debug for IssuingCardFraudWarningType {
162 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
163 f.write_str(self.as_str())
164 }
165}
166#[cfg(feature = "serialize")]
167impl serde::Serialize for IssuingCardFraudWarningType {
168 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
169 where
170 S: serde::Serializer,
171 {
172 serializer.serialize_str(self.as_str())
173 }
174}
175impl miniserde::Deserialize for IssuingCardFraudWarningType {
176 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
177 crate::Place::new(out)
178 }
179}
180
181impl miniserde::de::Visitor for crate::Place<IssuingCardFraudWarningType> {
182 fn string(&mut self, s: &str) -> miniserde::Result<()> {
183 use std::str::FromStr;
184 self.out = Some(IssuingCardFraudWarningType::from_str(s).expect("infallible"));
185 Ok(())
186 }
187}
188
189stripe_types::impl_from_val_with_from_str!(IssuingCardFraudWarningType);
190#[cfg(feature = "deserialize")]
191impl<'de> serde::Deserialize<'de> for IssuingCardFraudWarningType {
192 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
193 use std::str::FromStr;
194 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
195 Ok(Self::from_str(&s).expect("infallible"))
196 }
197}