stripe_shared/
payment_pages_checkout_session_branding_settings_icon.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionBrandingSettingsIcon {
5    /// The ID of a [File upload](https://stripe.com/docs/api/files) representing the icon.
6    /// Purpose must be `business_icon`.
7    /// Required if `type` is `file` and disallowed otherwise.
8    pub file: Option<String>,
9    /// The type of image for the icon. Must be one of `file` or `url`.
10    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
11    pub type_: PaymentPagesCheckoutSessionBrandingSettingsIconType,
12    /// The URL of the image. Present when `type` is `url`.
13    pub url: Option<String>,
14}
15#[doc(hidden)]
16pub struct PaymentPagesCheckoutSessionBrandingSettingsIconBuilder {
17    file: Option<Option<String>>,
18    type_: Option<PaymentPagesCheckoutSessionBrandingSettingsIconType>,
19    url: Option<Option<String>>,
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 PaymentPagesCheckoutSessionBrandingSettingsIcon {
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<PaymentPagesCheckoutSessionBrandingSettingsIcon>,
46        builder: PaymentPagesCheckoutSessionBrandingSettingsIconBuilder,
47    }
48
49    impl Visitor for Place<PaymentPagesCheckoutSessionBrandingSettingsIcon> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: PaymentPagesCheckoutSessionBrandingSettingsIconBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for PaymentPagesCheckoutSessionBrandingSettingsIconBuilder {
59        type Out = PaymentPagesCheckoutSessionBrandingSettingsIcon;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "file" => Deserialize::begin(&mut self.file),
63                "type" => Deserialize::begin(&mut self.type_),
64                "url" => Deserialize::begin(&mut self.url),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                file: Deserialize::default(),
72                type_: Deserialize::default(),
73                url: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(file), Some(type_), Some(url)) =
79                (self.file.take(), self.type_, self.url.take())
80            else {
81                return None;
82            };
83            Some(Self::Out { file, type_, url })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for PaymentPagesCheckoutSessionBrandingSettingsIcon {
99        type Builder = PaymentPagesCheckoutSessionBrandingSettingsIconBuilder;
100    }
101
102    impl FromValueOpt for PaymentPagesCheckoutSessionBrandingSettingsIcon {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = PaymentPagesCheckoutSessionBrandingSettingsIconBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "file" => b.file = FromValueOpt::from_value(v),
111                    "type" => b.type_ = FromValueOpt::from_value(v),
112                    "url" => b.url = FromValueOpt::from_value(v),
113                    _ => {}
114                }
115            }
116            b.take_out()
117        }
118    }
119};
120/// The type of image for the icon. Must be one of `file` or `url`.
121#[derive(Copy, Clone, Eq, PartialEq)]
122pub enum PaymentPagesCheckoutSessionBrandingSettingsIconType {
123    File,
124    Url,
125}
126impl PaymentPagesCheckoutSessionBrandingSettingsIconType {
127    pub fn as_str(self) -> &'static str {
128        use PaymentPagesCheckoutSessionBrandingSettingsIconType::*;
129        match self {
130            File => "file",
131            Url => "url",
132        }
133    }
134}
135
136impl std::str::FromStr for PaymentPagesCheckoutSessionBrandingSettingsIconType {
137    type Err = stripe_types::StripeParseError;
138    fn from_str(s: &str) -> Result<Self, Self::Err> {
139        use PaymentPagesCheckoutSessionBrandingSettingsIconType::*;
140        match s {
141            "file" => Ok(File),
142            "url" => Ok(Url),
143            _ => Err(stripe_types::StripeParseError),
144        }
145    }
146}
147impl std::fmt::Display for PaymentPagesCheckoutSessionBrandingSettingsIconType {
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 PaymentPagesCheckoutSessionBrandingSettingsIconType {
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 PaymentPagesCheckoutSessionBrandingSettingsIconType {
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 PaymentPagesCheckoutSessionBrandingSettingsIconType {
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<PaymentPagesCheckoutSessionBrandingSettingsIconType> {
174    fn string(&mut self, s: &str) -> miniserde::Result<()> {
175        use std::str::FromStr;
176        self.out = Some(
177            PaymentPagesCheckoutSessionBrandingSettingsIconType::from_str(s)
178                .map_err(|_| miniserde::Error)?,
179        );
180        Ok(())
181    }
182}
183
184stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionBrandingSettingsIconType);
185#[cfg(feature = "deserialize")]
186impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionBrandingSettingsIconType {
187    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
188        use std::str::FromStr;
189        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
190        Self::from_str(&s).map_err(|_| {
191            serde::de::Error::custom(
192                "Unknown value for PaymentPagesCheckoutSessionBrandingSettingsIconType",
193            )
194        })
195    }
196}