Skip to main content

stripe_shared/
payment_method_options_us_bank_account_mandate_options.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentMethodOptionsUsBankAccountMandateOptions {
6    /// Mandate collection method
7    pub collection_method: Option<PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod>,
8}
9#[cfg(feature = "redact-generated-debug")]
10impl std::fmt::Debug for PaymentMethodOptionsUsBankAccountMandateOptions {
11    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
12        f.debug_struct("PaymentMethodOptionsUsBankAccountMandateOptions").finish_non_exhaustive()
13    }
14}
15#[doc(hidden)]
16pub struct PaymentMethodOptionsUsBankAccountMandateOptionsBuilder {
17    collection_method:
18        Option<Option<PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod>>,
19}
20
21#[allow(
22    unused_variables,
23    irrefutable_let_patterns,
24    clippy::let_unit_value,
25    clippy::match_single_binding,
26    clippy::single_match
27)]
28const _: () = {
29    use miniserde::de::{Map, Visitor};
30    use miniserde::json::Value;
31    use miniserde::{Deserialize, Result, make_place};
32    use stripe_types::miniserde_helpers::FromValueOpt;
33    use stripe_types::{MapBuilder, ObjectDeser};
34
35    make_place!(Place);
36
37    impl Deserialize for PaymentMethodOptionsUsBankAccountMandateOptions {
38        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39            Place::new(out)
40        }
41    }
42
43    struct Builder<'a> {
44        out: &'a mut Option<PaymentMethodOptionsUsBankAccountMandateOptions>,
45        builder: PaymentMethodOptionsUsBankAccountMandateOptionsBuilder,
46    }
47
48    impl Visitor for Place<PaymentMethodOptionsUsBankAccountMandateOptions> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: PaymentMethodOptionsUsBankAccountMandateOptionsBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for PaymentMethodOptionsUsBankAccountMandateOptionsBuilder {
58        type Out = PaymentMethodOptionsUsBankAccountMandateOptions;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "collection_method" => Deserialize::begin(&mut self.collection_method),
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self { collection_method: Some(None) }
68        }
69
70        fn take_out(&mut self) -> Option<Self::Out> {
71            let (Some(collection_method),) = (self.collection_method.take(),) else {
72                return None;
73            };
74            Some(Self::Out { collection_method })
75        }
76    }
77
78    impl Map for Builder<'_> {
79        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80            self.builder.key(k)
81        }
82
83        fn finish(&mut self) -> Result<()> {
84            *self.out = self.builder.take_out();
85            Ok(())
86        }
87    }
88
89    impl ObjectDeser for PaymentMethodOptionsUsBankAccountMandateOptions {
90        type Builder = PaymentMethodOptionsUsBankAccountMandateOptionsBuilder;
91    }
92
93    impl FromValueOpt for PaymentMethodOptionsUsBankAccountMandateOptions {
94        fn from_value(v: Value) -> Option<Self> {
95            let Value::Object(obj) = v else {
96                return None;
97            };
98            let mut b = PaymentMethodOptionsUsBankAccountMandateOptionsBuilder::deser_default();
99            for (k, v) in obj {
100                match k.as_str() {
101                    "collection_method" => b.collection_method = FromValueOpt::from_value(v),
102                    _ => {}
103                }
104            }
105            b.take_out()
106        }
107    }
108};
109/// Mandate collection method
110#[derive(Clone, Eq, PartialEq)]
111#[non_exhaustive]
112pub enum PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
113    Paper,
114    /// An unrecognized value from Stripe. Should not be used as a request parameter.
115    Unknown(String),
116}
117impl PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
118    pub fn as_str(&self) -> &str {
119        use PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod::*;
120        match self {
121            Paper => "paper",
122            Unknown(v) => v,
123        }
124    }
125}
126
127impl std::str::FromStr for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
128    type Err = std::convert::Infallible;
129    fn from_str(s: &str) -> Result<Self, Self::Err> {
130        use PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod::*;
131        match s {
132            "paper" => Ok(Paper),
133            v => {
134                tracing::warn!(
135                    "Unknown value '{}' for enum '{}'",
136                    v,
137                    "PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod"
138                );
139                Ok(Unknown(v.to_owned()))
140            }
141        }
142    }
143}
144impl std::fmt::Display for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
145    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
146        f.write_str(self.as_str())
147    }
148}
149
150#[cfg(not(feature = "redact-generated-debug"))]
151impl std::fmt::Debug for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156#[cfg(feature = "redact-generated-debug")]
157impl std::fmt::Debug for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
158    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159        f.debug_struct(stringify!(PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod))
160            .finish_non_exhaustive()
161    }
162}
163#[cfg(feature = "serialize")]
164impl serde::Serialize for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
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 PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod {
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<PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod>
180{
181    fn string(&mut self, s: &str) -> miniserde::Result<()> {
182        use std::str::FromStr;
183        self.out = Some(
184            PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod::from_str(s)
185                .expect("infallible"),
186        );
187        Ok(())
188    }
189}
190
191stripe_types::impl_from_val_with_from_str!(
192    PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod
193);
194#[cfg(feature = "deserialize")]
195impl<'de> serde::Deserialize<'de>
196    for PaymentMethodOptionsUsBankAccountMandateOptionsCollectionMethod
197{
198    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199        use std::str::FromStr;
200        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201        Ok(Self::from_str(&s).expect("infallible"))
202    }
203}