stripe_shared/
issuing_dispute_other_evidence.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingDisputeOtherEvidence {
5    /// (ID of a [file upload](https://stripe.com/docs/guides/file-upload)) Additional documentation supporting the dispute.
6    pub additional_documentation: Option<stripe_types::Expandable<stripe_shared::File>>,
7    /// Explanation of why the cardholder is disputing this transaction.
8    pub explanation: Option<String>,
9    /// Description of the merchandise or service that was purchased.
10    pub product_description: Option<String>,
11    /// Whether the product was a merchandise or service.
12    pub product_type: Option<IssuingDisputeOtherEvidenceProductType>,
13}
14#[doc(hidden)]
15pub struct IssuingDisputeOtherEvidenceBuilder {
16    additional_documentation: Option<Option<stripe_types::Expandable<stripe_shared::File>>>,
17    explanation: Option<Option<String>>,
18    product_description: Option<Option<String>>,
19    product_type: Option<Option<IssuingDisputeOtherEvidenceProductType>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for IssuingDisputeOtherEvidence {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<IssuingDisputeOtherEvidence>,
46        builder: IssuingDisputeOtherEvidenceBuilder,
47    }
48
49    impl Visitor for Place<IssuingDisputeOtherEvidence> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: IssuingDisputeOtherEvidenceBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for IssuingDisputeOtherEvidenceBuilder {
59        type Out = IssuingDisputeOtherEvidence;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "additional_documentation" => {
63                    Deserialize::begin(&mut self.additional_documentation)
64                }
65                "explanation" => Deserialize::begin(&mut self.explanation),
66                "product_description" => Deserialize::begin(&mut self.product_description),
67                "product_type" => Deserialize::begin(&mut self.product_type),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self {
74                additional_documentation: Deserialize::default(),
75                explanation: Deserialize::default(),
76                product_description: Deserialize::default(),
77                product_type: Deserialize::default(),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (
83                Some(additional_documentation),
84                Some(explanation),
85                Some(product_description),
86                Some(product_type),
87            ) = (
88                self.additional_documentation.take(),
89                self.explanation.take(),
90                self.product_description.take(),
91                self.product_type,
92            )
93            else {
94                return None;
95            };
96            Some(Self::Out {
97                additional_documentation,
98                explanation,
99                product_description,
100                product_type,
101            })
102        }
103    }
104
105    impl Map for Builder<'_> {
106        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
107            self.builder.key(k)
108        }
109
110        fn finish(&mut self) -> Result<()> {
111            *self.out = self.builder.take_out();
112            Ok(())
113        }
114    }
115
116    impl ObjectDeser for IssuingDisputeOtherEvidence {
117        type Builder = IssuingDisputeOtherEvidenceBuilder;
118    }
119
120    impl FromValueOpt for IssuingDisputeOtherEvidence {
121        fn from_value(v: Value) -> Option<Self> {
122            let Value::Object(obj) = v else {
123                return None;
124            };
125            let mut b = IssuingDisputeOtherEvidenceBuilder::deser_default();
126            for (k, v) in obj {
127                match k.as_str() {
128                    "additional_documentation" => {
129                        b.additional_documentation = FromValueOpt::from_value(v)
130                    }
131                    "explanation" => b.explanation = FromValueOpt::from_value(v),
132                    "product_description" => b.product_description = FromValueOpt::from_value(v),
133                    "product_type" => b.product_type = FromValueOpt::from_value(v),
134                    _ => {}
135                }
136            }
137            b.take_out()
138        }
139    }
140};
141/// Whether the product was a merchandise or service.
142#[derive(Copy, Clone, Eq, PartialEq)]
143pub enum IssuingDisputeOtherEvidenceProductType {
144    Merchandise,
145    Service,
146}
147impl IssuingDisputeOtherEvidenceProductType {
148    pub fn as_str(self) -> &'static str {
149        use IssuingDisputeOtherEvidenceProductType::*;
150        match self {
151            Merchandise => "merchandise",
152            Service => "service",
153        }
154    }
155}
156
157impl std::str::FromStr for IssuingDisputeOtherEvidenceProductType {
158    type Err = stripe_types::StripeParseError;
159    fn from_str(s: &str) -> Result<Self, Self::Err> {
160        use IssuingDisputeOtherEvidenceProductType::*;
161        match s {
162            "merchandise" => Ok(Merchandise),
163            "service" => Ok(Service),
164            _ => Err(stripe_types::StripeParseError),
165        }
166    }
167}
168impl std::fmt::Display for IssuingDisputeOtherEvidenceProductType {
169    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170        f.write_str(self.as_str())
171    }
172}
173
174impl std::fmt::Debug for IssuingDisputeOtherEvidenceProductType {
175    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
176        f.write_str(self.as_str())
177    }
178}
179#[cfg(feature = "serialize")]
180impl serde::Serialize for IssuingDisputeOtherEvidenceProductType {
181    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
182    where
183        S: serde::Serializer,
184    {
185        serializer.serialize_str(self.as_str())
186    }
187}
188impl miniserde::Deserialize for IssuingDisputeOtherEvidenceProductType {
189    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
190        crate::Place::new(out)
191    }
192}
193
194impl miniserde::de::Visitor for crate::Place<IssuingDisputeOtherEvidenceProductType> {
195    fn string(&mut self, s: &str) -> miniserde::Result<()> {
196        use std::str::FromStr;
197        self.out = Some(
198            IssuingDisputeOtherEvidenceProductType::from_str(s).map_err(|_| miniserde::Error)?,
199        );
200        Ok(())
201    }
202}
203
204stripe_types::impl_from_val_with_from_str!(IssuingDisputeOtherEvidenceProductType);
205#[cfg(feature = "deserialize")]
206impl<'de> serde::Deserialize<'de> for IssuingDisputeOtherEvidenceProductType {
207    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
208        use std::str::FromStr;
209        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
210        Self::from_str(&s).map_err(|_| {
211            serde::de::Error::custom("Unknown value for IssuingDisputeOtherEvidenceProductType")
212        })
213    }
214}