stripe_shared/
issuing_dispute_evidence.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingDisputeEvidence {
5    pub canceled: Option<stripe_shared::IssuingDisputeCanceledEvidence>,
6    pub duplicate: Option<stripe_shared::IssuingDisputeDuplicateEvidence>,
7    pub fraudulent: Option<stripe_shared::IssuingDisputeFraudulentEvidence>,
8    pub merchandise_not_as_described:
9        Option<stripe_shared::IssuingDisputeMerchandiseNotAsDescribedEvidence>,
10    pub no_valid_authorization: Option<stripe_shared::IssuingDisputeNoValidAuthorizationEvidence>,
11    pub not_received: Option<stripe_shared::IssuingDisputeNotReceivedEvidence>,
12    pub other: Option<stripe_shared::IssuingDisputeOtherEvidence>,
13    /// The reason for filing the dispute. Its value will match the field containing the evidence.
14    pub reason: IssuingDisputeEvidenceReason,
15    pub service_not_as_described:
16        Option<stripe_shared::IssuingDisputeServiceNotAsDescribedEvidence>,
17}
18#[doc(hidden)]
19pub struct IssuingDisputeEvidenceBuilder {
20    canceled: Option<Option<stripe_shared::IssuingDisputeCanceledEvidence>>,
21    duplicate: Option<Option<stripe_shared::IssuingDisputeDuplicateEvidence>>,
22    fraudulent: Option<Option<stripe_shared::IssuingDisputeFraudulentEvidence>>,
23    merchandise_not_as_described:
24        Option<Option<stripe_shared::IssuingDisputeMerchandiseNotAsDescribedEvidence>>,
25    no_valid_authorization:
26        Option<Option<stripe_shared::IssuingDisputeNoValidAuthorizationEvidence>>,
27    not_received: Option<Option<stripe_shared::IssuingDisputeNotReceivedEvidence>>,
28    other: Option<Option<stripe_shared::IssuingDisputeOtherEvidence>>,
29    reason: Option<IssuingDisputeEvidenceReason>,
30    service_not_as_described:
31        Option<Option<stripe_shared::IssuingDisputeServiceNotAsDescribedEvidence>>,
32}
33
34#[allow(
35    unused_variables,
36    irrefutable_let_patterns,
37    clippy::let_unit_value,
38    clippy::match_single_binding,
39    clippy::single_match
40)]
41const _: () = {
42    use miniserde::de::{Map, Visitor};
43    use miniserde::json::Value;
44    use miniserde::{Deserialize, Result, make_place};
45    use stripe_types::miniserde_helpers::FromValueOpt;
46    use stripe_types::{MapBuilder, ObjectDeser};
47
48    make_place!(Place);
49
50    impl Deserialize for IssuingDisputeEvidence {
51        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
52            Place::new(out)
53        }
54    }
55
56    struct Builder<'a> {
57        out: &'a mut Option<IssuingDisputeEvidence>,
58        builder: IssuingDisputeEvidenceBuilder,
59    }
60
61    impl Visitor for Place<IssuingDisputeEvidence> {
62        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
63            Ok(Box::new(Builder {
64                out: &mut self.out,
65                builder: IssuingDisputeEvidenceBuilder::deser_default(),
66            }))
67        }
68    }
69
70    impl MapBuilder for IssuingDisputeEvidenceBuilder {
71        type Out = IssuingDisputeEvidence;
72        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
73            Ok(match k {
74                "canceled" => Deserialize::begin(&mut self.canceled),
75                "duplicate" => Deserialize::begin(&mut self.duplicate),
76                "fraudulent" => Deserialize::begin(&mut self.fraudulent),
77                "merchandise_not_as_described" => {
78                    Deserialize::begin(&mut self.merchandise_not_as_described)
79                }
80                "no_valid_authorization" => Deserialize::begin(&mut self.no_valid_authorization),
81                "not_received" => Deserialize::begin(&mut self.not_received),
82                "other" => Deserialize::begin(&mut self.other),
83                "reason" => Deserialize::begin(&mut self.reason),
84                "service_not_as_described" => {
85                    Deserialize::begin(&mut self.service_not_as_described)
86                }
87                _ => <dyn Visitor>::ignore(),
88            })
89        }
90
91        fn deser_default() -> Self {
92            Self {
93                canceled: Deserialize::default(),
94                duplicate: Deserialize::default(),
95                fraudulent: Deserialize::default(),
96                merchandise_not_as_described: Deserialize::default(),
97                no_valid_authorization: Deserialize::default(),
98                not_received: Deserialize::default(),
99                other: Deserialize::default(),
100                reason: Deserialize::default(),
101                service_not_as_described: Deserialize::default(),
102            }
103        }
104
105        fn take_out(&mut self) -> Option<Self::Out> {
106            let (
107                Some(canceled),
108                Some(duplicate),
109                Some(fraudulent),
110                Some(merchandise_not_as_described),
111                Some(no_valid_authorization),
112                Some(not_received),
113                Some(other),
114                Some(reason),
115                Some(service_not_as_described),
116            ) = (
117                self.canceled.take(),
118                self.duplicate.take(),
119                self.fraudulent.take(),
120                self.merchandise_not_as_described.take(),
121                self.no_valid_authorization.take(),
122                self.not_received.take(),
123                self.other.take(),
124                self.reason.take(),
125                self.service_not_as_described.take(),
126            )
127            else {
128                return None;
129            };
130            Some(Self::Out {
131                canceled,
132                duplicate,
133                fraudulent,
134                merchandise_not_as_described,
135                no_valid_authorization,
136                not_received,
137                other,
138                reason,
139                service_not_as_described,
140            })
141        }
142    }
143
144    impl Map for Builder<'_> {
145        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
146            self.builder.key(k)
147        }
148
149        fn finish(&mut self) -> Result<()> {
150            *self.out = self.builder.take_out();
151            Ok(())
152        }
153    }
154
155    impl ObjectDeser for IssuingDisputeEvidence {
156        type Builder = IssuingDisputeEvidenceBuilder;
157    }
158
159    impl FromValueOpt for IssuingDisputeEvidence {
160        fn from_value(v: Value) -> Option<Self> {
161            let Value::Object(obj) = v else {
162                return None;
163            };
164            let mut b = IssuingDisputeEvidenceBuilder::deser_default();
165            for (k, v) in obj {
166                match k.as_str() {
167                    "canceled" => b.canceled = FromValueOpt::from_value(v),
168                    "duplicate" => b.duplicate = FromValueOpt::from_value(v),
169                    "fraudulent" => b.fraudulent = FromValueOpt::from_value(v),
170                    "merchandise_not_as_described" => {
171                        b.merchandise_not_as_described = FromValueOpt::from_value(v)
172                    }
173                    "no_valid_authorization" => {
174                        b.no_valid_authorization = FromValueOpt::from_value(v)
175                    }
176                    "not_received" => b.not_received = FromValueOpt::from_value(v),
177                    "other" => b.other = FromValueOpt::from_value(v),
178                    "reason" => b.reason = FromValueOpt::from_value(v),
179                    "service_not_as_described" => {
180                        b.service_not_as_described = FromValueOpt::from_value(v)
181                    }
182                    _ => {}
183                }
184            }
185            b.take_out()
186        }
187    }
188};
189/// The reason for filing the dispute. Its value will match the field containing the evidence.
190#[derive(Clone, Eq, PartialEq)]
191#[non_exhaustive]
192pub enum IssuingDisputeEvidenceReason {
193    Canceled,
194    Duplicate,
195    Fraudulent,
196    MerchandiseNotAsDescribed,
197    NoValidAuthorization,
198    NotReceived,
199    Other,
200    ServiceNotAsDescribed,
201    /// An unrecognized value from Stripe. Should not be used as a request parameter.
202    Unknown(String),
203}
204impl IssuingDisputeEvidenceReason {
205    pub fn as_str(&self) -> &str {
206        use IssuingDisputeEvidenceReason::*;
207        match self {
208            Canceled => "canceled",
209            Duplicate => "duplicate",
210            Fraudulent => "fraudulent",
211            MerchandiseNotAsDescribed => "merchandise_not_as_described",
212            NoValidAuthorization => "no_valid_authorization",
213            NotReceived => "not_received",
214            Other => "other",
215            ServiceNotAsDescribed => "service_not_as_described",
216            Unknown(v) => v,
217        }
218    }
219}
220
221impl std::str::FromStr for IssuingDisputeEvidenceReason {
222    type Err = std::convert::Infallible;
223    fn from_str(s: &str) -> Result<Self, Self::Err> {
224        use IssuingDisputeEvidenceReason::*;
225        match s {
226            "canceled" => Ok(Canceled),
227            "duplicate" => Ok(Duplicate),
228            "fraudulent" => Ok(Fraudulent),
229            "merchandise_not_as_described" => Ok(MerchandiseNotAsDescribed),
230            "no_valid_authorization" => Ok(NoValidAuthorization),
231            "not_received" => Ok(NotReceived),
232            "other" => Ok(Other),
233            "service_not_as_described" => Ok(ServiceNotAsDescribed),
234            v => {
235                tracing::warn!(
236                    "Unknown value '{}' for enum '{}'",
237                    v,
238                    "IssuingDisputeEvidenceReason"
239                );
240                Ok(Unknown(v.to_owned()))
241            }
242        }
243    }
244}
245impl std::fmt::Display for IssuingDisputeEvidenceReason {
246    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
247        f.write_str(self.as_str())
248    }
249}
250
251impl std::fmt::Debug for IssuingDisputeEvidenceReason {
252    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
253        f.write_str(self.as_str())
254    }
255}
256#[cfg(feature = "serialize")]
257impl serde::Serialize for IssuingDisputeEvidenceReason {
258    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
259    where
260        S: serde::Serializer,
261    {
262        serializer.serialize_str(self.as_str())
263    }
264}
265impl miniserde::Deserialize for IssuingDisputeEvidenceReason {
266    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
267        crate::Place::new(out)
268    }
269}
270
271impl miniserde::de::Visitor for crate::Place<IssuingDisputeEvidenceReason> {
272    fn string(&mut self, s: &str) -> miniserde::Result<()> {
273        use std::str::FromStr;
274        self.out = Some(IssuingDisputeEvidenceReason::from_str(s).expect("infallible"));
275        Ok(())
276    }
277}
278
279stripe_types::impl_from_val_with_from_str!(IssuingDisputeEvidenceReason);
280#[cfg(feature = "deserialize")]
281impl<'de> serde::Deserialize<'de> for IssuingDisputeEvidenceReason {
282    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
283        use std::str::FromStr;
284        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
285        Ok(Self::from_str(&s).expect("infallible"))
286    }
287}