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