stripe_shared/
payment_method_options_card_present.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsCardPresent {
5 pub capture_method: Option<PaymentMethodOptionsCardPresentCaptureMethod>,
7 pub request_extended_authorization: Option<bool>,
9 pub request_incremental_authorization_support: Option<bool>,
12 pub routing: Option<stripe_shared::PaymentMethodOptionsCardPresentRouting>,
13}
14#[doc(hidden)]
15pub struct PaymentMethodOptionsCardPresentBuilder {
16 capture_method: Option<Option<PaymentMethodOptionsCardPresentCaptureMethod>>,
17 request_extended_authorization: Option<Option<bool>>,
18 request_incremental_authorization_support: Option<Option<bool>>,
19 routing: Option<Option<stripe_shared::PaymentMethodOptionsCardPresentRouting>>,
20}
21
22#[allow(
23 unused_variables,
24 irrefutable_let_patterns,
25 clippy::let_unit_value,
26 clippy::match_single_binding,
27 clippy::single_match
28)]
29const _: () = {
30 use miniserde::de::{Map, Visitor};
31 use miniserde::json::Value;
32 use miniserde::{Deserialize, Result, make_place};
33 use stripe_types::miniserde_helpers::FromValueOpt;
34 use stripe_types::{MapBuilder, ObjectDeser};
35
36 make_place!(Place);
37
38 impl Deserialize for PaymentMethodOptionsCardPresent {
39 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40 Place::new(out)
41 }
42 }
43
44 struct Builder<'a> {
45 out: &'a mut Option<PaymentMethodOptionsCardPresent>,
46 builder: PaymentMethodOptionsCardPresentBuilder,
47 }
48
49 impl Visitor for Place<PaymentMethodOptionsCardPresent> {
50 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51 Ok(Box::new(Builder {
52 out: &mut self.out,
53 builder: PaymentMethodOptionsCardPresentBuilder::deser_default(),
54 }))
55 }
56 }
57
58 impl MapBuilder for PaymentMethodOptionsCardPresentBuilder {
59 type Out = PaymentMethodOptionsCardPresent;
60 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61 Ok(match k {
62 "capture_method" => Deserialize::begin(&mut self.capture_method),
63 "request_extended_authorization" => {
64 Deserialize::begin(&mut self.request_extended_authorization)
65 }
66 "request_incremental_authorization_support" => {
67 Deserialize::begin(&mut self.request_incremental_authorization_support)
68 }
69 "routing" => Deserialize::begin(&mut self.routing),
70 _ => <dyn Visitor>::ignore(),
71 })
72 }
73
74 fn deser_default() -> Self {
75 Self {
76 capture_method: Deserialize::default(),
77 request_extended_authorization: Deserialize::default(),
78 request_incremental_authorization_support: Deserialize::default(),
79 routing: Deserialize::default(),
80 }
81 }
82
83 fn take_out(&mut self) -> Option<Self::Out> {
84 let (
85 Some(capture_method),
86 Some(request_extended_authorization),
87 Some(request_incremental_authorization_support),
88 Some(routing),
89 ) = (
90 self.capture_method.take(),
91 self.request_extended_authorization,
92 self.request_incremental_authorization_support,
93 self.routing.take(),
94 )
95 else {
96 return None;
97 };
98 Some(Self::Out {
99 capture_method,
100 request_extended_authorization,
101 request_incremental_authorization_support,
102 routing,
103 })
104 }
105 }
106
107 impl Map for Builder<'_> {
108 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
109 self.builder.key(k)
110 }
111
112 fn finish(&mut self) -> Result<()> {
113 *self.out = self.builder.take_out();
114 Ok(())
115 }
116 }
117
118 impl ObjectDeser for PaymentMethodOptionsCardPresent {
119 type Builder = PaymentMethodOptionsCardPresentBuilder;
120 }
121
122 impl FromValueOpt for PaymentMethodOptionsCardPresent {
123 fn from_value(v: Value) -> Option<Self> {
124 let Value::Object(obj) = v else {
125 return None;
126 };
127 let mut b = PaymentMethodOptionsCardPresentBuilder::deser_default();
128 for (k, v) in obj {
129 match k.as_str() {
130 "capture_method" => b.capture_method = FromValueOpt::from_value(v),
131 "request_extended_authorization" => {
132 b.request_extended_authorization = FromValueOpt::from_value(v)
133 }
134 "request_incremental_authorization_support" => {
135 b.request_incremental_authorization_support = FromValueOpt::from_value(v)
136 }
137 "routing" => b.routing = FromValueOpt::from_value(v),
138 _ => {}
139 }
140 }
141 b.take_out()
142 }
143 }
144};
145#[derive(Clone, Eq, PartialEq)]
147#[non_exhaustive]
148pub enum PaymentMethodOptionsCardPresentCaptureMethod {
149 Manual,
150 ManualPreferred,
151 Unknown(String),
153}
154impl PaymentMethodOptionsCardPresentCaptureMethod {
155 pub fn as_str(&self) -> &str {
156 use PaymentMethodOptionsCardPresentCaptureMethod::*;
157 match self {
158 Manual => "manual",
159 ManualPreferred => "manual_preferred",
160 Unknown(v) => v,
161 }
162 }
163}
164
165impl std::str::FromStr for PaymentMethodOptionsCardPresentCaptureMethod {
166 type Err = std::convert::Infallible;
167 fn from_str(s: &str) -> Result<Self, Self::Err> {
168 use PaymentMethodOptionsCardPresentCaptureMethod::*;
169 match s {
170 "manual" => Ok(Manual),
171 "manual_preferred" => Ok(ManualPreferred),
172 v => {
173 tracing::warn!(
174 "Unknown value '{}' for enum '{}'",
175 v,
176 "PaymentMethodOptionsCardPresentCaptureMethod"
177 );
178 Ok(Unknown(v.to_owned()))
179 }
180 }
181 }
182}
183impl std::fmt::Display for PaymentMethodOptionsCardPresentCaptureMethod {
184 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185 f.write_str(self.as_str())
186 }
187}
188
189impl std::fmt::Debug for PaymentMethodOptionsCardPresentCaptureMethod {
190 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
191 f.write_str(self.as_str())
192 }
193}
194#[cfg(feature = "serialize")]
195impl serde::Serialize for PaymentMethodOptionsCardPresentCaptureMethod {
196 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
197 where
198 S: serde::Serializer,
199 {
200 serializer.serialize_str(self.as_str())
201 }
202}
203impl miniserde::Deserialize for PaymentMethodOptionsCardPresentCaptureMethod {
204 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
205 crate::Place::new(out)
206 }
207}
208
209impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardPresentCaptureMethod> {
210 fn string(&mut self, s: &str) -> miniserde::Result<()> {
211 use std::str::FromStr;
212 self.out =
213 Some(PaymentMethodOptionsCardPresentCaptureMethod::from_str(s).expect("infallible"));
214 Ok(())
215 }
216}
217
218stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardPresentCaptureMethod);
219#[cfg(feature = "deserialize")]
220impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardPresentCaptureMethod {
221 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
222 use std::str::FromStr;
223 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
224 Ok(Self::from_str(&s).expect("infallible"))
225 }
226}