1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct MandatePayto {
5 pub amount: Option<i64>,
7 pub amount_type: MandatePaytoAmountType,
11 pub end_date: Option<String>,
13 pub payment_schedule: MandatePaytoPaymentSchedule,
15 pub payments_per_period: Option<i64>,
19 pub purpose: Option<MandatePaytoPurpose>,
21 pub start_date: Option<String>,
23}
24#[doc(hidden)]
25pub struct MandatePaytoBuilder {
26 amount: Option<Option<i64>>,
27 amount_type: Option<MandatePaytoAmountType>,
28 end_date: Option<Option<String>>,
29 payment_schedule: Option<MandatePaytoPaymentSchedule>,
30 payments_per_period: Option<Option<i64>>,
31 purpose: Option<Option<MandatePaytoPurpose>>,
32 start_date: Option<Option<String>>,
33}
34
35#[allow(
36 unused_variables,
37 irrefutable_let_patterns,
38 clippy::let_unit_value,
39 clippy::match_single_binding,
40 clippy::single_match
41)]
42const _: () = {
43 use miniserde::de::{Map, Visitor};
44 use miniserde::json::Value;
45 use miniserde::{Deserialize, Result, make_place};
46 use stripe_types::miniserde_helpers::FromValueOpt;
47 use stripe_types::{MapBuilder, ObjectDeser};
48
49 make_place!(Place);
50
51 impl Deserialize for MandatePayto {
52 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
53 Place::new(out)
54 }
55 }
56
57 struct Builder<'a> {
58 out: &'a mut Option<MandatePayto>,
59 builder: MandatePaytoBuilder,
60 }
61
62 impl Visitor for Place<MandatePayto> {
63 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
64 Ok(Box::new(Builder {
65 out: &mut self.out,
66 builder: MandatePaytoBuilder::deser_default(),
67 }))
68 }
69 }
70
71 impl MapBuilder for MandatePaytoBuilder {
72 type Out = MandatePayto;
73 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
74 Ok(match k {
75 "amount" => Deserialize::begin(&mut self.amount),
76 "amount_type" => Deserialize::begin(&mut self.amount_type),
77 "end_date" => Deserialize::begin(&mut self.end_date),
78 "payment_schedule" => Deserialize::begin(&mut self.payment_schedule),
79 "payments_per_period" => Deserialize::begin(&mut self.payments_per_period),
80 "purpose" => Deserialize::begin(&mut self.purpose),
81 "start_date" => Deserialize::begin(&mut self.start_date),
82 _ => <dyn Visitor>::ignore(),
83 })
84 }
85
86 fn deser_default() -> Self {
87 Self {
88 amount: Deserialize::default(),
89 amount_type: Deserialize::default(),
90 end_date: Deserialize::default(),
91 payment_schedule: Deserialize::default(),
92 payments_per_period: Deserialize::default(),
93 purpose: Deserialize::default(),
94 start_date: Deserialize::default(),
95 }
96 }
97
98 fn take_out(&mut self) -> Option<Self::Out> {
99 let (
100 Some(amount),
101 Some(amount_type),
102 Some(end_date),
103 Some(payment_schedule),
104 Some(payments_per_period),
105 Some(purpose),
106 Some(start_date),
107 ) = (
108 self.amount,
109 self.amount_type.take(),
110 self.end_date.take(),
111 self.payment_schedule.take(),
112 self.payments_per_period,
113 self.purpose.take(),
114 self.start_date.take(),
115 )
116 else {
117 return None;
118 };
119 Some(Self::Out {
120 amount,
121 amount_type,
122 end_date,
123 payment_schedule,
124 payments_per_period,
125 purpose,
126 start_date,
127 })
128 }
129 }
130
131 impl Map for Builder<'_> {
132 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
133 self.builder.key(k)
134 }
135
136 fn finish(&mut self) -> Result<()> {
137 *self.out = self.builder.take_out();
138 Ok(())
139 }
140 }
141
142 impl ObjectDeser for MandatePayto {
143 type Builder = MandatePaytoBuilder;
144 }
145
146 impl FromValueOpt for MandatePayto {
147 fn from_value(v: Value) -> Option<Self> {
148 let Value::Object(obj) = v else {
149 return None;
150 };
151 let mut b = MandatePaytoBuilder::deser_default();
152 for (k, v) in obj {
153 match k.as_str() {
154 "amount" => b.amount = FromValueOpt::from_value(v),
155 "amount_type" => b.amount_type = FromValueOpt::from_value(v),
156 "end_date" => b.end_date = FromValueOpt::from_value(v),
157 "payment_schedule" => b.payment_schedule = FromValueOpt::from_value(v),
158 "payments_per_period" => b.payments_per_period = FromValueOpt::from_value(v),
159 "purpose" => b.purpose = FromValueOpt::from_value(v),
160 "start_date" => b.start_date = FromValueOpt::from_value(v),
161 _ => {}
162 }
163 }
164 b.take_out()
165 }
166 }
167};
168#[derive(Clone, Eq, PartialEq)]
172#[non_exhaustive]
173pub enum MandatePaytoAmountType {
174 Fixed,
175 Maximum,
176 Unknown(String),
178}
179impl MandatePaytoAmountType {
180 pub fn as_str(&self) -> &str {
181 use MandatePaytoAmountType::*;
182 match self {
183 Fixed => "fixed",
184 Maximum => "maximum",
185 Unknown(v) => v,
186 }
187 }
188}
189
190impl std::str::FromStr for MandatePaytoAmountType {
191 type Err = std::convert::Infallible;
192 fn from_str(s: &str) -> Result<Self, Self::Err> {
193 use MandatePaytoAmountType::*;
194 match s {
195 "fixed" => Ok(Fixed),
196 "maximum" => Ok(Maximum),
197 v => {
198 tracing::warn!("Unknown value '{}' for enum '{}'", v, "MandatePaytoAmountType");
199 Ok(Unknown(v.to_owned()))
200 }
201 }
202 }
203}
204impl std::fmt::Display for MandatePaytoAmountType {
205 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
206 f.write_str(self.as_str())
207 }
208}
209
210impl std::fmt::Debug for MandatePaytoAmountType {
211 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
212 f.write_str(self.as_str())
213 }
214}
215#[cfg(feature = "serialize")]
216impl serde::Serialize for MandatePaytoAmountType {
217 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
218 where
219 S: serde::Serializer,
220 {
221 serializer.serialize_str(self.as_str())
222 }
223}
224impl miniserde::Deserialize for MandatePaytoAmountType {
225 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
226 crate::Place::new(out)
227 }
228}
229
230impl miniserde::de::Visitor for crate::Place<MandatePaytoAmountType> {
231 fn string(&mut self, s: &str) -> miniserde::Result<()> {
232 use std::str::FromStr;
233 self.out = Some(MandatePaytoAmountType::from_str(s).expect("infallible"));
234 Ok(())
235 }
236}
237
238stripe_types::impl_from_val_with_from_str!(MandatePaytoAmountType);
239#[cfg(feature = "deserialize")]
240impl<'de> serde::Deserialize<'de> for MandatePaytoAmountType {
241 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
242 use std::str::FromStr;
243 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
244 Ok(Self::from_str(&s).expect("infallible"))
245 }
246}
247#[derive(Clone, Eq, PartialEq)]
249#[non_exhaustive]
250pub enum MandatePaytoPaymentSchedule {
251 Adhoc,
252 Annual,
253 Daily,
254 Fortnightly,
255 Monthly,
256 Quarterly,
257 SemiAnnual,
258 Weekly,
259 Unknown(String),
261}
262impl MandatePaytoPaymentSchedule {
263 pub fn as_str(&self) -> &str {
264 use MandatePaytoPaymentSchedule::*;
265 match self {
266 Adhoc => "adhoc",
267 Annual => "annual",
268 Daily => "daily",
269 Fortnightly => "fortnightly",
270 Monthly => "monthly",
271 Quarterly => "quarterly",
272 SemiAnnual => "semi_annual",
273 Weekly => "weekly",
274 Unknown(v) => v,
275 }
276 }
277}
278
279impl std::str::FromStr for MandatePaytoPaymentSchedule {
280 type Err = std::convert::Infallible;
281 fn from_str(s: &str) -> Result<Self, Self::Err> {
282 use MandatePaytoPaymentSchedule::*;
283 match s {
284 "adhoc" => Ok(Adhoc),
285 "annual" => Ok(Annual),
286 "daily" => Ok(Daily),
287 "fortnightly" => Ok(Fortnightly),
288 "monthly" => Ok(Monthly),
289 "quarterly" => Ok(Quarterly),
290 "semi_annual" => Ok(SemiAnnual),
291 "weekly" => Ok(Weekly),
292 v => {
293 tracing::warn!(
294 "Unknown value '{}' for enum '{}'",
295 v,
296 "MandatePaytoPaymentSchedule"
297 );
298 Ok(Unknown(v.to_owned()))
299 }
300 }
301 }
302}
303impl std::fmt::Display for MandatePaytoPaymentSchedule {
304 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
305 f.write_str(self.as_str())
306 }
307}
308
309impl std::fmt::Debug for MandatePaytoPaymentSchedule {
310 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
311 f.write_str(self.as_str())
312 }
313}
314#[cfg(feature = "serialize")]
315impl serde::Serialize for MandatePaytoPaymentSchedule {
316 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
317 where
318 S: serde::Serializer,
319 {
320 serializer.serialize_str(self.as_str())
321 }
322}
323impl miniserde::Deserialize for MandatePaytoPaymentSchedule {
324 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
325 crate::Place::new(out)
326 }
327}
328
329impl miniserde::de::Visitor for crate::Place<MandatePaytoPaymentSchedule> {
330 fn string(&mut self, s: &str) -> miniserde::Result<()> {
331 use std::str::FromStr;
332 self.out = Some(MandatePaytoPaymentSchedule::from_str(s).expect("infallible"));
333 Ok(())
334 }
335}
336
337stripe_types::impl_from_val_with_from_str!(MandatePaytoPaymentSchedule);
338#[cfg(feature = "deserialize")]
339impl<'de> serde::Deserialize<'de> for MandatePaytoPaymentSchedule {
340 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
341 use std::str::FromStr;
342 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
343 Ok(Self::from_str(&s).expect("infallible"))
344 }
345}
346#[derive(Clone, Eq, PartialEq)]
348#[non_exhaustive]
349pub enum MandatePaytoPurpose {
350 DependantSupport,
351 Government,
352 Loan,
353 Mortgage,
354 Other,
355 Pension,
356 Personal,
357 Retail,
358 Salary,
359 Tax,
360 Utility,
361 Unknown(String),
363}
364impl MandatePaytoPurpose {
365 pub fn as_str(&self) -> &str {
366 use MandatePaytoPurpose::*;
367 match self {
368 DependantSupport => "dependant_support",
369 Government => "government",
370 Loan => "loan",
371 Mortgage => "mortgage",
372 Other => "other",
373 Pension => "pension",
374 Personal => "personal",
375 Retail => "retail",
376 Salary => "salary",
377 Tax => "tax",
378 Utility => "utility",
379 Unknown(v) => v,
380 }
381 }
382}
383
384impl std::str::FromStr for MandatePaytoPurpose {
385 type Err = std::convert::Infallible;
386 fn from_str(s: &str) -> Result<Self, Self::Err> {
387 use MandatePaytoPurpose::*;
388 match s {
389 "dependant_support" => Ok(DependantSupport),
390 "government" => Ok(Government),
391 "loan" => Ok(Loan),
392 "mortgage" => Ok(Mortgage),
393 "other" => Ok(Other),
394 "pension" => Ok(Pension),
395 "personal" => Ok(Personal),
396 "retail" => Ok(Retail),
397 "salary" => Ok(Salary),
398 "tax" => Ok(Tax),
399 "utility" => Ok(Utility),
400 v => {
401 tracing::warn!("Unknown value '{}' for enum '{}'", v, "MandatePaytoPurpose");
402 Ok(Unknown(v.to_owned()))
403 }
404 }
405 }
406}
407impl std::fmt::Display for MandatePaytoPurpose {
408 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
409 f.write_str(self.as_str())
410 }
411}
412
413impl std::fmt::Debug for MandatePaytoPurpose {
414 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
415 f.write_str(self.as_str())
416 }
417}
418#[cfg(feature = "serialize")]
419impl serde::Serialize for MandatePaytoPurpose {
420 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
421 where
422 S: serde::Serializer,
423 {
424 serializer.serialize_str(self.as_str())
425 }
426}
427impl miniserde::Deserialize for MandatePaytoPurpose {
428 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
429 crate::Place::new(out)
430 }
431}
432
433impl miniserde::de::Visitor for crate::Place<MandatePaytoPurpose> {
434 fn string(&mut self, s: &str) -> miniserde::Result<()> {
435 use std::str::FromStr;
436 self.out = Some(MandatePaytoPurpose::from_str(s).expect("infallible"));
437 Ok(())
438 }
439}
440
441stripe_types::impl_from_val_with_from_str!(MandatePaytoPurpose);
442#[cfg(feature = "deserialize")]
443impl<'de> serde::Deserialize<'de> for MandatePaytoPurpose {
444 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
445 use std::str::FromStr;
446 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
447 Ok(Self::from_str(&s).expect("infallible"))
448 }
449}