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
69                _ => <dyn Visitor>::ignore(),
70            })
71        }
72
73        fn deser_default() -> Self {
74            Self {
75                additional_documentation: Deserialize::default(),
76                explanation: Deserialize::default(),
77                product_description: Deserialize::default(),
78                product_type: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (
84                Some(additional_documentation),
85                Some(explanation),
86                Some(product_description),
87                Some(product_type),
88            ) = (
89                self.additional_documentation.take(),
90                self.explanation.take(),
91                self.product_description.take(),
92                self.product_type,
93            )
94            else {
95                return None;
96            };
97            Some(Self::Out {
98                additional_documentation,
99                explanation,
100                product_description,
101                product_type,
102            })
103        }
104    }
105
106    impl Map for Builder<'_> {
107        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
108            self.builder.key(k)
109        }
110
111        fn finish(&mut self) -> Result<()> {
112            *self.out = self.builder.take_out();
113            Ok(())
114        }
115    }
116
117    impl ObjectDeser for IssuingDisputeOtherEvidence {
118        type Builder = IssuingDisputeOtherEvidenceBuilder;
119    }
120
121    impl FromValueOpt for IssuingDisputeOtherEvidence {
122        fn from_value(v: Value) -> Option<Self> {
123            let Value::Object(obj) = v else {
124                return None;
125            };
126            let mut b = IssuingDisputeOtherEvidenceBuilder::deser_default();
127            for (k, v) in obj {
128                match k.as_str() {
129                    "additional_documentation" => {
130                        b.additional_documentation = FromValueOpt::from_value(v)
131                    }
132                    "explanation" => b.explanation = FromValueOpt::from_value(v),
133                    "product_description" => b.product_description = FromValueOpt::from_value(v),
134                    "product_type" => b.product_type = FromValueOpt::from_value(v),
135
136                    _ => {}
137                }
138            }
139            b.take_out()
140        }
141    }
142};
143/// Whether the product was a merchandise or service.
144#[derive(Copy, Clone, Eq, PartialEq)]
145pub enum IssuingDisputeOtherEvidenceProductType {
146    Merchandise,
147    Service,
148}
149impl IssuingDisputeOtherEvidenceProductType {
150    pub fn as_str(self) -> &'static str {
151        use IssuingDisputeOtherEvidenceProductType::*;
152        match self {
153            Merchandise => "merchandise",
154            Service => "service",
155        }
156    }
157}
158
159impl std::str::FromStr for IssuingDisputeOtherEvidenceProductType {
160    type Err = stripe_types::StripeParseError;
161    fn from_str(s: &str) -> Result<Self, Self::Err> {
162        use IssuingDisputeOtherEvidenceProductType::*;
163        match s {
164            "merchandise" => Ok(Merchandise),
165            "service" => Ok(Service),
166            _ => Err(stripe_types::StripeParseError),
167        }
168    }
169}
170impl std::fmt::Display for IssuingDisputeOtherEvidenceProductType {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175
176impl std::fmt::Debug for IssuingDisputeOtherEvidenceProductType {
177    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178        f.write_str(self.as_str())
179    }
180}
181#[cfg(feature = "serialize")]
182impl serde::Serialize for IssuingDisputeOtherEvidenceProductType {
183    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
184    where
185        S: serde::Serializer,
186    {
187        serializer.serialize_str(self.as_str())
188    }
189}
190impl miniserde::Deserialize for IssuingDisputeOtherEvidenceProductType {
191    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
192        crate::Place::new(out)
193    }
194}
195
196impl miniserde::de::Visitor for crate::Place<IssuingDisputeOtherEvidenceProductType> {
197    fn string(&mut self, s: &str) -> miniserde::Result<()> {
198        use std::str::FromStr;
199        self.out = Some(
200            IssuingDisputeOtherEvidenceProductType::from_str(s).map_err(|_| miniserde::Error)?,
201        );
202        Ok(())
203    }
204}
205
206stripe_types::impl_from_val_with_from_str!(IssuingDisputeOtherEvidenceProductType);
207#[cfg(feature = "deserialize")]
208impl<'de> serde::Deserialize<'de> for IssuingDisputeOtherEvidenceProductType {
209    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
210        use std::str::FromStr;
211        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
212        Self::from_str(&s).map_err(|_| {
213            serde::de::Error::custom("Unknown value for IssuingDisputeOtherEvidenceProductType")
214        })
215    }
216}