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