1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionBrandingSettings {
5 pub background_color: String,
7 pub border_style: PaymentPagesCheckoutSessionBrandingSettingsBorderStyle,
9 pub button_color: String,
11 pub display_name: String,
13 pub font_family: String,
16 pub icon: Option<stripe_shared::PaymentPagesCheckoutSessionBrandingSettingsIcon>,
18 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.take(),
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#[derive(Clone, Eq, PartialEq)]
167#[non_exhaustive]
168pub enum PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
169 Pill,
170 Rectangular,
171 Rounded,
172 Unknown(String),
174}
175impl PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
176 pub fn as_str(&self) -> &str {
177 use PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::*;
178 match self {
179 Pill => "pill",
180 Rectangular => "rectangular",
181 Rounded => "rounded",
182 Unknown(v) => v,
183 }
184 }
185}
186
187impl std::str::FromStr for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
188 type Err = std::convert::Infallible;
189 fn from_str(s: &str) -> Result<Self, Self::Err> {
190 use PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::*;
191 match s {
192 "pill" => Ok(Pill),
193 "rectangular" => Ok(Rectangular),
194 "rounded" => Ok(Rounded),
195 v => {
196 tracing::warn!(
197 "Unknown value '{}' for enum '{}'",
198 v,
199 "PaymentPagesCheckoutSessionBrandingSettingsBorderStyle"
200 );
201 Ok(Unknown(v.to_owned()))
202 }
203 }
204 }
205}
206impl std::fmt::Display for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
207 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
208 f.write_str(self.as_str())
209 }
210}
211
212impl std::fmt::Debug for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
213 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
214 f.write_str(self.as_str())
215 }
216}
217#[cfg(feature = "serialize")]
218impl serde::Serialize for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
219 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
220 where
221 S: serde::Serializer,
222 {
223 serializer.serialize_str(self.as_str())
224 }
225}
226impl miniserde::Deserialize for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
227 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
228 crate::Place::new(out)
229 }
230}
231
232impl miniserde::de::Visitor
233 for crate::Place<PaymentPagesCheckoutSessionBrandingSettingsBorderStyle>
234{
235 fn string(&mut self, s: &str) -> miniserde::Result<()> {
236 use std::str::FromStr;
237 self.out = Some(
238 PaymentPagesCheckoutSessionBrandingSettingsBorderStyle::from_str(s)
239 .expect("infallible"),
240 );
241 Ok(())
242 }
243}
244
245stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionBrandingSettingsBorderStyle);
246#[cfg(feature = "deserialize")]
247impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionBrandingSettingsBorderStyle {
248 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
249 use std::str::FromStr;
250 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
251 Ok(Self::from_str(&s).expect("infallible"))
252 }
253}