stripe_shared/
payment_method_options_customer_balance_eu_bank_account.rs

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