stripe_shared/
invoice_payment_method_options_acss_debit_mandate_options.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct InvoicePaymentMethodOptionsAcssDebitMandateOptions {
5    /// Transaction type of the mandate.
6    pub transaction_type: Option<InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType>,
7}
8#[doc(hidden)]
9pub struct InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder {
10    transaction_type:
11        Option<Option<InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType>>,
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 InvoicePaymentMethodOptionsAcssDebitMandateOptions {
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<InvoicePaymentMethodOptionsAcssDebitMandateOptions>,
38        builder: InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder,
39    }
40
41    impl Visitor for Place<InvoicePaymentMethodOptionsAcssDebitMandateOptions> {
42        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
43            Ok(Box::new(Builder {
44                out: &mut self.out,
45                builder: InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder::deser_default(),
46            }))
47        }
48    }
49
50    impl MapBuilder for InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder {
51        type Out = InvoicePaymentMethodOptionsAcssDebitMandateOptions;
52        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
53            Ok(match k {
54                "transaction_type" => Deserialize::begin(&mut self.transaction_type),
55                _ => <dyn Visitor>::ignore(),
56            })
57        }
58
59        fn deser_default() -> Self {
60            Self { transaction_type: Deserialize::default() }
61        }
62
63        fn take_out(&mut self) -> Option<Self::Out> {
64            let (Some(transaction_type),) = (self.transaction_type.take(),) else {
65                return None;
66            };
67            Some(Self::Out { transaction_type })
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 InvoicePaymentMethodOptionsAcssDebitMandateOptions {
83        type Builder = InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder;
84    }
85
86    impl FromValueOpt for InvoicePaymentMethodOptionsAcssDebitMandateOptions {
87        fn from_value(v: Value) -> Option<Self> {
88            let Value::Object(obj) = v else {
89                return None;
90            };
91            let mut b = InvoicePaymentMethodOptionsAcssDebitMandateOptionsBuilder::deser_default();
92            for (k, v) in obj {
93                match k.as_str() {
94                    "transaction_type" => b.transaction_type = FromValueOpt::from_value(v),
95                    _ => {}
96                }
97            }
98            b.take_out()
99        }
100    }
101};
102/// Transaction type of the mandate.
103#[derive(Clone, Eq, PartialEq)]
104#[non_exhaustive]
105pub enum InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
106    Business,
107    Personal,
108    /// An unrecognized value from Stripe. Should not be used as a request parameter.
109    Unknown(String),
110}
111impl InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
112    pub fn as_str(&self) -> &str {
113        use InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::*;
114        match self {
115            Business => "business",
116            Personal => "personal",
117            Unknown(v) => v,
118        }
119    }
120}
121
122impl std::str::FromStr for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
123    type Err = std::convert::Infallible;
124    fn from_str(s: &str) -> Result<Self, Self::Err> {
125        use InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::*;
126        match s {
127            "business" => Ok(Business),
128            "personal" => Ok(Personal),
129            v => {
130                tracing::warn!(
131                    "Unknown value '{}' for enum '{}'",
132                    v,
133                    "InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType"
134                );
135                Ok(Unknown(v.to_owned()))
136            }
137        }
138    }
139}
140impl std::fmt::Display for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
141    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
142        f.write_str(self.as_str())
143    }
144}
145
146impl std::fmt::Debug for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
147    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148        f.write_str(self.as_str())
149    }
150}
151#[cfg(feature = "serialize")]
152impl serde::Serialize for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
153    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
154    where
155        S: serde::Serializer,
156    {
157        serializer.serialize_str(self.as_str())
158    }
159}
160impl miniserde::Deserialize for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
161    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
162        crate::Place::new(out)
163    }
164}
165
166impl miniserde::de::Visitor
167    for crate::Place<InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType>
168{
169    fn string(&mut self, s: &str) -> miniserde::Result<()> {
170        use std::str::FromStr;
171        self.out = Some(
172            InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::from_str(s)
173                .expect("infallible"),
174        );
175        Ok(())
176    }
177}
178
179stripe_types::impl_from_val_with_from_str!(
180    InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType
181);
182#[cfg(feature = "deserialize")]
183impl<'de> serde::Deserialize<'de>
184    for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType
185{
186    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
187        use std::str::FromStr;
188        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
189        Ok(Self::from_str(&s).expect("infallible"))
190    }
191}