Skip to main content

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