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