stripe_shared/
payment_method_options_klarna.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsKlarna {
5 pub capture_method: Option<PaymentMethodOptionsKlarnaCaptureMethod>,
7 pub preferred_locale: Option<String>,
9 pub setup_future_usage: Option<PaymentMethodOptionsKlarnaSetupFutureUsage>,
18}
19#[doc(hidden)]
20pub struct PaymentMethodOptionsKlarnaBuilder {
21 capture_method: Option<Option<PaymentMethodOptionsKlarnaCaptureMethod>>,
22 preferred_locale: Option<Option<String>>,
23 setup_future_usage: Option<Option<PaymentMethodOptionsKlarnaSetupFutureUsage>>,
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 PaymentMethodOptionsKlarna {
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<PaymentMethodOptionsKlarna>,
50 builder: PaymentMethodOptionsKlarnaBuilder,
51 }
52
53 impl Visitor for Place<PaymentMethodOptionsKlarna> {
54 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55 Ok(Box::new(Builder {
56 out: &mut self.out,
57 builder: PaymentMethodOptionsKlarnaBuilder::deser_default(),
58 }))
59 }
60 }
61
62 impl MapBuilder for PaymentMethodOptionsKlarnaBuilder {
63 type Out = PaymentMethodOptionsKlarna;
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 Map for Builder<'_> {
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 PaymentMethodOptionsKlarna {
104 type Builder = PaymentMethodOptionsKlarnaBuilder;
105 }
106
107 impl FromValueOpt for PaymentMethodOptionsKlarna {
108 fn from_value(v: Value) -> Option<Self> {
109 let Value::Object(obj) = v else {
110 return None;
111 };
112 let mut b = PaymentMethodOptionsKlarnaBuilder::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 PaymentMethodOptionsKlarnaCaptureMethod {
129 Manual,
130}
131impl PaymentMethodOptionsKlarnaCaptureMethod {
132 pub fn as_str(self) -> &'static str {
133 use PaymentMethodOptionsKlarnaCaptureMethod::*;
134 match self {
135 Manual => "manual",
136 }
137 }
138}
139
140impl std::str::FromStr for PaymentMethodOptionsKlarnaCaptureMethod {
141 type Err = stripe_types::StripeParseError;
142 fn from_str(s: &str) -> Result<Self, Self::Err> {
143 use PaymentMethodOptionsKlarnaCaptureMethod::*;
144 match s {
145 "manual" => Ok(Manual),
146 _ => Err(stripe_types::StripeParseError),
147 }
148 }
149}
150impl std::fmt::Display for PaymentMethodOptionsKlarnaCaptureMethod {
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 PaymentMethodOptionsKlarnaCaptureMethod {
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 PaymentMethodOptionsKlarnaCaptureMethod {
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 PaymentMethodOptionsKlarnaCaptureMethod {
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<PaymentMethodOptionsKlarnaCaptureMethod> {
177 fn string(&mut self, s: &str) -> miniserde::Result<()> {
178 use std::str::FromStr;
179 self.out = Some(
180 PaymentMethodOptionsKlarnaCaptureMethod::from_str(s).map_err(|_| miniserde::Error)?,
181 );
182 Ok(())
183 }
184}
185
186stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsKlarnaCaptureMethod);
187#[cfg(feature = "deserialize")]
188impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsKlarnaCaptureMethod {
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 PaymentMethodOptionsKlarnaCaptureMethod")
194 })
195 }
196}
197#[derive(Copy, Clone, Eq, PartialEq)]
206pub enum PaymentMethodOptionsKlarnaSetupFutureUsage {
207 None,
208 OffSession,
209 OnSession,
210}
211impl PaymentMethodOptionsKlarnaSetupFutureUsage {
212 pub fn as_str(self) -> &'static str {
213 use PaymentMethodOptionsKlarnaSetupFutureUsage::*;
214 match self {
215 None => "none",
216 OffSession => "off_session",
217 OnSession => "on_session",
218 }
219 }
220}
221
222impl std::str::FromStr for PaymentMethodOptionsKlarnaSetupFutureUsage {
223 type Err = stripe_types::StripeParseError;
224 fn from_str(s: &str) -> Result<Self, Self::Err> {
225 use PaymentMethodOptionsKlarnaSetupFutureUsage::*;
226 match s {
227 "none" => Ok(None),
228 "off_session" => Ok(OffSession),
229 "on_session" => Ok(OnSession),
230 _ => Err(stripe_types::StripeParseError),
231 }
232 }
233}
234impl std::fmt::Display for PaymentMethodOptionsKlarnaSetupFutureUsage {
235 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236 f.write_str(self.as_str())
237 }
238}
239
240impl std::fmt::Debug for PaymentMethodOptionsKlarnaSetupFutureUsage {
241 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
242 f.write_str(self.as_str())
243 }
244}
245#[cfg(feature = "serialize")]
246impl serde::Serialize for PaymentMethodOptionsKlarnaSetupFutureUsage {
247 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
248 where
249 S: serde::Serializer,
250 {
251 serializer.serialize_str(self.as_str())
252 }
253}
254impl miniserde::Deserialize for PaymentMethodOptionsKlarnaSetupFutureUsage {
255 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
256 crate::Place::new(out)
257 }
258}
259
260impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsKlarnaSetupFutureUsage> {
261 fn string(&mut self, s: &str) -> miniserde::Result<()> {
262 use std::str::FromStr;
263 self.out = Some(
264 PaymentMethodOptionsKlarnaSetupFutureUsage::from_str(s)
265 .map_err(|_| miniserde::Error)?,
266 );
267 Ok(())
268 }
269}
270
271stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsKlarnaSetupFutureUsage);
272#[cfg(feature = "deserialize")]
273impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsKlarnaSetupFutureUsage {
274 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
275 use std::str::FromStr;
276 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
277 Self::from_str(&s).map_err(|_| {
278 serde::de::Error::custom("Unknown value for PaymentMethodOptionsKlarnaSetupFutureUsage")
279 })
280 }
281}