stripe_shared/
payment_intent_payment_method_options_bacs_debit.rs1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentPaymentMethodOptionsBacsDebit {
5 pub mandate_options:
6 Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsBacsDebit>,
7 pub setup_future_usage: Option<PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage>,
16 pub target_date: Option<String>,
20}
21#[doc(hidden)]
22pub struct PaymentIntentPaymentMethodOptionsBacsDebitBuilder {
23 mandate_options:
24 Option<Option<stripe_shared::PaymentIntentPaymentMethodOptionsMandateOptionsBacsDebit>>,
25 setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage>>,
26 target_date: Option<Option<String>>,
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 PaymentIntentPaymentMethodOptionsBacsDebit {
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<PaymentIntentPaymentMethodOptionsBacsDebit>,
53 builder: PaymentIntentPaymentMethodOptionsBacsDebitBuilder,
54 }
55
56 impl Visitor for Place<PaymentIntentPaymentMethodOptionsBacsDebit> {
57 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
58 Ok(Box::new(Builder {
59 out: &mut self.out,
60 builder: PaymentIntentPaymentMethodOptionsBacsDebitBuilder::deser_default(),
61 }))
62 }
63 }
64
65 impl MapBuilder for PaymentIntentPaymentMethodOptionsBacsDebitBuilder {
66 type Out = PaymentIntentPaymentMethodOptionsBacsDebit;
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 "target_date" => Deserialize::begin(&mut self.target_date),
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(),
87 self.setup_future_usage.take(),
88 self.target_date.take(),
89 ) else {
90 return None;
91 };
92 Some(Self::Out { mandate_options, setup_future_usage, target_date })
93 }
94 }
95
96 impl Map for Builder<'_> {
97 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
98 self.builder.key(k)
99 }
100
101 fn finish(&mut self) -> Result<()> {
102 *self.out = self.builder.take_out();
103 Ok(())
104 }
105 }
106
107 impl ObjectDeser for PaymentIntentPaymentMethodOptionsBacsDebit {
108 type Builder = PaymentIntentPaymentMethodOptionsBacsDebitBuilder;
109 }
110
111 impl FromValueOpt for PaymentIntentPaymentMethodOptionsBacsDebit {
112 fn from_value(v: Value) -> Option<Self> {
113 let Value::Object(obj) = v else {
114 return None;
115 };
116 let mut b = PaymentIntentPaymentMethodOptionsBacsDebitBuilder::deser_default();
117 for (k, v) in obj {
118 match k.as_str() {
119 "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
120 "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
121 "target_date" => b.target_date = FromValueOpt::from_value(v),
122 _ => {}
123 }
124 }
125 b.take_out()
126 }
127 }
128};
129#[derive(Clone, Eq, PartialEq)]
138#[non_exhaustive]
139pub enum PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
140 None,
141 OffSession,
142 OnSession,
143 Unknown(String),
145}
146impl PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
147 pub fn as_str(&self) -> &str {
148 use PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage::*;
149 match self {
150 None => "none",
151 OffSession => "off_session",
152 OnSession => "on_session",
153 Unknown(v) => v,
154 }
155 }
156}
157
158impl std::str::FromStr for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
159 type Err = std::convert::Infallible;
160 fn from_str(s: &str) -> Result<Self, Self::Err> {
161 use PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage::*;
162 match s {
163 "none" => Ok(None),
164 "off_session" => Ok(OffSession),
165 "on_session" => Ok(OnSession),
166 v => {
167 tracing::warn!(
168 "Unknown value '{}' for enum '{}'",
169 v,
170 "PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage"
171 );
172 Ok(Unknown(v.to_owned()))
173 }
174 }
175 }
176}
177impl std::fmt::Display for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
178 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
179 f.write_str(self.as_str())
180 }
181}
182
183impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
184 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185 f.write_str(self.as_str())
186 }
187}
188#[cfg(feature = "serialize")]
189impl serde::Serialize for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
190 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
191 where
192 S: serde::Serializer,
193 {
194 serializer.serialize_str(self.as_str())
195 }
196}
197impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
198 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
199 crate::Place::new(out)
200 }
201}
202
203impl miniserde::de::Visitor
204 for crate::Place<PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage>
205{
206 fn string(&mut self, s: &str) -> miniserde::Result<()> {
207 use std::str::FromStr;
208 self.out = Some(
209 PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage::from_str(s)
210 .expect("infallible"),
211 );
212 Ok(())
213 }
214}
215
216stripe_types::impl_from_val_with_from_str!(
217 PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage
218);
219#[cfg(feature = "deserialize")]
220impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsBacsDebitSetupFutureUsage {
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}