1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsPaypal {
5 pub capture_method: Option<PaymentMethodOptionsPaypalCaptureMethod>,
7 pub preferred_locale: Option<String>,
9 pub reference: Option<String>,
12 pub setup_future_usage: Option<PaymentMethodOptionsPaypalSetupFutureUsage>,
21}
22#[doc(hidden)]
23pub struct PaymentMethodOptionsPaypalBuilder {
24 capture_method: Option<Option<PaymentMethodOptionsPaypalCaptureMethod>>,
25 preferred_locale: Option<Option<String>>,
26 reference: Option<Option<String>>,
27 setup_future_usage: Option<Option<PaymentMethodOptionsPaypalSetupFutureUsage>>,
28}
29
30#[allow(
31 unused_variables,
32 irrefutable_let_patterns,
33 clippy::let_unit_value,
34 clippy::match_single_binding,
35 clippy::single_match
36)]
37const _: () = {
38 use miniserde::de::{Map, Visitor};
39 use miniserde::json::Value;
40 use miniserde::{Deserialize, Result, make_place};
41 use stripe_types::miniserde_helpers::FromValueOpt;
42 use stripe_types::{MapBuilder, ObjectDeser};
43
44 make_place!(Place);
45
46 impl Deserialize for PaymentMethodOptionsPaypal {
47 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
48 Place::new(out)
49 }
50 }
51
52 struct Builder<'a> {
53 out: &'a mut Option<PaymentMethodOptionsPaypal>,
54 builder: PaymentMethodOptionsPaypalBuilder,
55 }
56
57 impl Visitor for Place<PaymentMethodOptionsPaypal> {
58 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59 Ok(Box::new(Builder {
60 out: &mut self.out,
61 builder: PaymentMethodOptionsPaypalBuilder::deser_default(),
62 }))
63 }
64 }
65
66 impl MapBuilder for PaymentMethodOptionsPaypalBuilder {
67 type Out = PaymentMethodOptionsPaypal;
68 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
69 Ok(match k {
70 "capture_method" => Deserialize::begin(&mut self.capture_method),
71 "preferred_locale" => Deserialize::begin(&mut self.preferred_locale),
72 "reference" => Deserialize::begin(&mut self.reference),
73 "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
74 _ => <dyn Visitor>::ignore(),
75 })
76 }
77
78 fn deser_default() -> Self {
79 Self {
80 capture_method: Deserialize::default(),
81 preferred_locale: Deserialize::default(),
82 reference: Deserialize::default(),
83 setup_future_usage: Deserialize::default(),
84 }
85 }
86
87 fn take_out(&mut self) -> Option<Self::Out> {
88 let (
89 Some(capture_method),
90 Some(preferred_locale),
91 Some(reference),
92 Some(setup_future_usage),
93 ) = (
94 self.capture_method.take(),
95 self.preferred_locale.take(),
96 self.reference.take(),
97 self.setup_future_usage.take(),
98 )
99 else {
100 return None;
101 };
102 Some(Self::Out { capture_method, preferred_locale, reference, setup_future_usage })
103 }
104 }
105
106 impl Map for Builder<'_> {
107 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
108 self.builder.key(k)
109 }
110
111 fn finish(&mut self) -> Result<()> {
112 *self.out = self.builder.take_out();
113 Ok(())
114 }
115 }
116
117 impl ObjectDeser for PaymentMethodOptionsPaypal {
118 type Builder = PaymentMethodOptionsPaypalBuilder;
119 }
120
121 impl FromValueOpt for PaymentMethodOptionsPaypal {
122 fn from_value(v: Value) -> Option<Self> {
123 let Value::Object(obj) = v else {
124 return None;
125 };
126 let mut b = PaymentMethodOptionsPaypalBuilder::deser_default();
127 for (k, v) in obj {
128 match k.as_str() {
129 "capture_method" => b.capture_method = FromValueOpt::from_value(v),
130 "preferred_locale" => b.preferred_locale = FromValueOpt::from_value(v),
131 "reference" => b.reference = FromValueOpt::from_value(v),
132 "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
133 _ => {}
134 }
135 }
136 b.take_out()
137 }
138 }
139};
140#[derive(Clone, Eq, PartialEq)]
142#[non_exhaustive]
143pub enum PaymentMethodOptionsPaypalCaptureMethod {
144 Manual,
145 Unknown(String),
147}
148impl PaymentMethodOptionsPaypalCaptureMethod {
149 pub fn as_str(&self) -> &str {
150 use PaymentMethodOptionsPaypalCaptureMethod::*;
151 match self {
152 Manual => "manual",
153 Unknown(v) => v,
154 }
155 }
156}
157
158impl std::str::FromStr for PaymentMethodOptionsPaypalCaptureMethod {
159 type Err = std::convert::Infallible;
160 fn from_str(s: &str) -> Result<Self, Self::Err> {
161 use PaymentMethodOptionsPaypalCaptureMethod::*;
162 match s {
163 "manual" => Ok(Manual),
164 v => {
165 tracing::warn!(
166 "Unknown value '{}' for enum '{}'",
167 v,
168 "PaymentMethodOptionsPaypalCaptureMethod"
169 );
170 Ok(Unknown(v.to_owned()))
171 }
172 }
173 }
174}
175impl std::fmt::Display for PaymentMethodOptionsPaypalCaptureMethod {
176 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177 f.write_str(self.as_str())
178 }
179}
180
181impl std::fmt::Debug for PaymentMethodOptionsPaypalCaptureMethod {
182 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183 f.write_str(self.as_str())
184 }
185}
186#[cfg(feature = "serialize")]
187impl serde::Serialize for PaymentMethodOptionsPaypalCaptureMethod {
188 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
189 where
190 S: serde::Serializer,
191 {
192 serializer.serialize_str(self.as_str())
193 }
194}
195impl miniserde::Deserialize for PaymentMethodOptionsPaypalCaptureMethod {
196 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
197 crate::Place::new(out)
198 }
199}
200
201impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsPaypalCaptureMethod> {
202 fn string(&mut self, s: &str) -> miniserde::Result<()> {
203 use std::str::FromStr;
204 self.out = Some(PaymentMethodOptionsPaypalCaptureMethod::from_str(s).expect("infallible"));
205 Ok(())
206 }
207}
208
209stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsPaypalCaptureMethod);
210#[cfg(feature = "deserialize")]
211impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsPaypalCaptureMethod {
212 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
213 use std::str::FromStr;
214 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
215 Ok(Self::from_str(&s).expect("infallible"))
216 }
217}
218#[derive(Clone, Eq, PartialEq)]
227#[non_exhaustive]
228pub enum PaymentMethodOptionsPaypalSetupFutureUsage {
229 None,
230 OffSession,
231 Unknown(String),
233}
234impl PaymentMethodOptionsPaypalSetupFutureUsage {
235 pub fn as_str(&self) -> &str {
236 use PaymentMethodOptionsPaypalSetupFutureUsage::*;
237 match self {
238 None => "none",
239 OffSession => "off_session",
240 Unknown(v) => v,
241 }
242 }
243}
244
245impl std::str::FromStr for PaymentMethodOptionsPaypalSetupFutureUsage {
246 type Err = std::convert::Infallible;
247 fn from_str(s: &str) -> Result<Self, Self::Err> {
248 use PaymentMethodOptionsPaypalSetupFutureUsage::*;
249 match s {
250 "none" => Ok(None),
251 "off_session" => Ok(OffSession),
252 v => {
253 tracing::warn!(
254 "Unknown value '{}' for enum '{}'",
255 v,
256 "PaymentMethodOptionsPaypalSetupFutureUsage"
257 );
258 Ok(Unknown(v.to_owned()))
259 }
260 }
261 }
262}
263impl std::fmt::Display for PaymentMethodOptionsPaypalSetupFutureUsage {
264 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
265 f.write_str(self.as_str())
266 }
267}
268
269impl std::fmt::Debug for PaymentMethodOptionsPaypalSetupFutureUsage {
270 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
271 f.write_str(self.as_str())
272 }
273}
274#[cfg(feature = "serialize")]
275impl serde::Serialize for PaymentMethodOptionsPaypalSetupFutureUsage {
276 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
277 where
278 S: serde::Serializer,
279 {
280 serializer.serialize_str(self.as_str())
281 }
282}
283impl miniserde::Deserialize for PaymentMethodOptionsPaypalSetupFutureUsage {
284 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
285 crate::Place::new(out)
286 }
287}
288
289impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsPaypalSetupFutureUsage> {
290 fn string(&mut self, s: &str) -> miniserde::Result<()> {
291 use std::str::FromStr;
292 self.out =
293 Some(PaymentMethodOptionsPaypalSetupFutureUsage::from_str(s).expect("infallible"));
294 Ok(())
295 }
296}
297
298stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsPaypalSetupFutureUsage);
299#[cfg(feature = "deserialize")]
300impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsPaypalSetupFutureUsage {
301 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
302 use std::str::FromStr;
303 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
304 Ok(Self::from_str(&s).expect("infallible"))
305 }
306}