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
80                _ => <dyn Visitor>::ignore(),
81            })
82        }
83
84        fn deser_default() -> Self {
85            Self {
86                background_color: Deserialize::default(),
87                border_style: Deserialize::default(),
88                button_color: Deserialize::default(),
89                display_name: Deserialize::default(),
90                font_family: Deserialize::default(),
91                icon: Deserialize::default(),
92                logo: Deserialize::default(),
93            }
94        }
95
96        fn take_out(&mut self) -> Option<Self::Out> {
97            let (
98                Some(background_color),
99                Some(border_style),
100                Some(button_color),
101                Some(display_name),
102                Some(font_family),
103                Some(icon),
104                Some(logo),
105            ) = (
106                self.background_color.take(),
107                self.border_style,
108                self.button_color.take(),
109                self.display_name.take(),
110                self.font_family.take(),
111                self.icon.take(),
112                self.logo.take(),
113            )
114            else {
115                return None;
116            };
117            Some(Self::Out {
118                background_color,
119                border_style,
120                button_color,
121                display_name,
122                font_family,
123                icon,
124                logo,
125            })
126        }
127    }
128
129    impl Map for Builder<'_> {
130        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
131            self.builder.key(k)
132        }
133
134        fn finish(&mut self) -> Result<()> {
135            *self.out = self.builder.take_out();
136            Ok(())
137        }
138    }
139
140    impl ObjectDeser for PaymentPagesCheckoutSessionBrandingSettings {
141        type Builder = PaymentPagesCheckoutSessionBrandingSettingsBuilder;
142    }
143
144    impl FromValueOpt for PaymentPagesCheckoutSessionBrandingSettings {
145        fn from_value(v: Value) -> Option<Self> {
146            let Value::Object(obj) = v else {
147                return None;
148            };
149            let mut b = PaymentPagesCheckoutSessionBrandingSettingsBuilder::deser_default();
150            for (k, v) in obj {
151                match k.as_str() {
152                    "background_color" => b.background_color = FromValueOpt::from_value(v),
153                    "border_style" => b.border_style = FromValueOpt::from_value(v),
154                    "button_color" => b.button_color = FromValueOpt::from_value(v),
155                    "display_name" => b.display_name = FromValueOpt::from_value(v),
156                    "font_family" => b.font_family = FromValueOpt::from_value(v),
157                    "icon" => b.icon = FromValueOpt::from_value(v),
158                    "logo" => b.logo = FromValueOpt::from_value(v),
159
160                    _ => {}
161                }
162            }
163            b.take_out()
164        }
165    }
166};
167/// The border style for the Checkout Session. Must be one of `rounded`, `rectangular`, or `pill`.
168#[derive(Copy, Clone, Eq, PartialEq)]
169pub enum PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
170    Pill,
171    Rectangular,
172    Rounded,
173}
174impl PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
175    pub fn as_str(self) -> &'static str {
176        use PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::*;
177        match self {
178            Pill => "pill",
179            Rectangular => "rectangular",
180            Rounded => "rounded",
181        }
182    }
183}
184
185impl std::str::FromStr for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
186    type Err = stripe_types::StripeParseError;
187    fn from_str(s: &str) -> Result<Self, Self::Err> {
188        use PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::*;
189        match s {
190            "pill" => Ok(Pill),
191            "rectangular" => Ok(Rectangular),
192            "rounded" => Ok(Rounded),
193            _ => Err(stripe_types::StripeParseError),
194        }
195    }
196}
197impl std::fmt::Display for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
198    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
199        f.write_str(self.as_str())
200    }
201}
202
203impl std::fmt::Debug for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
204    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
205        f.write_str(self.as_str())
206    }
207}
208#[cfg(feature = "serialize")]
209impl serde::Serialize for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
210    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
211    where
212        S: serde::Serializer,
213    {
214        serializer.serialize_str(self.as_str())
215    }
216}
217impl miniserde::Deserialize for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
218    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
219        crate::Place::new(out)
220    }
221}
222
223impl miniserde::de::Visitor
224    for crate::Place<PaymentPagesCheckoutSessionBrandingSettingsBorderStyle>
225{
226    fn string(&mut self, s: &str) -> miniserde::Result<()> {
227        use std::str::FromStr;
228        self.out = Some(
229            PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::from_str(s)
230                .map_err(|_| miniserde::Error)?,
231        );
232        Ok(())
233    }
234}
235
236stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionBrandingSettingsBorderStyle);
237#[cfg(feature = "deserialize")]
238impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
239    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
240        use std::str::FromStr;
241        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
242        Self::from_str(&s).map_err(|_| {
243            serde::de::Error::custom(
244                "Unknown value for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle",
245            )
246        })
247    }
248}