stripe_shared/
invoice_payment_method_options_acss_debit_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 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,) 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(Copy, Clone, Eq, PartialEq)]
104pub enum InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
105    Business,
106    Personal,
107}
108impl InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
109    pub fn as_str(self) -> &'static str {
110        use InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::*;
111        match self {
112            Business => "business",
113            Personal => "personal",
114        }
115    }
116}
117
118impl std::str::FromStr for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
119    type Err = stripe_types::StripeParseError;
120    fn from_str(s: &str) -> Result<Self, Self::Err> {
121        use InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::*;
122        match s {
123            "business" => Ok(Business),
124            "personal" => Ok(Personal),
125            _ => Err(stripe_types::StripeParseError),
126        }
127    }
128}
129impl std::fmt::Display for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
130    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
131        f.write_str(self.as_str())
132    }
133}
134
135impl std::fmt::Debug for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
136    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
137        f.write_str(self.as_str())
138    }
139}
140#[cfg(feature = "serialize")]
141impl serde::Serialize for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
142    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
143    where
144        S: serde::Serializer,
145    {
146        serializer.serialize_str(self.as_str())
147    }
148}
149impl miniserde::Deserialize for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType {
150    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
151        crate::Place::new(out)
152    }
153}
154
155impl miniserde::de::Visitor
156    for crate::Place<InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType>
157{
158    fn string(&mut self, s: &str) -> miniserde::Result<()> {
159        use std::str::FromStr;
160        self.out = Some(
161            InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType::from_str(s)
162                .map_err(|_| miniserde::Error)?,
163        );
164        Ok(())
165    }
166}
167
168stripe_types::impl_from_val_with_from_str!(
169    InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType
170);
171#[cfg(feature = "deserialize")]
172impl<'de> serde::Deserialize<'de>
173    for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType
174{
175    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
176        use std::str::FromStr;
177        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
178        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for InvoicePaymentMethodOptionsAcssDebitMandateOptionsTransactionType"))
179    }
180}