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