1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentPagesCheckoutSessionCustomFields {
6 pub dropdown: Option<stripe_shared::PaymentPagesCheckoutSessionCustomFieldsDropdown>,
7 pub key: String,
10 pub label: stripe_shared::PaymentPagesCheckoutSessionCustomFieldsLabel,
11 pub numeric: Option<stripe_shared::PaymentPagesCheckoutSessionCustomFieldsNumeric>,
12 pub optional: bool,
15 pub text: Option<stripe_shared::PaymentPagesCheckoutSessionCustomFieldsText>,
16 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
18 pub type_: PaymentPagesCheckoutSessionCustomFieldsType,
19}
20#[cfg(feature = "redact-generated-debug")]
21impl std::fmt::Debug for PaymentPagesCheckoutSessionCustomFields {
22 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23 f.debug_struct("PaymentPagesCheckoutSessionCustomFields").finish_non_exhaustive()
24 }
25}
26#[doc(hidden)]
27pub struct PaymentPagesCheckoutSessionCustomFieldsBuilder {
28 dropdown: Option<Option<stripe_shared::PaymentPagesCheckoutSessionCustomFieldsDropdown>>,
29 key: Option<String>,
30 label: Option<stripe_shared::PaymentPagesCheckoutSessionCustomFieldsLabel>,
31 numeric: Option<Option<stripe_shared::PaymentPagesCheckoutSessionCustomFieldsNumeric>>,
32 optional: Option<bool>,
33 text: Option<Option<stripe_shared::PaymentPagesCheckoutSessionCustomFieldsText>>,
34 type_: Option<PaymentPagesCheckoutSessionCustomFieldsType>,
35}
36
37#[allow(
38 unused_variables,
39 irrefutable_let_patterns,
40 clippy::let_unit_value,
41 clippy::match_single_binding,
42 clippy::single_match
43)]
44const _: () = {
45 use miniserde::de::{Map, Visitor};
46 use miniserde::json::Value;
47 use miniserde::{Deserialize, Result, make_place};
48 use stripe_types::miniserde_helpers::FromValueOpt;
49 use stripe_types::{MapBuilder, ObjectDeser};
50
51 make_place!(Place);
52
53 impl Deserialize for PaymentPagesCheckoutSessionCustomFields {
54 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
55 Place::new(out)
56 }
57 }
58
59 struct Builder<'a> {
60 out: &'a mut Option<PaymentPagesCheckoutSessionCustomFields>,
61 builder: PaymentPagesCheckoutSessionCustomFieldsBuilder,
62 }
63
64 impl Visitor for Place<PaymentPagesCheckoutSessionCustomFields> {
65 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
66 Ok(Box::new(Builder {
67 out: &mut self.out,
68 builder: PaymentPagesCheckoutSessionCustomFieldsBuilder::deser_default(),
69 }))
70 }
71 }
72
73 impl MapBuilder for PaymentPagesCheckoutSessionCustomFieldsBuilder {
74 type Out = PaymentPagesCheckoutSessionCustomFields;
75 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
76 Ok(match k {
77 "dropdown" => Deserialize::begin(&mut self.dropdown),
78 "key" => Deserialize::begin(&mut self.key),
79 "label" => Deserialize::begin(&mut self.label),
80 "numeric" => Deserialize::begin(&mut self.numeric),
81 "optional" => Deserialize::begin(&mut self.optional),
82 "text" => Deserialize::begin(&mut self.text),
83 "type" => Deserialize::begin(&mut self.type_),
84 _ => <dyn Visitor>::ignore(),
85 })
86 }
87
88 fn deser_default() -> Self {
89 Self {
90 dropdown: Some(None),
91 key: None,
92 label: None,
93 numeric: Some(None),
94 optional: None,
95 text: Some(None),
96 type_: None,
97 }
98 }
99
100 fn take_out(&mut self) -> Option<Self::Out> {
101 let (
102 Some(dropdown),
103 Some(key),
104 Some(label),
105 Some(numeric),
106 Some(optional),
107 Some(text),
108 Some(type_),
109 ) = (
110 self.dropdown.take(),
111 self.key.take(),
112 self.label.take(),
113 self.numeric.take(),
114 self.optional,
115 self.text.take(),
116 self.type_.take(),
117 )
118 else {
119 return None;
120 };
121 Some(Self::Out { dropdown, key, label, numeric, optional, text, type_ })
122 }
123 }
124
125 impl Map for Builder<'_> {
126 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
127 self.builder.key(k)
128 }
129
130 fn finish(&mut self) -> Result<()> {
131 *self.out = self.builder.take_out();
132 Ok(())
133 }
134 }
135
136 impl ObjectDeser for PaymentPagesCheckoutSessionCustomFields {
137 type Builder = PaymentPagesCheckoutSessionCustomFieldsBuilder;
138 }
139
140 impl FromValueOpt for PaymentPagesCheckoutSessionCustomFields {
141 fn from_value(v: Value) -> Option<Self> {
142 let Value::Object(obj) = v else {
143 return None;
144 };
145 let mut b = PaymentPagesCheckoutSessionCustomFieldsBuilder::deser_default();
146 for (k, v) in obj {
147 match k.as_str() {
148 "dropdown" => b.dropdown = FromValueOpt::from_value(v),
149 "key" => b.key = FromValueOpt::from_value(v),
150 "label" => b.label = FromValueOpt::from_value(v),
151 "numeric" => b.numeric = FromValueOpt::from_value(v),
152 "optional" => b.optional = FromValueOpt::from_value(v),
153 "text" => b.text = FromValueOpt::from_value(v),
154 "type" => b.type_ = FromValueOpt::from_value(v),
155 _ => {}
156 }
157 }
158 b.take_out()
159 }
160 }
161};
162#[derive(Clone, Eq, PartialEq)]
164#[non_exhaustive]
165pub enum PaymentPagesCheckoutSessionCustomFieldsType {
166 Dropdown,
167 Numeric,
168 Text,
169 Unknown(String),
171}
172impl PaymentPagesCheckoutSessionCustomFieldsType {
173 pub fn as_str(&self) -> &str {
174 use PaymentPagesCheckoutSessionCustomFieldsType::*;
175 match self {
176 Dropdown => "dropdown",
177 Numeric => "numeric",
178 Text => "text",
179 Unknown(v) => v,
180 }
181 }
182}
183
184impl std::str::FromStr for PaymentPagesCheckoutSessionCustomFieldsType {
185 type Err = std::convert::Infallible;
186 fn from_str(s: &str) -> Result<Self, Self::Err> {
187 use PaymentPagesCheckoutSessionCustomFieldsType::*;
188 match s {
189 "dropdown" => Ok(Dropdown),
190 "numeric" => Ok(Numeric),
191 "text" => Ok(Text),
192 v => {
193 tracing::warn!(
194 "Unknown value '{}' for enum '{}'",
195 v,
196 "PaymentPagesCheckoutSessionCustomFieldsType"
197 );
198 Ok(Unknown(v.to_owned()))
199 }
200 }
201 }
202}
203impl std::fmt::Display for PaymentPagesCheckoutSessionCustomFieldsType {
204 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
205 f.write_str(self.as_str())
206 }
207}
208
209#[cfg(not(feature = "redact-generated-debug"))]
210impl std::fmt::Debug for PaymentPagesCheckoutSessionCustomFieldsType {
211 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
212 f.write_str(self.as_str())
213 }
214}
215#[cfg(feature = "redact-generated-debug")]
216impl std::fmt::Debug for PaymentPagesCheckoutSessionCustomFieldsType {
217 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
218 f.debug_struct(stringify!(PaymentPagesCheckoutSessionCustomFieldsType))
219 .finish_non_exhaustive()
220 }
221}
222#[cfg(feature = "serialize")]
223impl serde::Serialize for PaymentPagesCheckoutSessionCustomFieldsType {
224 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
225 where
226 S: serde::Serializer,
227 {
228 serializer.serialize_str(self.as_str())
229 }
230}
231impl miniserde::Deserialize for PaymentPagesCheckoutSessionCustomFieldsType {
232 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
233 crate::Place::new(out)
234 }
235}
236
237impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionCustomFieldsType> {
238 fn string(&mut self, s: &str) -> miniserde::Result<()> {
239 use std::str::FromStr;
240 self.out =
241 Some(PaymentPagesCheckoutSessionCustomFieldsType::from_str(s).expect("infallible"));
242 Ok(())
243 }
244}
245
246stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionCustomFieldsType);
247#[cfg(feature = "deserialize")]
248impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionCustomFieldsType {
249 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
250 use std::str::FromStr;
251 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
252 Ok(Self::from_str(&s).expect("infallible"))
253 }
254}