stripe_shared/
payment_method_fpx.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodFpx {
5    /// Account holder type, if provided. Can be one of `individual` or `company`.
6    pub account_holder_type: Option<PaymentMethodFpxAccountHolderType>,
7    /// The customer's bank, if provided.
8    /// Can be one of `affin_bank`, `agrobank`, `alliance_bank`, `ambank`, `bank_islam`, `bank_muamalat`, `bank_rakyat`, `bsn`, `cimb`, `hong_leong_bank`, `hsbc`, `kfh`, `maybank2u`, `ocbc`, `public_bank`, `rhb`, `standard_chartered`, `uob`, `deutsche_bank`, `maybank2e`, `pb_enterprise`, or `bank_of_china`.
9    pub bank: PaymentMethodFpxBank,
10}
11#[doc(hidden)]
12pub struct PaymentMethodFpxBuilder {
13    account_holder_type: Option<Option<PaymentMethodFpxAccountHolderType>>,
14    bank: Option<PaymentMethodFpxBank>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{Deserialize, Result, make_place};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for PaymentMethodFpx {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<PaymentMethodFpx>,
41        builder: PaymentMethodFpxBuilder,
42    }
43
44    impl Visitor for Place<PaymentMethodFpx> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: PaymentMethodFpxBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for PaymentMethodFpxBuilder {
54        type Out = PaymentMethodFpx;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "account_holder_type" => Deserialize::begin(&mut self.account_holder_type),
58                "bank" => Deserialize::begin(&mut self.bank),
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { account_holder_type: Deserialize::default(), bank: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(account_holder_type), Some(bank)) =
69                (self.account_holder_type.take(), self.bank.take())
70            else {
71                return None;
72            };
73            Some(Self::Out { account_holder_type, bank })
74        }
75    }
76
77    impl Map for Builder<'_> {
78        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
79            self.builder.key(k)
80        }
81
82        fn finish(&mut self) -> Result<()> {
83            *self.out = self.builder.take_out();
84            Ok(())
85        }
86    }
87
88    impl ObjectDeser for PaymentMethodFpx {
89        type Builder = PaymentMethodFpxBuilder;
90    }
91
92    impl FromValueOpt for PaymentMethodFpx {
93        fn from_value(v: Value) -> Option<Self> {
94            let Value::Object(obj) = v else {
95                return None;
96            };
97            let mut b = PaymentMethodFpxBuilder::deser_default();
98            for (k, v) in obj {
99                match k.as_str() {
100                    "account_holder_type" => b.account_holder_type = FromValueOpt::from_value(v),
101                    "bank" => b.bank = FromValueOpt::from_value(v),
102                    _ => {}
103                }
104            }
105            b.take_out()
106        }
107    }
108};
109/// Account holder type, if provided. Can be one of `individual` or `company`.
110#[derive(Clone, Eq, PartialEq)]
111#[non_exhaustive]
112pub enum PaymentMethodFpxAccountHolderType {
113    Company,
114    Individual,
115    /// An unrecognized value from Stripe. Should not be used as a request parameter.
116    Unknown(String),
117}
118impl PaymentMethodFpxAccountHolderType {
119    pub fn as_str(&self) -> &str {
120        use PaymentMethodFpxAccountHolderType::*;
121        match self {
122            Company => "company",
123            Individual => "individual",
124            Unknown(v) => v,
125        }
126    }
127}
128
129impl std::str::FromStr for PaymentMethodFpxAccountHolderType {
130    type Err = std::convert::Infallible;
131    fn from_str(s: &str) -> Result<Self, Self::Err> {
132        use PaymentMethodFpxAccountHolderType::*;
133        match s {
134            "company" => Ok(Company),
135            "individual" => Ok(Individual),
136            v => {
137                tracing::warn!(
138                    "Unknown value '{}' for enum '{}'",
139                    v,
140                    "PaymentMethodFpxAccountHolderType"
141                );
142                Ok(Unknown(v.to_owned()))
143            }
144        }
145    }
146}
147impl std::fmt::Display for PaymentMethodFpxAccountHolderType {
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.write_str(self.as_str())
150    }
151}
152
153impl std::fmt::Debug for PaymentMethodFpxAccountHolderType {
154    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155        f.write_str(self.as_str())
156    }
157}
158#[cfg(feature = "serialize")]
159impl serde::Serialize for PaymentMethodFpxAccountHolderType {
160    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
161    where
162        S: serde::Serializer,
163    {
164        serializer.serialize_str(self.as_str())
165    }
166}
167impl miniserde::Deserialize for PaymentMethodFpxAccountHolderType {
168    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
169        crate::Place::new(out)
170    }
171}
172
173impl miniserde::de::Visitor for crate::Place<PaymentMethodFpxAccountHolderType> {
174    fn string(&mut self, s: &str) -> miniserde::Result<()> {
175        use std::str::FromStr;
176        self.out = Some(PaymentMethodFpxAccountHolderType::from_str(s).expect("infallible"));
177        Ok(())
178    }
179}
180
181stripe_types::impl_from_val_with_from_str!(PaymentMethodFpxAccountHolderType);
182#[cfg(feature = "deserialize")]
183impl<'de> serde::Deserialize<'de> for PaymentMethodFpxAccountHolderType {
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        Ok(Self::from_str(&s).expect("infallible"))
188    }
189}
190/// The customer's bank, if provided.
191/// Can be one of `affin_bank`, `agrobank`, `alliance_bank`, `ambank`, `bank_islam`, `bank_muamalat`, `bank_rakyat`, `bsn`, `cimb`, `hong_leong_bank`, `hsbc`, `kfh`, `maybank2u`, `ocbc`, `public_bank`, `rhb`, `standard_chartered`, `uob`, `deutsche_bank`, `maybank2e`, `pb_enterprise`, or `bank_of_china`.
192#[derive(Clone, Eq, PartialEq)]
193#[non_exhaustive]
194pub enum PaymentMethodFpxBank {
195    AffinBank,
196    Agrobank,
197    AllianceBank,
198    Ambank,
199    BankIslam,
200    BankMuamalat,
201    BankOfChina,
202    BankRakyat,
203    Bsn,
204    Cimb,
205    DeutscheBank,
206    HongLeongBank,
207    Hsbc,
208    Kfh,
209    Maybank2e,
210    Maybank2u,
211    Ocbc,
212    PbEnterprise,
213    PublicBank,
214    Rhb,
215    StandardChartered,
216    Uob,
217    /// An unrecognized value from Stripe. Should not be used as a request parameter.
218    Unknown(String),
219}
220impl PaymentMethodFpxBank {
221    pub fn as_str(&self) -> &str {
222        use PaymentMethodFpxBank::*;
223        match self {
224            AffinBank => "affin_bank",
225            Agrobank => "agrobank",
226            AllianceBank => "alliance_bank",
227            Ambank => "ambank",
228            BankIslam => "bank_islam",
229            BankMuamalat => "bank_muamalat",
230            BankOfChina => "bank_of_china",
231            BankRakyat => "bank_rakyat",
232            Bsn => "bsn",
233            Cimb => "cimb",
234            DeutscheBank => "deutsche_bank",
235            HongLeongBank => "hong_leong_bank",
236            Hsbc => "hsbc",
237            Kfh => "kfh",
238            Maybank2e => "maybank2e",
239            Maybank2u => "maybank2u",
240            Ocbc => "ocbc",
241            PbEnterprise => "pb_enterprise",
242            PublicBank => "public_bank",
243            Rhb => "rhb",
244            StandardChartered => "standard_chartered",
245            Uob => "uob",
246            Unknown(v) => v,
247        }
248    }
249}
250
251impl std::str::FromStr for PaymentMethodFpxBank {
252    type Err = std::convert::Infallible;
253    fn from_str(s: &str) -> Result<Self, Self::Err> {
254        use PaymentMethodFpxBank::*;
255        match s {
256            "affin_bank" => Ok(AffinBank),
257            "agrobank" => Ok(Agrobank),
258            "alliance_bank" => Ok(AllianceBank),
259            "ambank" => Ok(Ambank),
260            "bank_islam" => Ok(BankIslam),
261            "bank_muamalat" => Ok(BankMuamalat),
262            "bank_of_china" => Ok(BankOfChina),
263            "bank_rakyat" => Ok(BankRakyat),
264            "bsn" => Ok(Bsn),
265            "cimb" => Ok(Cimb),
266            "deutsche_bank" => Ok(DeutscheBank),
267            "hong_leong_bank" => Ok(HongLeongBank),
268            "hsbc" => Ok(Hsbc),
269            "kfh" => Ok(Kfh),
270            "maybank2e" => Ok(Maybank2e),
271            "maybank2u" => Ok(Maybank2u),
272            "ocbc" => Ok(Ocbc),
273            "pb_enterprise" => Ok(PbEnterprise),
274            "public_bank" => Ok(PublicBank),
275            "rhb" => Ok(Rhb),
276            "standard_chartered" => Ok(StandardChartered),
277            "uob" => Ok(Uob),
278            v => {
279                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PaymentMethodFpxBank");
280                Ok(Unknown(v.to_owned()))
281            }
282        }
283    }
284}
285impl std::fmt::Display for PaymentMethodFpxBank {
286    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
287        f.write_str(self.as_str())
288    }
289}
290
291impl std::fmt::Debug for PaymentMethodFpxBank {
292    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
293        f.write_str(self.as_str())
294    }
295}
296#[cfg(feature = "serialize")]
297impl serde::Serialize for PaymentMethodFpxBank {
298    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
299    where
300        S: serde::Serializer,
301    {
302        serializer.serialize_str(self.as_str())
303    }
304}
305impl miniserde::Deserialize for PaymentMethodFpxBank {
306    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
307        crate::Place::new(out)
308    }
309}
310
311impl miniserde::de::Visitor for crate::Place<PaymentMethodFpxBank> {
312    fn string(&mut self, s: &str) -> miniserde::Result<()> {
313        use std::str::FromStr;
314        self.out = Some(PaymentMethodFpxBank::from_str(s).expect("infallible"));
315        Ok(())
316    }
317}
318
319stripe_types::impl_from_val_with_from_str!(PaymentMethodFpxBank);
320#[cfg(feature = "deserialize")]
321impl<'de> serde::Deserialize<'de> for PaymentMethodFpxBank {
322    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
323        use std::str::FromStr;
324        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
325        Ok(Self::from_str(&s).expect("infallible"))
326    }
327}