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