stripe_shared/
platform_earning_fee_source.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PlatformEarningFeeSource {
5    /// Charge ID that created this application fee.
6    pub charge: Option<String>,
7    /// Payout ID that created this application fee.
8    pub payout: Option<String>,
9    /// Type of object that created the application fee.
10    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
11    pub type_: PlatformEarningFeeSourceType,
12}
13#[doc(hidden)]
14pub struct PlatformEarningFeeSourceBuilder {
15    charge: Option<Option<String>>,
16    payout: Option<Option<String>>,
17    type_: Option<PlatformEarningFeeSourceType>,
18}
19
20#[allow(
21    unused_variables,
22    irrefutable_let_patterns,
23    clippy::let_unit_value,
24    clippy::match_single_binding,
25    clippy::single_match
26)]
27const _: () = {
28    use miniserde::de::{Map, Visitor};
29    use miniserde::json::Value;
30    use miniserde::{make_place, Deserialize, Result};
31    use stripe_types::miniserde_helpers::FromValueOpt;
32    use stripe_types::{MapBuilder, ObjectDeser};
33
34    make_place!(Place);
35
36    impl Deserialize for PlatformEarningFeeSource {
37        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
38            Place::new(out)
39        }
40    }
41
42    struct Builder<'a> {
43        out: &'a mut Option<PlatformEarningFeeSource>,
44        builder: PlatformEarningFeeSourceBuilder,
45    }
46
47    impl Visitor for Place<PlatformEarningFeeSource> {
48        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
49            Ok(Box::new(Builder {
50                out: &mut self.out,
51                builder: PlatformEarningFeeSourceBuilder::deser_default(),
52            }))
53        }
54    }
55
56    impl MapBuilder for PlatformEarningFeeSourceBuilder {
57        type Out = PlatformEarningFeeSource;
58        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
59            Ok(match k {
60                "charge" => Deserialize::begin(&mut self.charge),
61                "payout" => Deserialize::begin(&mut self.payout),
62                "type" => Deserialize::begin(&mut self.type_),
63
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                charge: Deserialize::default(),
71                payout: Deserialize::default(),
72                type_: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(charge), Some(payout), Some(type_)) =
78                (self.charge.take(), self.payout.take(), self.type_)
79            else {
80                return None;
81            };
82            Some(Self::Out { charge, payout, type_ })
83        }
84    }
85
86    impl<'a> Map for Builder<'a> {
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 PlatformEarningFeeSource {
98        type Builder = PlatformEarningFeeSourceBuilder;
99    }
100
101    impl FromValueOpt for PlatformEarningFeeSource {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PlatformEarningFeeSourceBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "charge" => b.charge = FromValueOpt::from_value(v),
110                    "payout" => b.payout = FromValueOpt::from_value(v),
111                    "type" => b.type_ = FromValueOpt::from_value(v),
112
113                    _ => {}
114                }
115            }
116            b.take_out()
117        }
118    }
119};
120/// Type of object that created the application fee.
121#[derive(Copy, Clone, Eq, PartialEq)]
122pub enum PlatformEarningFeeSourceType {
123    Charge,
124    Payout,
125}
126impl PlatformEarningFeeSourceType {
127    pub fn as_str(self) -> &'static str {
128        use PlatformEarningFeeSourceType::*;
129        match self {
130            Charge => "charge",
131            Payout => "payout",
132        }
133    }
134}
135
136impl std::str::FromStr for PlatformEarningFeeSourceType {
137    type Err = stripe_types::StripeParseError;
138    fn from_str(s: &str) -> Result<Self, Self::Err> {
139        use PlatformEarningFeeSourceType::*;
140        match s {
141            "charge" => Ok(Charge),
142            "payout" => Ok(Payout),
143            _ => Err(stripe_types::StripeParseError),
144        }
145    }
146}
147impl std::fmt::Display for PlatformEarningFeeSourceType {
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.write_str(self.as_str())
150    }
151}
152
153impl std::fmt::Debug for PlatformEarningFeeSourceType {
154    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155        f.write_str(self.as_str())
156    }
157}
158#[cfg(feature = "serialize")]
159impl serde::Serialize for PlatformEarningFeeSourceType {
160    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
161    where
162        S: serde::Serializer,
163    {
164        serializer.serialize_str(self.as_str())
165    }
166}
167impl miniserde::Deserialize for PlatformEarningFeeSourceType {
168    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
169        crate::Place::new(out)
170    }
171}
172
173impl miniserde::de::Visitor for crate::Place<PlatformEarningFeeSourceType> {
174    fn string(&mut self, s: &str) -> miniserde::Result<()> {
175        use std::str::FromStr;
176        self.out = Some(PlatformEarningFeeSourceType::from_str(s).map_err(|_| miniserde::Error)?);
177        Ok(())
178    }
179}
180
181stripe_types::impl_from_val_with_from_str!(PlatformEarningFeeSourceType);
182#[cfg(feature = "deserialize")]
183impl<'de> serde::Deserialize<'de> for PlatformEarningFeeSourceType {
184    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
185        use std::str::FromStr;
186        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
187        Self::from_str(&s)
188            .map_err(|_| serde::de::Error::custom("Unknown value for PlatformEarningFeeSourceType"))
189    }
190}