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::{make_place, Deserialize, Result};
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
70 _ => <dyn Visitor>::ignore(),
71 })
72 }
73
74 fn deser_default() -> Self {
75 Self {
76 capture_method: Deserialize::default(),
77 preferred_locale: Deserialize::default(),
78 setup_future_usage: Deserialize::default(),
79 }
80 }
81
82 fn take_out(&mut self) -> Option<Self::Out> {
83 let (Some(capture_method), Some(preferred_locale), Some(setup_future_usage)) =
84 (self.capture_method, self.preferred_locale.take(), self.setup_future_usage)
85 else {
86 return None;
87 };
88 Some(Self::Out { capture_method, preferred_locale, setup_future_usage })
89 }
90 }
91
92 impl<'a> Map for Builder<'a> {
93 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
94 self.builder.key(k)
95 }
96
97 fn finish(&mut self) -> Result<()> {
98 *self.out = self.builder.take_out();
99 Ok(())
100 }
101 }
102
103 impl ObjectDeser for PaymentMethodOptionsAffirm {
104 type Builder = PaymentMethodOptionsAffirmBuilder;
105 }
106
107 impl FromValueOpt for PaymentMethodOptionsAffirm {
108 fn from_value(v: Value) -> Option<Self> {
109 let Value::Object(obj) = v else {
110 return None;
111 };
112 let mut b = PaymentMethodOptionsAffirmBuilder::deser_default();
113 for (k, v) in obj {
114 match k.as_str() {
115 "capture_method" => b.capture_method = FromValueOpt::from_value(v),
116 "preferred_locale" => b.preferred_locale = FromValueOpt::from_value(v),
117 "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
118
119 _ => {}
120 }
121 }
122 b.take_out()
123 }
124 }
125};
126#[derive(Copy, Clone, Eq, PartialEq)]
128pub enum PaymentMethodOptionsAffirmCaptureMethod {
129 Manual,
130}
131impl PaymentMethodOptionsAffirmCaptureMethod {
132 pub fn as_str(self) -> &'static str {
133 use PaymentMethodOptionsAffirmCaptureMethod::*;
134 match self {
135 Manual => "manual",
136 }
137 }
138}
139
140impl std::str::FromStr for PaymentMethodOptionsAffirmCaptureMethod {
141 type Err = stripe_types::StripeParseError;
142 fn from_str(s: &str) -> Result<Self, Self::Err> {
143 use PaymentMethodOptionsAffirmCaptureMethod::*;
144 match s {
145 "manual" => Ok(Manual),
146 _ => Err(stripe_types::StripeParseError),
147 }
148 }
149}
150impl std::fmt::Display for PaymentMethodOptionsAffirmCaptureMethod {
151 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152 f.write_str(self.as_str())
153 }
154}
155
156impl std::fmt::Debug for PaymentMethodOptionsAffirmCaptureMethod {
157 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158 f.write_str(self.as_str())
159 }
160}
161#[cfg(feature = "serialize")]
162impl serde::Serialize for PaymentMethodOptionsAffirmCaptureMethod {
163 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
164 where
165 S: serde::Serializer,
166 {
167 serializer.serialize_str(self.as_str())
168 }
169}
170impl miniserde::Deserialize for PaymentMethodOptionsAffirmCaptureMethod {
171 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
172 crate::Place::new(out)
173 }
174}
175
176impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsAffirmCaptureMethod> {
177 fn string(&mut self, s: &str) -> miniserde::Result<()> {
178 use std::str::FromStr;
179 self.out = Some(
180 PaymentMethodOptionsAffirmCaptureMethod::from_str(s).map_err(|_| miniserde::Error)?,
181 );
182 Ok(())
183 }
184}
185
186stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsAffirmCaptureMethod);
187#[cfg(feature = "deserialize")]
188impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsAffirmCaptureMethod {
189 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
190 use std::str::FromStr;
191 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
192 Self::from_str(&s).map_err(|_| {
193 serde::de::Error::custom("Unknown value for PaymentMethodOptionsAffirmCaptureMethod")
194 })
195 }
196}
197#[derive(Copy, Clone, Eq, PartialEq)]
206pub enum PaymentMethodOptionsAffirmSetupFutureUsage {
207 None,
208}
209impl PaymentMethodOptionsAffirmSetupFutureUsage {
210 pub fn as_str(self) -> &'static str {
211 use PaymentMethodOptionsAffirmSetupFutureUsage::*;
212 match self {
213 None => "none",
214 }
215 }
216}
217
218impl std::str::FromStr for PaymentMethodOptionsAffirmSetupFutureUsage {
219 type Err = stripe_types::StripeParseError;
220 fn from_str(s: &str) -> Result<Self, Self::Err> {
221 use PaymentMethodOptionsAffirmSetupFutureUsage::*;
222 match s {
223 "none" => Ok(None),
224 _ => Err(stripe_types::StripeParseError),
225 }
226 }
227}
228impl std::fmt::Display for PaymentMethodOptionsAffirmSetupFutureUsage {
229 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
230 f.write_str(self.as_str())
231 }
232}
233
234impl std::fmt::Debug for PaymentMethodOptionsAffirmSetupFutureUsage {
235 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236 f.write_str(self.as_str())
237 }
238}
239#[cfg(feature = "serialize")]
240impl serde::Serialize for PaymentMethodOptionsAffirmSetupFutureUsage {
241 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
242 where
243 S: serde::Serializer,
244 {
245 serializer.serialize_str(self.as_str())
246 }
247}
248impl miniserde::Deserialize for PaymentMethodOptionsAffirmSetupFutureUsage {
249 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
250 crate::Place::new(out)
251 }
252}
253
254impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsAffirmSetupFutureUsage> {
255 fn string(&mut self, s: &str) -> miniserde::Result<()> {
256 use std::str::FromStr;
257 self.out = Some(
258 PaymentMethodOptionsAffirmSetupFutureUsage::from_str(s)
259 .map_err(|_| miniserde::Error)?,
260 );
261 Ok(())
262 }
263}
264
265stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsAffirmSetupFutureUsage);
266#[cfg(feature = "deserialize")]
267impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsAffirmSetupFutureUsage {
268 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
269 use std::str::FromStr;
270 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
271 Self::from_str(&s).map_err(|_| {
272 serde::de::Error::custom("Unknown value for PaymentMethodOptionsAffirmSetupFutureUsage")
273 })
274 }
275}