stripe_shared/
payment_method_details_sofort.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodDetailsSofort {
5    /// Bank code of bank associated with the bank account.
6    pub bank_code: Option<String>,
7    /// Name of the bank associated with the bank account.
8    pub bank_name: Option<String>,
9    /// Bank Identifier Code of the bank associated with the bank account.
10    pub bic: Option<String>,
11    /// Two-letter ISO code representing the country the bank account is located in.
12    pub country: Option<String>,
13    /// The ID of the SEPA Direct Debit PaymentMethod which was generated by this Charge.
14    pub generated_sepa_debit: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
15    /// The mandate for the SEPA Direct Debit PaymentMethod which was generated by this Charge.
16    pub generated_sepa_debit_mandate: Option<stripe_types::Expandable<stripe_shared::Mandate>>,
17    /// Last four characters of the IBAN.
18    pub iban_last4: Option<String>,
19    /// Preferred language of the SOFORT authorization page that the customer is redirected to.
20    /// Can be one of `de`, `en`, `es`, `fr`, `it`, `nl`, or `pl`
21    pub preferred_language: Option<PaymentMethodDetailsSofortPreferredLanguage>,
22    /// Owner's verified full name. Values are verified or provided by SOFORT directly
23    /// (if supported) at the time of authorization or settlement. They cannot be set or mutated.
24    pub verified_name: Option<String>,
25}
26#[doc(hidden)]
27pub struct PaymentMethodDetailsSofortBuilder {
28    bank_code: Option<Option<String>>,
29    bank_name: Option<Option<String>>,
30    bic: Option<Option<String>>,
31    country: Option<Option<String>>,
32    generated_sepa_debit: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
33    generated_sepa_debit_mandate: Option<Option<stripe_types::Expandable<stripe_shared::Mandate>>>,
34    iban_last4: Option<Option<String>>,
35    preferred_language: Option<Option<PaymentMethodDetailsSofortPreferredLanguage>>,
36    verified_name: Option<Option<String>>,
37}
38
39#[allow(
40    unused_variables,
41    irrefutable_let_patterns,
42    clippy::let_unit_value,
43    clippy::match_single_binding,
44    clippy::single_match
45)]
46const _: () = {
47    use miniserde::de::{Map, Visitor};
48    use miniserde::json::Value;
49    use miniserde::{Deserialize, Result, make_place};
50    use stripe_types::miniserde_helpers::FromValueOpt;
51    use stripe_types::{MapBuilder, ObjectDeser};
52
53    make_place!(Place);
54
55    impl Deserialize for PaymentMethodDetailsSofort {
56        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
57            Place::new(out)
58        }
59    }
60
61    struct Builder<'a> {
62        out: &'a mut Option<PaymentMethodDetailsSofort>,
63        builder: PaymentMethodDetailsSofortBuilder,
64    }
65
66    impl Visitor for Place<PaymentMethodDetailsSofort> {
67        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
68            Ok(Box::new(Builder {
69                out: &mut self.out,
70                builder: PaymentMethodDetailsSofortBuilder::deser_default(),
71            }))
72        }
73    }
74
75    impl MapBuilder for PaymentMethodDetailsSofortBuilder {
76        type Out = PaymentMethodDetailsSofort;
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            Ok(match k {
79                "bank_code" => Deserialize::begin(&mut self.bank_code),
80                "bank_name" => Deserialize::begin(&mut self.bank_name),
81                "bic" => Deserialize::begin(&mut self.bic),
82                "country" => Deserialize::begin(&mut self.country),
83                "generated_sepa_debit" => Deserialize::begin(&mut self.generated_sepa_debit),
84                "generated_sepa_debit_mandate" => {
85                    Deserialize::begin(&mut self.generated_sepa_debit_mandate)
86                }
87                "iban_last4" => Deserialize::begin(&mut self.iban_last4),
88                "preferred_language" => Deserialize::begin(&mut self.preferred_language),
89                "verified_name" => Deserialize::begin(&mut self.verified_name),
90                _ => <dyn Visitor>::ignore(),
91            })
92        }
93
94        fn deser_default() -> Self {
95            Self {
96                bank_code: Deserialize::default(),
97                bank_name: Deserialize::default(),
98                bic: Deserialize::default(),
99                country: Deserialize::default(),
100                generated_sepa_debit: Deserialize::default(),
101                generated_sepa_debit_mandate: Deserialize::default(),
102                iban_last4: Deserialize::default(),
103                preferred_language: Deserialize::default(),
104                verified_name: Deserialize::default(),
105            }
106        }
107
108        fn take_out(&mut self) -> Option<Self::Out> {
109            let (
110                Some(bank_code),
111                Some(bank_name),
112                Some(bic),
113                Some(country),
114                Some(generated_sepa_debit),
115                Some(generated_sepa_debit_mandate),
116                Some(iban_last4),
117                Some(preferred_language),
118                Some(verified_name),
119            ) = (
120                self.bank_code.take(),
121                self.bank_name.take(),
122                self.bic.take(),
123                self.country.take(),
124                self.generated_sepa_debit.take(),
125                self.generated_sepa_debit_mandate.take(),
126                self.iban_last4.take(),
127                self.preferred_language.take(),
128                self.verified_name.take(),
129            )
130            else {
131                return None;
132            };
133            Some(Self::Out {
134                bank_code,
135                bank_name,
136                bic,
137                country,
138                generated_sepa_debit,
139                generated_sepa_debit_mandate,
140                iban_last4,
141                preferred_language,
142                verified_name,
143            })
144        }
145    }
146
147    impl Map for Builder<'_> {
148        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
149            self.builder.key(k)
150        }
151
152        fn finish(&mut self) -> Result<()> {
153            *self.out = self.builder.take_out();
154            Ok(())
155        }
156    }
157
158    impl ObjectDeser for PaymentMethodDetailsSofort {
159        type Builder = PaymentMethodDetailsSofortBuilder;
160    }
161
162    impl FromValueOpt for PaymentMethodDetailsSofort {
163        fn from_value(v: Value) -> Option<Self> {
164            let Value::Object(obj) = v else {
165                return None;
166            };
167            let mut b = PaymentMethodDetailsSofortBuilder::deser_default();
168            for (k, v) in obj {
169                match k.as_str() {
170                    "bank_code" => b.bank_code = FromValueOpt::from_value(v),
171                    "bank_name" => b.bank_name = FromValueOpt::from_value(v),
172                    "bic" => b.bic = FromValueOpt::from_value(v),
173                    "country" => b.country = FromValueOpt::from_value(v),
174                    "generated_sepa_debit" => b.generated_sepa_debit = FromValueOpt::from_value(v),
175                    "generated_sepa_debit_mandate" => {
176                        b.generated_sepa_debit_mandate = FromValueOpt::from_value(v)
177                    }
178                    "iban_last4" => b.iban_last4 = FromValueOpt::from_value(v),
179                    "preferred_language" => b.preferred_language = FromValueOpt::from_value(v),
180                    "verified_name" => b.verified_name = FromValueOpt::from_value(v),
181                    _ => {}
182                }
183            }
184            b.take_out()
185        }
186    }
187};
188/// Preferred language of the SOFORT authorization page that the customer is redirected to.
189/// Can be one of `de`, `en`, `es`, `fr`, `it`, `nl`, or `pl`
190#[derive(Clone, Eq, PartialEq)]
191#[non_exhaustive]
192pub enum PaymentMethodDetailsSofortPreferredLanguage {
193    De,
194    En,
195    Es,
196    Fr,
197    It,
198    Nl,
199    Pl,
200    /// An unrecognized value from Stripe. Should not be used as a request parameter.
201    Unknown(String),
202}
203impl PaymentMethodDetailsSofortPreferredLanguage {
204    pub fn as_str(&self) -> &str {
205        use PaymentMethodDetailsSofortPreferredLanguage::*;
206        match self {
207            De => "de",
208            En => "en",
209            Es => "es",
210            Fr => "fr",
211            It => "it",
212            Nl => "nl",
213            Pl => "pl",
214            Unknown(v) => v,
215        }
216    }
217}
218
219impl std::str::FromStr for PaymentMethodDetailsSofortPreferredLanguage {
220    type Err = std::convert::Infallible;
221    fn from_str(s: &str) -> Result<Self, Self::Err> {
222        use PaymentMethodDetailsSofortPreferredLanguage::*;
223        match s {
224            "de" => Ok(De),
225            "en" => Ok(En),
226            "es" => Ok(Es),
227            "fr" => Ok(Fr),
228            "it" => Ok(It),
229            "nl" => Ok(Nl),
230            "pl" => Ok(Pl),
231            v => {
232                tracing::warn!(
233                    "Unknown value '{}' for enum '{}'",
234                    v,
235                    "PaymentMethodDetailsSofortPreferredLanguage"
236                );
237                Ok(Unknown(v.to_owned()))
238            }
239        }
240    }
241}
242impl std::fmt::Display for PaymentMethodDetailsSofortPreferredLanguage {
243    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
244        f.write_str(self.as_str())
245    }
246}
247
248impl std::fmt::Debug for PaymentMethodDetailsSofortPreferredLanguage {
249    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250        f.write_str(self.as_str())
251    }
252}
253#[cfg(feature = "serialize")]
254impl serde::Serialize for PaymentMethodDetailsSofortPreferredLanguage {
255    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
256    where
257        S: serde::Serializer,
258    {
259        serializer.serialize_str(self.as_str())
260    }
261}
262impl miniserde::Deserialize for PaymentMethodDetailsSofortPreferredLanguage {
263    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
264        crate::Place::new(out)
265    }
266}
267
268impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsSofortPreferredLanguage> {
269    fn string(&mut self, s: &str) -> miniserde::Result<()> {
270        use std::str::FromStr;
271        self.out =
272            Some(PaymentMethodDetailsSofortPreferredLanguage::from_str(s).expect("infallible"));
273        Ok(())
274    }
275}
276
277stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsSofortPreferredLanguage);
278#[cfg(feature = "deserialize")]
279impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsSofortPreferredLanguage {
280    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
281        use std::str::FromStr;
282        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
283        Ok(Self::from_str(&s).expect("infallible"))
284    }
285}