stripe_shared/
dispute_payment_method_details.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct DisputePaymentMethodDetails {
5    pub amazon_pay: Option<stripe_shared::DisputePaymentMethodDetailsAmazonPay>,
6    pub card: Option<stripe_shared::DisputePaymentMethodDetailsCard>,
7    pub klarna: Option<stripe_shared::DisputePaymentMethodDetailsKlarna>,
8    pub paypal: Option<stripe_shared::DisputePaymentMethodDetailsPaypal>,
9    /// Payment method type.
10    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
11    pub type_: DisputePaymentMethodDetailsType,
12}
13#[doc(hidden)]
14pub struct DisputePaymentMethodDetailsBuilder {
15    amazon_pay: Option<Option<stripe_shared::DisputePaymentMethodDetailsAmazonPay>>,
16    card: Option<Option<stripe_shared::DisputePaymentMethodDetailsCard>>,
17    klarna: Option<Option<stripe_shared::DisputePaymentMethodDetailsKlarna>>,
18    paypal: Option<Option<stripe_shared::DisputePaymentMethodDetailsPaypal>>,
19    type_: Option<DisputePaymentMethodDetailsType>,
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 DisputePaymentMethodDetails {
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<DisputePaymentMethodDetails>,
46        builder: DisputePaymentMethodDetailsBuilder,
47    }
48
49    impl Visitor for Place<DisputePaymentMethodDetails> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: DisputePaymentMethodDetailsBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for DisputePaymentMethodDetailsBuilder {
59        type Out = DisputePaymentMethodDetails;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "amazon_pay" => Deserialize::begin(&mut self.amazon_pay),
63                "card" => Deserialize::begin(&mut self.card),
64                "klarna" => Deserialize::begin(&mut self.klarna),
65                "paypal" => Deserialize::begin(&mut self.paypal),
66                "type" => Deserialize::begin(&mut self.type_),
67                _ => <dyn Visitor>::ignore(),
68            })
69        }
70
71        fn deser_default() -> Self {
72            Self {
73                amazon_pay: Deserialize::default(),
74                card: Deserialize::default(),
75                klarna: Deserialize::default(),
76                paypal: Deserialize::default(),
77                type_: Deserialize::default(),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (Some(amazon_pay), Some(card), Some(klarna), Some(paypal), Some(type_)) = (
83                self.amazon_pay.take(),
84                self.card.take(),
85                self.klarna.take(),
86                self.paypal.take(),
87                self.type_.take(),
88            ) else {
89                return None;
90            };
91            Some(Self::Out { amazon_pay, card, klarna, paypal, type_ })
92        }
93    }
94
95    impl Map for Builder<'_> {
96        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
97            self.builder.key(k)
98        }
99
100        fn finish(&mut self) -> Result<()> {
101            *self.out = self.builder.take_out();
102            Ok(())
103        }
104    }
105
106    impl ObjectDeser for DisputePaymentMethodDetails {
107        type Builder = DisputePaymentMethodDetailsBuilder;
108    }
109
110    impl FromValueOpt for DisputePaymentMethodDetails {
111        fn from_value(v: Value) -> Option<Self> {
112            let Value::Object(obj) = v else {
113                return None;
114            };
115            let mut b = DisputePaymentMethodDetailsBuilder::deser_default();
116            for (k, v) in obj {
117                match k.as_str() {
118                    "amazon_pay" => b.amazon_pay = FromValueOpt::from_value(v),
119                    "card" => b.card = FromValueOpt::from_value(v),
120                    "klarna" => b.klarna = FromValueOpt::from_value(v),
121                    "paypal" => b.paypal = FromValueOpt::from_value(v),
122                    "type" => b.type_ = FromValueOpt::from_value(v),
123                    _ => {}
124                }
125            }
126            b.take_out()
127        }
128    }
129};
130/// Payment method type.
131#[derive(Clone, Eq, PartialEq)]
132#[non_exhaustive]
133pub enum DisputePaymentMethodDetailsType {
134    AmazonPay,
135    Card,
136    Klarna,
137    Paypal,
138    /// An unrecognized value from Stripe. Should not be used as a request parameter.
139    Unknown(String),
140}
141impl DisputePaymentMethodDetailsType {
142    pub fn as_str(&self) -> &str {
143        use DisputePaymentMethodDetailsType::*;
144        match self {
145            AmazonPay => "amazon_pay",
146            Card => "card",
147            Klarna => "klarna",
148            Paypal => "paypal",
149            Unknown(v) => v,
150        }
151    }
152}
153
154impl std::str::FromStr for DisputePaymentMethodDetailsType {
155    type Err = std::convert::Infallible;
156    fn from_str(s: &str) -> Result<Self, Self::Err> {
157        use DisputePaymentMethodDetailsType::*;
158        match s {
159            "amazon_pay" => Ok(AmazonPay),
160            "card" => Ok(Card),
161            "klarna" => Ok(Klarna),
162            "paypal" => Ok(Paypal),
163            v => {
164                tracing::warn!(
165                    "Unknown value '{}' for enum '{}'",
166                    v,
167                    "DisputePaymentMethodDetailsType"
168                );
169                Ok(Unknown(v.to_owned()))
170            }
171        }
172    }
173}
174impl std::fmt::Display for DisputePaymentMethodDetailsType {
175    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
176        f.write_str(self.as_str())
177    }
178}
179
180impl std::fmt::Debug for DisputePaymentMethodDetailsType {
181    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
182        f.write_str(self.as_str())
183    }
184}
185#[cfg(feature = "serialize")]
186impl serde::Serialize for DisputePaymentMethodDetailsType {
187    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
188    where
189        S: serde::Serializer,
190    {
191        serializer.serialize_str(self.as_str())
192    }
193}
194impl miniserde::Deserialize for DisputePaymentMethodDetailsType {
195    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
196        crate::Place::new(out)
197    }
198}
199
200impl miniserde::de::Visitor for crate::Place<DisputePaymentMethodDetailsType> {
201    fn string(&mut self, s: &str) -> miniserde::Result<()> {
202        use std::str::FromStr;
203        self.out = Some(DisputePaymentMethodDetailsType::from_str(s).expect("infallible"));
204        Ok(())
205    }
206}
207
208stripe_types::impl_from_val_with_from_str!(DisputePaymentMethodDetailsType);
209#[cfg(feature = "deserialize")]
210impl<'de> serde::Deserialize<'de> for DisputePaymentMethodDetailsType {
211    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
212        use std::str::FromStr;
213        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
214        Ok(Self::from_str(&s).expect("infallible"))
215    }
216}