stripe_shared/
payment_pages_checkout_session_branding_settings.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionBrandingSettings {
5    /// A hex color value starting with `#` representing the background color for the Checkout Session.
6    pub background_color: String,
7    /// The border style for the Checkout Session. Must be one of `rounded`, `rectangular`, or `pill`.
8    pub border_style: PaymentPagesCheckoutSessionBrandingSettingsBorderStyle,
9    /// A hex color value starting with `#` representing the button color for the Checkout Session.
10    pub button_color: String,
11    /// The display name shown on the Checkout Session.
12    pub display_name: String,
13    /// The font family for the Checkout Session.
14    /// Must be one of the [supported font families](https://docs.stripe.com/payments/checkout/customization/appearance?payment-ui=stripe-hosted#font-compatibility).
15    pub font_family: String,
16    /// The icon for the Checkout Session. You cannot set both `logo` and `icon`.
17    pub icon: Option<stripe_shared::PaymentPagesCheckoutSessionBrandingSettingsIcon>,
18    /// The logo for the Checkout Session. You cannot set both `logo` and `icon`.
19    pub logo: Option<stripe_shared::PaymentPagesCheckoutSessionBrandingSettingsLogo>,
20}
21#[doc(hidden)]
22pub struct PaymentPagesCheckoutSessionBrandingSettingsBuilder {
23    background_color: Option<String>,
24    border_style: Option<PaymentPagesCheckoutSessionBrandingSettingsBorderStyle>,
25    button_color: Option<String>,
26    display_name: Option<String>,
27    font_family: Option<String>,
28    icon: Option<Option<stripe_shared::PaymentPagesCheckoutSessionBrandingSettingsIcon>>,
29    logo: Option<Option<stripe_shared::PaymentPagesCheckoutSessionBrandingSettingsLogo>>,
30}
31
32#[allow(
33    unused_variables,
34    irrefutable_let_patterns,
35    clippy::let_unit_value,
36    clippy::match_single_binding,
37    clippy::single_match
38)]
39const _: () = {
40    use miniserde::de::{Map, Visitor};
41    use miniserde::json::Value;
42    use miniserde::{Deserialize, Result, make_place};
43    use stripe_types::miniserde_helpers::FromValueOpt;
44    use stripe_types::{MapBuilder, ObjectDeser};
45
46    make_place!(Place);
47
48    impl Deserialize for PaymentPagesCheckoutSessionBrandingSettings {
49        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50            Place::new(out)
51        }
52    }
53
54    struct Builder<'a> {
55        out: &'a mut Option<PaymentPagesCheckoutSessionBrandingSettings>,
56        builder: PaymentPagesCheckoutSessionBrandingSettingsBuilder,
57    }
58
59    impl Visitor for Place<PaymentPagesCheckoutSessionBrandingSettings> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: PaymentPagesCheckoutSessionBrandingSettingsBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for PaymentPagesCheckoutSessionBrandingSettingsBuilder {
69        type Out = PaymentPagesCheckoutSessionBrandingSettings;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "background_color" => Deserialize::begin(&mut self.background_color),
73                "border_style" => Deserialize::begin(&mut self.border_style),
74                "button_color" => Deserialize::begin(&mut self.button_color),
75                "display_name" => Deserialize::begin(&mut self.display_name),
76                "font_family" => Deserialize::begin(&mut self.font_family),
77                "icon" => Deserialize::begin(&mut self.icon),
78                "logo" => Deserialize::begin(&mut self.logo),
79                _ => <dyn Visitor>::ignore(),
80            })
81        }
82
83        fn deser_default() -> Self {
84            Self {
85                background_color: Deserialize::default(),
86                border_style: Deserialize::default(),
87                button_color: Deserialize::default(),
88                display_name: Deserialize::default(),
89                font_family: Deserialize::default(),
90                icon: Deserialize::default(),
91                logo: Deserialize::default(),
92            }
93        }
94
95        fn take_out(&mut self) -> Option<Self::Out> {
96            let (
97                Some(background_color),
98                Some(border_style),
99                Some(button_color),
100                Some(display_name),
101                Some(font_family),
102                Some(icon),
103                Some(logo),
104            ) = (
105                self.background_color.take(),
106                self.border_style,
107                self.button_color.take(),
108                self.display_name.take(),
109                self.font_family.take(),
110                self.icon.take(),
111                self.logo.take(),
112            )
113            else {
114                return None;
115            };
116            Some(Self::Out {
117                background_color,
118                border_style,
119                button_color,
120                display_name,
121                font_family,
122                icon,
123                logo,
124            })
125        }
126    }
127
128    impl Map for Builder<'_> {
129        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
130            self.builder.key(k)
131        }
132
133        fn finish(&mut self) -> Result<()> {
134            *self.out = self.builder.take_out();
135            Ok(())
136        }
137    }
138
139    impl ObjectDeser for PaymentPagesCheckoutSessionBrandingSettings {
140        type Builder = PaymentPagesCheckoutSessionBrandingSettingsBuilder;
141    }
142
143    impl FromValueOpt for PaymentPagesCheckoutSessionBrandingSettings {
144        fn from_value(v: Value) -> Option<Self> {
145            let Value::Object(obj) = v else {
146                return None;
147            };
148            let mut b = PaymentPagesCheckoutSessionBrandingSettingsBuilder::deser_default();
149            for (k, v) in obj {
150                match k.as_str() {
151                    "background_color" => b.background_color = FromValueOpt::from_value(v),
152                    "border_style" => b.border_style = FromValueOpt::from_value(v),
153                    "button_color" => b.button_color = FromValueOpt::from_value(v),
154                    "display_name" => b.display_name = FromValueOpt::from_value(v),
155                    "font_family" => b.font_family = FromValueOpt::from_value(v),
156                    "icon" => b.icon = FromValueOpt::from_value(v),
157                    "logo" => b.logo = FromValueOpt::from_value(v),
158                    _ => {}
159                }
160            }
161            b.take_out()
162        }
163    }
164};
165/// The border style for the Checkout Session. Must be one of `rounded`, `rectangular`, or `pill`.
166#[derive(Copy, Clone, Eq, PartialEq)]
167pub enum PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
168    Pill,
169    Rectangular,
170    Rounded,
171}
172impl PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
173    pub fn as_str(self) -> &'static str {
174        use PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::*;
175        match self {
176            Pill => "pill",
177            Rectangular => "rectangular",
178            Rounded => "rounded",
179        }
180    }
181}
182
183impl std::str::FromStr for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
184    type Err = stripe_types::StripeParseError;
185    fn from_str(s: &str) -> Result<Self, Self::Err> {
186        use PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::*;
187        match s {
188            "pill" => Ok(Pill),
189            "rectangular" => Ok(Rectangular),
190            "rounded" => Ok(Rounded),
191            _ => Err(stripe_types::StripeParseError),
192        }
193    }
194}
195impl std::fmt::Display for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
196    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
197        f.write_str(self.as_str())
198    }
199}
200
201impl std::fmt::Debug for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
202    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
203        f.write_str(self.as_str())
204    }
205}
206#[cfg(feature = "serialize")]
207impl serde::Serialize for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
208    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
209    where
210        S: serde::Serializer,
211    {
212        serializer.serialize_str(self.as_str())
213    }
214}
215impl miniserde::Deserialize for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
216    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
217        crate::Place::new(out)
218    }
219}
220
221impl miniserde::de::Visitor
222    for crate::Place<PaymentPagesCheckoutSessionBrandingSettingsBorderStyle>
223{
224    fn string(&mut self, s: &str) -> miniserde::Result<()> {
225        use std::str::FromStr;
226        self.out = Some(
227            PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::from_str(s)
228                .map_err(|_| miniserde::Error)?,
229        );
230        Ok(())
231    }
232}
233
234stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionBrandingSettingsBorderStyle);
235#[cfg(feature = "deserialize")]
236impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
237    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
238        use std::str::FromStr;
239        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
240        Self::from_str(&s).map_err(|_| {
241            serde::de::Error::custom(
242                "Unknown value for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle",
243            )
244        })
245    }
246}