stripe_shared/
invoice_payment_method_options_bancontact.rs

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