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