stripe_shared/
payment_method_options_us_bank_account_mandate_options.rs

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