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