stripe_shared/
dispute_payment_method_details_card.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct DisputePaymentMethodDetailsCard {
5    /// Card brand.
6    /// Can be `amex`, `cartes_bancaires`, `diners`, `discover`, `eftpos_au`, `jcb`, `link`, `mastercard`, `unionpay`, `visa` or `unknown`.
7    pub brand: String,
8    /// The type of dispute opened. Different case types may have varying fees and financial impact.
9    pub case_type: DisputePaymentMethodDetailsCardCaseType,
10    /// The card network's specific dispute reason code, which maps to one of Stripe's primary dispute categories to simplify response guidance.
11    /// The [Network code map](https://stripe.com/docs/disputes/categories#network-code-map) lists all available dispute reason codes by network.
12    pub network_reason_code: Option<String>,
13}
14#[doc(hidden)]
15pub struct DisputePaymentMethodDetailsCardBuilder {
16    brand: Option<String>,
17    case_type: Option<DisputePaymentMethodDetailsCardCaseType>,
18    network_reason_code: Option<Option<String>>,
19}
20
21#[allow(
22    unused_variables,
23    irrefutable_let_patterns,
24    clippy::let_unit_value,
25    clippy::match_single_binding,
26    clippy::single_match
27)]
28const _: () = {
29    use miniserde::de::{Map, Visitor};
30    use miniserde::json::Value;
31    use miniserde::{Deserialize, Result, make_place};
32    use stripe_types::miniserde_helpers::FromValueOpt;
33    use stripe_types::{MapBuilder, ObjectDeser};
34
35    make_place!(Place);
36
37    impl Deserialize for DisputePaymentMethodDetailsCard {
38        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39            Place::new(out)
40        }
41    }
42
43    struct Builder<'a> {
44        out: &'a mut Option<DisputePaymentMethodDetailsCard>,
45        builder: DisputePaymentMethodDetailsCardBuilder,
46    }
47
48    impl Visitor for Place<DisputePaymentMethodDetailsCard> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: DisputePaymentMethodDetailsCardBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for DisputePaymentMethodDetailsCardBuilder {
58        type Out = DisputePaymentMethodDetailsCard;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "brand" => Deserialize::begin(&mut self.brand),
62                "case_type" => Deserialize::begin(&mut self.case_type),
63                "network_reason_code" => Deserialize::begin(&mut self.network_reason_code),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                brand: Deserialize::default(),
71                case_type: Deserialize::default(),
72                network_reason_code: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(brand), Some(case_type), Some(network_reason_code)) =
78                (self.brand.take(), self.case_type.take(), self.network_reason_code.take())
79            else {
80                return None;
81            };
82            Some(Self::Out { brand, case_type, network_reason_code })
83        }
84    }
85
86    impl Map for Builder<'_> {
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            self.builder.key(k)
89        }
90
91        fn finish(&mut self) -> Result<()> {
92            *self.out = self.builder.take_out();
93            Ok(())
94        }
95    }
96
97    impl ObjectDeser for DisputePaymentMethodDetailsCard {
98        type Builder = DisputePaymentMethodDetailsCardBuilder;
99    }
100
101    impl FromValueOpt for DisputePaymentMethodDetailsCard {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = DisputePaymentMethodDetailsCardBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "brand" => b.brand = FromValueOpt::from_value(v),
110                    "case_type" => b.case_type = FromValueOpt::from_value(v),
111                    "network_reason_code" => b.network_reason_code = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// The type of dispute opened. Different case types may have varying fees and financial impact.
120#[derive(Clone, Eq, PartialEq)]
121#[non_exhaustive]
122pub enum DisputePaymentMethodDetailsCardCaseType {
123    Block,
124    Chargeback,
125    Compliance,
126    Inquiry,
127    Resolution,
128    /// An unrecognized value from Stripe. Should not be used as a request parameter.
129    Unknown(String),
130}
131impl DisputePaymentMethodDetailsCardCaseType {
132    pub fn as_str(&self) -> &str {
133        use DisputePaymentMethodDetailsCardCaseType::*;
134        match self {
135            Block => "block",
136            Chargeback => "chargeback",
137            Compliance => "compliance",
138            Inquiry => "inquiry",
139            Resolution => "resolution",
140            Unknown(v) => v,
141        }
142    }
143}
144
145impl std::str::FromStr for DisputePaymentMethodDetailsCardCaseType {
146    type Err = std::convert::Infallible;
147    fn from_str(s: &str) -> Result<Self, Self::Err> {
148        use DisputePaymentMethodDetailsCardCaseType::*;
149        match s {
150            "block" => Ok(Block),
151            "chargeback" => Ok(Chargeback),
152            "compliance" => Ok(Compliance),
153            "inquiry" => Ok(Inquiry),
154            "resolution" => Ok(Resolution),
155            v => {
156                tracing::warn!(
157                    "Unknown value '{}' for enum '{}'",
158                    v,
159                    "DisputePaymentMethodDetailsCardCaseType"
160                );
161                Ok(Unknown(v.to_owned()))
162            }
163        }
164    }
165}
166impl std::fmt::Display for DisputePaymentMethodDetailsCardCaseType {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171
172impl std::fmt::Debug for DisputePaymentMethodDetailsCardCaseType {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177#[cfg(feature = "serialize")]
178impl serde::Serialize for DisputePaymentMethodDetailsCardCaseType {
179    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
180    where
181        S: serde::Serializer,
182    {
183        serializer.serialize_str(self.as_str())
184    }
185}
186impl miniserde::Deserialize for DisputePaymentMethodDetailsCardCaseType {
187    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
188        crate::Place::new(out)
189    }
190}
191
192impl miniserde::de::Visitor for crate::Place<DisputePaymentMethodDetailsCardCaseType> {
193    fn string(&mut self, s: &str) -> miniserde::Result<()> {
194        use std::str::FromStr;
195        self.out = Some(DisputePaymentMethodDetailsCardCaseType::from_str(s).expect("infallible"));
196        Ok(())
197    }
198}
199
200stripe_types::impl_from_val_with_from_str!(DisputePaymentMethodDetailsCardCaseType);
201#[cfg(feature = "deserialize")]
202impl<'de> serde::Deserialize<'de> for DisputePaymentMethodDetailsCardCaseType {
203    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
204        use std::str::FromStr;
205        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
206        Ok(Self::from_str(&s).expect("infallible"))
207    }
208}