1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoiceMandateOptionsPayto {
5 pub amount: Option<i64>,
8 pub amount_type: Option<InvoiceMandateOptionsPaytoAmountType>,
10 pub purpose: Option<InvoiceMandateOptionsPaytoPurpose>,
12}
13#[doc(hidden)]
14pub struct InvoiceMandateOptionsPaytoBuilder {
15 amount: Option<Option<i64>>,
16 amount_type: Option<Option<InvoiceMandateOptionsPaytoAmountType>>,
17 purpose: Option<Option<InvoiceMandateOptionsPaytoPurpose>>,
18}
19
20#[allow(
21 unused_variables,
22 irrefutable_let_patterns,
23 clippy::let_unit_value,
24 clippy::match_single_binding,
25 clippy::single_match
26)]
27const _: () = {
28 use miniserde::de::{Map, Visitor};
29 use miniserde::json::Value;
30 use miniserde::{Deserialize, Result, make_place};
31 use stripe_types::miniserde_helpers::FromValueOpt;
32 use stripe_types::{MapBuilder, ObjectDeser};
33
34 make_place!(Place);
35
36 impl Deserialize for InvoiceMandateOptionsPayto {
37 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
38 Place::new(out)
39 }
40 }
41
42 struct Builder<'a> {
43 out: &'a mut Option<InvoiceMandateOptionsPayto>,
44 builder: InvoiceMandateOptionsPaytoBuilder,
45 }
46
47 impl Visitor for Place<InvoiceMandateOptionsPayto> {
48 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
49 Ok(Box::new(Builder {
50 out: &mut self.out,
51 builder: InvoiceMandateOptionsPaytoBuilder::deser_default(),
52 }))
53 }
54 }
55
56 impl MapBuilder for InvoiceMandateOptionsPaytoBuilder {
57 type Out = InvoiceMandateOptionsPayto;
58 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
59 Ok(match k {
60 "amount" => Deserialize::begin(&mut self.amount),
61 "amount_type" => Deserialize::begin(&mut self.amount_type),
62 "purpose" => Deserialize::begin(&mut self.purpose),
63 _ => <dyn Visitor>::ignore(),
64 })
65 }
66
67 fn deser_default() -> Self {
68 Self {
69 amount: Deserialize::default(),
70 amount_type: Deserialize::default(),
71 purpose: Deserialize::default(),
72 }
73 }
74
75 fn take_out(&mut self) -> Option<Self::Out> {
76 let (Some(amount), Some(amount_type), Some(purpose)) =
77 (self.amount, self.amount_type.take(), self.purpose.take())
78 else {
79 return None;
80 };
81 Some(Self::Out { amount, amount_type, purpose })
82 }
83 }
84
85 impl Map for Builder<'_> {
86 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
87 self.builder.key(k)
88 }
89
90 fn finish(&mut self) -> Result<()> {
91 *self.out = self.builder.take_out();
92 Ok(())
93 }
94 }
95
96 impl ObjectDeser for InvoiceMandateOptionsPayto {
97 type Builder = InvoiceMandateOptionsPaytoBuilder;
98 }
99
100 impl FromValueOpt for InvoiceMandateOptionsPayto {
101 fn from_value(v: Value) -> Option<Self> {
102 let Value::Object(obj) = v else {
103 return None;
104 };
105 let mut b = InvoiceMandateOptionsPaytoBuilder::deser_default();
106 for (k, v) in obj {
107 match k.as_str() {
108 "amount" => b.amount = FromValueOpt::from_value(v),
109 "amount_type" => b.amount_type = FromValueOpt::from_value(v),
110 "purpose" => b.purpose = FromValueOpt::from_value(v),
111 _ => {}
112 }
113 }
114 b.take_out()
115 }
116 }
117};
118#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum InvoiceMandateOptionsPaytoAmountType {
122 Fixed,
123 Maximum,
124 Unknown(String),
126}
127impl InvoiceMandateOptionsPaytoAmountType {
128 pub fn as_str(&self) -> &str {
129 use InvoiceMandateOptionsPaytoAmountType::*;
130 match self {
131 Fixed => "fixed",
132 Maximum => "maximum",
133 Unknown(v) => v,
134 }
135 }
136}
137
138impl std::str::FromStr for InvoiceMandateOptionsPaytoAmountType {
139 type Err = std::convert::Infallible;
140 fn from_str(s: &str) -> Result<Self, Self::Err> {
141 use InvoiceMandateOptionsPaytoAmountType::*;
142 match s {
143 "fixed" => Ok(Fixed),
144 "maximum" => Ok(Maximum),
145 v => {
146 tracing::warn!(
147 "Unknown value '{}' for enum '{}'",
148 v,
149 "InvoiceMandateOptionsPaytoAmountType"
150 );
151 Ok(Unknown(v.to_owned()))
152 }
153 }
154 }
155}
156impl std::fmt::Display for InvoiceMandateOptionsPaytoAmountType {
157 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158 f.write_str(self.as_str())
159 }
160}
161
162impl std::fmt::Debug for InvoiceMandateOptionsPaytoAmountType {
163 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164 f.write_str(self.as_str())
165 }
166}
167#[cfg(feature = "serialize")]
168impl serde::Serialize for InvoiceMandateOptionsPaytoAmountType {
169 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
170 where
171 S: serde::Serializer,
172 {
173 serializer.serialize_str(self.as_str())
174 }
175}
176impl miniserde::Deserialize for InvoiceMandateOptionsPaytoAmountType {
177 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
178 crate::Place::new(out)
179 }
180}
181
182impl miniserde::de::Visitor for crate::Place<InvoiceMandateOptionsPaytoAmountType> {
183 fn string(&mut self, s: &str) -> miniserde::Result<()> {
184 use std::str::FromStr;
185 self.out = Some(InvoiceMandateOptionsPaytoAmountType::from_str(s).expect("infallible"));
186 Ok(())
187 }
188}
189
190stripe_types::impl_from_val_with_from_str!(InvoiceMandateOptionsPaytoAmountType);
191#[cfg(feature = "deserialize")]
192impl<'de> serde::Deserialize<'de> for InvoiceMandateOptionsPaytoAmountType {
193 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
194 use std::str::FromStr;
195 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
196 Ok(Self::from_str(&s).expect("infallible"))
197 }
198}
199#[derive(Clone, Eq, PartialEq)]
201#[non_exhaustive]
202pub enum InvoiceMandateOptionsPaytoPurpose {
203 DependantSupport,
204 Government,
205 Loan,
206 Mortgage,
207 Other,
208 Pension,
209 Personal,
210 Retail,
211 Salary,
212 Tax,
213 Utility,
214 Unknown(String),
216}
217impl InvoiceMandateOptionsPaytoPurpose {
218 pub fn as_str(&self) -> &str {
219 use InvoiceMandateOptionsPaytoPurpose::*;
220 match self {
221 DependantSupport => "dependant_support",
222 Government => "government",
223 Loan => "loan",
224 Mortgage => "mortgage",
225 Other => "other",
226 Pension => "pension",
227 Personal => "personal",
228 Retail => "retail",
229 Salary => "salary",
230 Tax => "tax",
231 Utility => "utility",
232 Unknown(v) => v,
233 }
234 }
235}
236
237impl std::str::FromStr for InvoiceMandateOptionsPaytoPurpose {
238 type Err = std::convert::Infallible;
239 fn from_str(s: &str) -> Result<Self, Self::Err> {
240 use InvoiceMandateOptionsPaytoPurpose::*;
241 match s {
242 "dependant_support" => Ok(DependantSupport),
243 "government" => Ok(Government),
244 "loan" => Ok(Loan),
245 "mortgage" => Ok(Mortgage),
246 "other" => Ok(Other),
247 "pension" => Ok(Pension),
248 "personal" => Ok(Personal),
249 "retail" => Ok(Retail),
250 "salary" => Ok(Salary),
251 "tax" => Ok(Tax),
252 "utility" => Ok(Utility),
253 v => {
254 tracing::warn!(
255 "Unknown value '{}' for enum '{}'",
256 v,
257 "InvoiceMandateOptionsPaytoPurpose"
258 );
259 Ok(Unknown(v.to_owned()))
260 }
261 }
262 }
263}
264impl std::fmt::Display for InvoiceMandateOptionsPaytoPurpose {
265 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
266 f.write_str(self.as_str())
267 }
268}
269
270impl std::fmt::Debug for InvoiceMandateOptionsPaytoPurpose {
271 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
272 f.write_str(self.as_str())
273 }
274}
275#[cfg(feature = "serialize")]
276impl serde::Serialize for InvoiceMandateOptionsPaytoPurpose {
277 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
278 where
279 S: serde::Serializer,
280 {
281 serializer.serialize_str(self.as_str())
282 }
283}
284impl miniserde::Deserialize for InvoiceMandateOptionsPaytoPurpose {
285 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
286 crate::Place::new(out)
287 }
288}
289
290impl miniserde::de::Visitor for crate::Place<InvoiceMandateOptionsPaytoPurpose> {
291 fn string(&mut self, s: &str) -> miniserde::Result<()> {
292 use std::str::FromStr;
293 self.out = Some(InvoiceMandateOptionsPaytoPurpose::from_str(s).expect("infallible"));
294 Ok(())
295 }
296}
297
298stripe_types::impl_from_val_with_from_str!(InvoiceMandateOptionsPaytoPurpose);
299#[cfg(feature = "deserialize")]
300impl<'de> serde::Deserialize<'de> for InvoiceMandateOptionsPaytoPurpose {
301 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
302 use std::str::FromStr;
303 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
304 Ok(Self::from_str(&s).expect("infallible"))
305 }
306}