stripe_shared/
payment_pages_checkout_session_branding_settings_logo.rs

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