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