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