stripe_shared/
invoice_payment_method_options_acss_debit.rs1#[derive(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::{Deserialize, Result, make_place};
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 _ => <dyn Visitor>::ignore(),
59 })
60 }
61
62 fn deser_default() -> Self {
63 Self {
64 mandate_options: Deserialize::default(),
65 verification_method: Deserialize::default(),
66 }
67 }
68
69 fn take_out(&mut self) -> Option<Self::Out> {
70 let (Some(mandate_options), Some(verification_method)) =
71 (self.mandate_options.take(), self.verification_method.take())
72 else {
73 return None;
74 };
75 Some(Self::Out { mandate_options, verification_method })
76 }
77 }
78
79 impl Map for Builder<'_> {
80 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81 self.builder.key(k)
82 }
83
84 fn finish(&mut self) -> Result<()> {
85 *self.out = self.builder.take_out();
86 Ok(())
87 }
88 }
89
90 impl ObjectDeser for InvoicePaymentMethodOptionsAcssDebit {
91 type Builder = InvoicePaymentMethodOptionsAcssDebitBuilder;
92 }
93
94 impl FromValueOpt for InvoicePaymentMethodOptionsAcssDebit {
95 fn from_value(v: Value) -> Option<Self> {
96 let Value::Object(obj) = v else {
97 return None;
98 };
99 let mut b = InvoicePaymentMethodOptionsAcssDebitBuilder::deser_default();
100 for (k, v) in obj {
101 match k.as_str() {
102 "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
103 "verification_method" => b.verification_method = FromValueOpt::from_value(v),
104 _ => {}
105 }
106 }
107 b.take_out()
108 }
109 }
110};
111#[derive(Clone, Eq, PartialEq)]
113#[non_exhaustive]
114pub enum InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
115 Automatic,
116 Instant,
117 Microdeposits,
118 Unknown(String),
120}
121impl InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
122 pub fn as_str(&self) -> &str {
123 use InvoicePaymentMethodOptionsAcssDebitVerificationMethod::*;
124 match self {
125 Automatic => "automatic",
126 Instant => "instant",
127 Microdeposits => "microdeposits",
128 Unknown(v) => v,
129 }
130 }
131}
132
133impl std::str::FromStr for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
134 type Err = std::convert::Infallible;
135 fn from_str(s: &str) -> Result<Self, Self::Err> {
136 use InvoicePaymentMethodOptionsAcssDebitVerificationMethod::*;
137 match s {
138 "automatic" => Ok(Automatic),
139 "instant" => Ok(Instant),
140 "microdeposits" => Ok(Microdeposits),
141 v => {
142 tracing::warn!(
143 "Unknown value '{}' for enum '{}'",
144 v,
145 "InvoicePaymentMethodOptionsAcssDebitVerificationMethod"
146 );
147 Ok(Unknown(v.to_owned()))
148 }
149 }
150 }
151}
152impl std::fmt::Display for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
153 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154 f.write_str(self.as_str())
155 }
156}
157
158impl std::fmt::Debug for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
159 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
160 f.write_str(self.as_str())
161 }
162}
163#[cfg(feature = "serialize")]
164impl serde::Serialize for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
165 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
166 where
167 S: serde::Serializer,
168 {
169 serializer.serialize_str(self.as_str())
170 }
171}
172impl miniserde::Deserialize for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
173 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
174 crate::Place::new(out)
175 }
176}
177
178impl miniserde::de::Visitor
179 for crate::Place<InvoicePaymentMethodOptionsAcssDebitVerificationMethod>
180{
181 fn string(&mut self, s: &str) -> miniserde::Result<()> {
182 use std::str::FromStr;
183 self.out = Some(
184 InvoicePaymentMethodOptionsAcssDebitVerificationMethod::from_str(s)
185 .expect("infallible"),
186 );
187 Ok(())
188 }
189}
190
191stripe_types::impl_from_val_with_from_str!(InvoicePaymentMethodOptionsAcssDebitVerificationMethod);
192#[cfg(feature = "deserialize")]
193impl<'de> serde::Deserialize<'de> for InvoicePaymentMethodOptionsAcssDebitVerificationMethod {
194 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
195 use std::str::FromStr;
196 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
197 Ok(Self::from_str(&s).expect("infallible"))
198 }
199}