stripe_shared/
payment_method_p24.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodP24 {
5    /// The customer's bank, if provided.
6    pub bank: Option<PaymentMethodP24Bank>,
7}
8#[doc(hidden)]
9pub struct PaymentMethodP24Builder {
10    bank: Option<Option<PaymentMethodP24Bank>>,
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 PaymentMethodP24 {
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<PaymentMethodP24>,
37        builder: PaymentMethodP24Builder,
38    }
39
40    impl Visitor for Place<PaymentMethodP24> {
41        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
42            Ok(Box::new(Builder {
43                out: &mut self.out,
44                builder: PaymentMethodP24Builder::deser_default(),
45            }))
46        }
47    }
48
49    impl MapBuilder for PaymentMethodP24Builder {
50        type Out = PaymentMethodP24;
51        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
52            Ok(match k {
53                "bank" => Deserialize::begin(&mut self.bank),
54                _ => <dyn Visitor>::ignore(),
55            })
56        }
57
58        fn deser_default() -> Self {
59            Self { bank: Deserialize::default() }
60        }
61
62        fn take_out(&mut self) -> Option<Self::Out> {
63            let (Some(bank),) = (self.bank.take(),) else {
64                return None;
65            };
66            Some(Self::Out { bank })
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 PaymentMethodP24 {
82        type Builder = PaymentMethodP24Builder;
83    }
84
85    impl FromValueOpt for PaymentMethodP24 {
86        fn from_value(v: Value) -> Option<Self> {
87            let Value::Object(obj) = v else {
88                return None;
89            };
90            let mut b = PaymentMethodP24Builder::deser_default();
91            for (k, v) in obj {
92                match k.as_str() {
93                    "bank" => b.bank = FromValueOpt::from_value(v),
94                    _ => {}
95                }
96            }
97            b.take_out()
98        }
99    }
100};
101/// The customer's bank, if provided.
102#[derive(Clone, Eq, PartialEq)]
103#[non_exhaustive]
104pub enum PaymentMethodP24Bank {
105    AliorBank,
106    BankMillennium,
107    BankNowyBfgSa,
108    BankPekaoSa,
109    BankiSpbdzielcze,
110    Blik,
111    BnpParibas,
112    Boz,
113    CitiHandlowy,
114    CreditAgricole,
115    Envelobank,
116    EtransferPocztowy24,
117    GetinBank,
118    Ideabank,
119    Ing,
120    Inteligo,
121    MbankMtransfer,
122    NestPrzelew,
123    NoblePay,
124    PbacZIpko,
125    PlusBank,
126    SantanderPrzelew24,
127    TmobileUsbugiBankowe,
128    ToyotaBank,
129    Velobank,
130    VolkswagenBank,
131    /// An unrecognized value from Stripe. Should not be used as a request parameter.
132    Unknown(String),
133}
134impl PaymentMethodP24Bank {
135    pub fn as_str(&self) -> &str {
136        use PaymentMethodP24Bank::*;
137        match self {
138            AliorBank => "alior_bank",
139            BankMillennium => "bank_millennium",
140            BankNowyBfgSa => "bank_nowy_bfg_sa",
141            BankPekaoSa => "bank_pekao_sa",
142            BankiSpbdzielcze => "banki_spbdzielcze",
143            Blik => "blik",
144            BnpParibas => "bnp_paribas",
145            Boz => "boz",
146            CitiHandlowy => "citi_handlowy",
147            CreditAgricole => "credit_agricole",
148            Envelobank => "envelobank",
149            EtransferPocztowy24 => "etransfer_pocztowy24",
150            GetinBank => "getin_bank",
151            Ideabank => "ideabank",
152            Ing => "ing",
153            Inteligo => "inteligo",
154            MbankMtransfer => "mbank_mtransfer",
155            NestPrzelew => "nest_przelew",
156            NoblePay => "noble_pay",
157            PbacZIpko => "pbac_z_ipko",
158            PlusBank => "plus_bank",
159            SantanderPrzelew24 => "santander_przelew24",
160            TmobileUsbugiBankowe => "tmobile_usbugi_bankowe",
161            ToyotaBank => "toyota_bank",
162            Velobank => "velobank",
163            VolkswagenBank => "volkswagen_bank",
164            Unknown(v) => v,
165        }
166    }
167}
168
169impl std::str::FromStr for PaymentMethodP24Bank {
170    type Err = std::convert::Infallible;
171    fn from_str(s: &str) -> Result<Self, Self::Err> {
172        use PaymentMethodP24Bank::*;
173        match s {
174            "alior_bank" => Ok(AliorBank),
175            "bank_millennium" => Ok(BankMillennium),
176            "bank_nowy_bfg_sa" => Ok(BankNowyBfgSa),
177            "bank_pekao_sa" => Ok(BankPekaoSa),
178            "banki_spbdzielcze" => Ok(BankiSpbdzielcze),
179            "blik" => Ok(Blik),
180            "bnp_paribas" => Ok(BnpParibas),
181            "boz" => Ok(Boz),
182            "citi_handlowy" => Ok(CitiHandlowy),
183            "credit_agricole" => Ok(CreditAgricole),
184            "envelobank" => Ok(Envelobank),
185            "etransfer_pocztowy24" => Ok(EtransferPocztowy24),
186            "getin_bank" => Ok(GetinBank),
187            "ideabank" => Ok(Ideabank),
188            "ing" => Ok(Ing),
189            "inteligo" => Ok(Inteligo),
190            "mbank_mtransfer" => Ok(MbankMtransfer),
191            "nest_przelew" => Ok(NestPrzelew),
192            "noble_pay" => Ok(NoblePay),
193            "pbac_z_ipko" => Ok(PbacZIpko),
194            "plus_bank" => Ok(PlusBank),
195            "santander_przelew24" => Ok(SantanderPrzelew24),
196            "tmobile_usbugi_bankowe" => Ok(TmobileUsbugiBankowe),
197            "toyota_bank" => Ok(ToyotaBank),
198            "velobank" => Ok(Velobank),
199            "volkswagen_bank" => Ok(VolkswagenBank),
200            v => {
201                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PaymentMethodP24Bank");
202                Ok(Unknown(v.to_owned()))
203            }
204        }
205    }
206}
207impl std::fmt::Display for PaymentMethodP24Bank {
208    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
209        f.write_str(self.as_str())
210    }
211}
212
213impl std::fmt::Debug for PaymentMethodP24Bank {
214    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
215        f.write_str(self.as_str())
216    }
217}
218#[cfg(feature = "serialize")]
219impl serde::Serialize for PaymentMethodP24Bank {
220    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
221    where
222        S: serde::Serializer,
223    {
224        serializer.serialize_str(self.as_str())
225    }
226}
227impl miniserde::Deserialize for PaymentMethodP24Bank {
228    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
229        crate::Place::new(out)
230    }
231}
232
233impl miniserde::de::Visitor for crate::Place<PaymentMethodP24Bank> {
234    fn string(&mut self, s: &str) -> miniserde::Result<()> {
235        use std::str::FromStr;
236        self.out = Some(PaymentMethodP24Bank::from_str(s).expect("infallible"));
237        Ok(())
238    }
239}
240
241stripe_types::impl_from_val_with_from_str!(PaymentMethodP24Bank);
242#[cfg(feature = "deserialize")]
243impl<'de> serde::Deserialize<'de> for PaymentMethodP24Bank {
244    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
245        use std::str::FromStr;
246        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
247        Ok(Self::from_str(&s).expect("infallible"))
248    }
249}