stripe_shared/
checkout_link_payment_method_options.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 CheckoutLinkPaymentMethodOptions {
6 pub capture_method: Option<CheckoutLinkPaymentMethodOptionsCaptureMethod>,
8 pub setup_future_usage: Option<CheckoutLinkPaymentMethodOptionsSetupFutureUsage>,
17}
18#[cfg(feature = "redact-generated-debug")]
19impl std::fmt::Debug for CheckoutLinkPaymentMethodOptions {
20 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21 f.debug_struct("CheckoutLinkPaymentMethodOptions").finish_non_exhaustive()
22 }
23}
24#[doc(hidden)]
25pub struct CheckoutLinkPaymentMethodOptionsBuilder {
26 capture_method: Option<Option<CheckoutLinkPaymentMethodOptionsCaptureMethod>>,
27 setup_future_usage: Option<Option<CheckoutLinkPaymentMethodOptionsSetupFutureUsage>>,
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 CheckoutLinkPaymentMethodOptions {
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<CheckoutLinkPaymentMethodOptions>,
54 builder: CheckoutLinkPaymentMethodOptionsBuilder,
55 }
56
57 impl Visitor for Place<CheckoutLinkPaymentMethodOptions> {
58 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59 Ok(Box::new(Builder {
60 out: &mut self.out,
61 builder: CheckoutLinkPaymentMethodOptionsBuilder::deser_default(),
62 }))
63 }
64 }
65
66 impl MapBuilder for CheckoutLinkPaymentMethodOptionsBuilder {
67 type Out = CheckoutLinkPaymentMethodOptions;
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 "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
72 _ => <dyn Visitor>::ignore(),
73 })
74 }
75
76 fn deser_default() -> Self {
77 Self {
78 capture_method: Deserialize::default(),
79 setup_future_usage: Deserialize::default(),
80 }
81 }
82
83 fn take_out(&mut self) -> Option<Self::Out> {
84 let (Some(capture_method), Some(setup_future_usage)) =
85 (self.capture_method.take(), self.setup_future_usage.take())
86 else {
87 return None;
88 };
89 Some(Self::Out { capture_method, 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 CheckoutLinkPaymentMethodOptions {
105 type Builder = CheckoutLinkPaymentMethodOptionsBuilder;
106 }
107
108 impl FromValueOpt for CheckoutLinkPaymentMethodOptions {
109 fn from_value(v: Value) -> Option<Self> {
110 let Value::Object(obj) = v else {
111 return None;
112 };
113 let mut b = CheckoutLinkPaymentMethodOptionsBuilder::deser_default();
114 for (k, v) in obj {
115 match k.as_str() {
116 "capture_method" => b.capture_method = FromValueOpt::from_value(v),
117 "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
118 _ => {}
119 }
120 }
121 b.take_out()
122 }
123 }
124};
125#[derive(Clone, Eq, PartialEq)]
127#[non_exhaustive]
128pub enum CheckoutLinkPaymentMethodOptionsCaptureMethod {
129 Manual,
130 Unknown(String),
132}
133impl CheckoutLinkPaymentMethodOptionsCaptureMethod {
134 pub fn as_str(&self) -> &str {
135 use CheckoutLinkPaymentMethodOptionsCaptureMethod::*;
136 match self {
137 Manual => "manual",
138 Unknown(v) => v,
139 }
140 }
141}
142
143impl std::str::FromStr for CheckoutLinkPaymentMethodOptionsCaptureMethod {
144 type Err = std::convert::Infallible;
145 fn from_str(s: &str) -> Result<Self, Self::Err> {
146 use CheckoutLinkPaymentMethodOptionsCaptureMethod::*;
147 match s {
148 "manual" => Ok(Manual),
149 v => {
150 tracing::warn!(
151 "Unknown value '{}' for enum '{}'",
152 v,
153 "CheckoutLinkPaymentMethodOptionsCaptureMethod"
154 );
155 Ok(Unknown(v.to_owned()))
156 }
157 }
158 }
159}
160impl std::fmt::Display for CheckoutLinkPaymentMethodOptionsCaptureMethod {
161 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162 f.write_str(self.as_str())
163 }
164}
165
166#[cfg(not(feature = "redact-generated-debug"))]
167impl std::fmt::Debug for CheckoutLinkPaymentMethodOptionsCaptureMethod {
168 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169 f.write_str(self.as_str())
170 }
171}
172#[cfg(feature = "redact-generated-debug")]
173impl std::fmt::Debug for CheckoutLinkPaymentMethodOptionsCaptureMethod {
174 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
175 f.debug_struct(stringify!(CheckoutLinkPaymentMethodOptionsCaptureMethod))
176 .finish_non_exhaustive()
177 }
178}
179#[cfg(feature = "serialize")]
180impl serde::Serialize for CheckoutLinkPaymentMethodOptionsCaptureMethod {
181 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
182 where
183 S: serde::Serializer,
184 {
185 serializer.serialize_str(self.as_str())
186 }
187}
188impl miniserde::Deserialize for CheckoutLinkPaymentMethodOptionsCaptureMethod {
189 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
190 crate::Place::new(out)
191 }
192}
193
194impl miniserde::de::Visitor for crate::Place<CheckoutLinkPaymentMethodOptionsCaptureMethod> {
195 fn string(&mut self, s: &str) -> miniserde::Result<()> {
196 use std::str::FromStr;
197 self.out =
198 Some(CheckoutLinkPaymentMethodOptionsCaptureMethod::from_str(s).expect("infallible"));
199 Ok(())
200 }
201}
202
203stripe_types::impl_from_val_with_from_str!(CheckoutLinkPaymentMethodOptionsCaptureMethod);
204#[cfg(feature = "deserialize")]
205impl<'de> serde::Deserialize<'de> for CheckoutLinkPaymentMethodOptionsCaptureMethod {
206 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
207 use std::str::FromStr;
208 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
209 Ok(Self::from_str(&s).expect("infallible"))
210 }
211}
212#[derive(Clone, Eq, PartialEq)]
221#[non_exhaustive]
222pub enum CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
223 None,
224 OffSession,
225 Unknown(String),
227}
228impl CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
229 pub fn as_str(&self) -> &str {
230 use CheckoutLinkPaymentMethodOptionsSetupFutureUsage::*;
231 match self {
232 None => "none",
233 OffSession => "off_session",
234 Unknown(v) => v,
235 }
236 }
237}
238
239impl std::str::FromStr for CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
240 type Err = std::convert::Infallible;
241 fn from_str(s: &str) -> Result<Self, Self::Err> {
242 use CheckoutLinkPaymentMethodOptionsSetupFutureUsage::*;
243 match s {
244 "none" => Ok(None),
245 "off_session" => Ok(OffSession),
246 v => {
247 tracing::warn!(
248 "Unknown value '{}' for enum '{}'",
249 v,
250 "CheckoutLinkPaymentMethodOptionsSetupFutureUsage"
251 );
252 Ok(Unknown(v.to_owned()))
253 }
254 }
255 }
256}
257impl std::fmt::Display for CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
258 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
259 f.write_str(self.as_str())
260 }
261}
262
263#[cfg(not(feature = "redact-generated-debug"))]
264impl std::fmt::Debug for CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
265 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
266 f.write_str(self.as_str())
267 }
268}
269#[cfg(feature = "redact-generated-debug")]
270impl std::fmt::Debug for CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
271 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
272 f.debug_struct(stringify!(CheckoutLinkPaymentMethodOptionsSetupFutureUsage))
273 .finish_non_exhaustive()
274 }
275}
276#[cfg(feature = "serialize")]
277impl serde::Serialize for CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
278 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
279 where
280 S: serde::Serializer,
281 {
282 serializer.serialize_str(self.as_str())
283 }
284}
285impl miniserde::Deserialize for CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
286 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
287 crate::Place::new(out)
288 }
289}
290
291impl miniserde::de::Visitor for crate::Place<CheckoutLinkPaymentMethodOptionsSetupFutureUsage> {
292 fn string(&mut self, s: &str) -> miniserde::Result<()> {
293 use std::str::FromStr;
294 self.out = Some(
295 CheckoutLinkPaymentMethodOptionsSetupFutureUsage::from_str(s).expect("infallible"),
296 );
297 Ok(())
298 }
299}
300
301stripe_types::impl_from_val_with_from_str!(CheckoutLinkPaymentMethodOptionsSetupFutureUsage);
302#[cfg(feature = "deserialize")]
303impl<'de> serde::Deserialize<'de> for CheckoutLinkPaymentMethodOptionsSetupFutureUsage {
304 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
305 use std::str::FromStr;
306 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
307 Ok(Self::from_str(&s).expect("infallible"))
308 }
309}