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                _ => <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_.take(), 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 PaymentPagesCheckoutSessionBrandingSettingsLogo {
99        type Builder = PaymentPagesCheckoutSessionBrandingSettingsLogoBuilder;
100    }
101
102    impl FromValueOpt for PaymentPagesCheckoutSessionBrandingSettingsLogo {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = PaymentPagesCheckoutSessionBrandingSettingsLogoBuilder::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 logo. Must be one of `file` or `url`.
121#[derive(Clone, Eq, PartialEq)]
122#[non_exhaustive]
123pub enum PaymentPagesCheckoutSessionBrandingSettingsLogoType {
124    File,
125    Url,
126    /// An unrecognized value from Stripe. Should not be used as a request parameter.
127    Unknown(String),
128}
129impl PaymentPagesCheckoutSessionBrandingSettingsLogoType {
130    pub fn as_str(&self) -> &str {
131        use PaymentPagesCheckoutSessionBrandingSettingsLogoType::*;
132        match self {
133            File => "file",
134            Url => "url",
135            Unknown(v) => v,
136        }
137    }
138}
139
140impl std::str::FromStr for PaymentPagesCheckoutSessionBrandingSettingsLogoType {
141    type Err = std::convert::Infallible;
142    fn from_str(s: &str) -> Result<Self, Self::Err> {
143        use PaymentPagesCheckoutSessionBrandingSettingsLogoType::*;
144        match s {
145            "file" => Ok(File),
146            "url" => Ok(Url),
147            v => {
148                tracing::warn!(
149                    "Unknown value '{}' for enum '{}'",
150                    v,
151                    "PaymentPagesCheckoutSessionBrandingSettingsLogoType"
152                );
153                Ok(Unknown(v.to_owned()))
154            }
155        }
156    }
157}
158impl std::fmt::Display for PaymentPagesCheckoutSessionBrandingSettingsLogoType {
159    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
160        f.write_str(self.as_str())
161    }
162}
163
164impl std::fmt::Debug for PaymentPagesCheckoutSessionBrandingSettingsLogoType {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169#[cfg(feature = "serialize")]
170impl serde::Serialize for PaymentPagesCheckoutSessionBrandingSettingsLogoType {
171    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
172    where
173        S: serde::Serializer,
174    {
175        serializer.serialize_str(self.as_str())
176    }
177}
178impl miniserde::Deserialize for PaymentPagesCheckoutSessionBrandingSettingsLogoType {
179    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
180        crate::Place::new(out)
181    }
182}
183
184impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionBrandingSettingsLogoType> {
185    fn string(&mut self, s: &str) -> miniserde::Result<()> {
186        use std::str::FromStr;
187        self.out = Some(
188            PaymentPagesCheckoutSessionBrandingSettingsLogoType::from_str(s).expect("infallible"),
189        );
190        Ok(())
191    }
192}
193
194stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionBrandingSettingsLogoType);
195#[cfg(feature = "deserialize")]
196impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionBrandingSettingsLogoType {
197    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
198        use std::str::FromStr;
199        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
200        Ok(Self::from_str(&s).expect("infallible"))
201    }
202}