stripe_shared/
payment_method_kr_card.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodKrCard {
5    /// The local credit or debit card brand.
6    pub brand: Option<PaymentMethodKrCardBrand>,
7    /// The last four digits of the card. This may not be present for American Express cards.
8    pub last4: Option<String>,
9}
10#[doc(hidden)]
11pub struct PaymentMethodKrCardBuilder {
12    brand: Option<Option<PaymentMethodKrCardBrand>>,
13    last4: Option<Option<String>>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for PaymentMethodKrCard {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<PaymentMethodKrCard>,
40        builder: PaymentMethodKrCardBuilder,
41    }
42
43    impl Visitor for Place<PaymentMethodKrCard> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: PaymentMethodKrCardBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for PaymentMethodKrCardBuilder {
53        type Out = PaymentMethodKrCard;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "brand" => Deserialize::begin(&mut self.brand),
57                "last4" => Deserialize::begin(&mut self.last4),
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { brand: Deserialize::default(), last4: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(brand), Some(last4)) = (self.brand.take(), self.last4.take()) else {
68                return None;
69            };
70            Some(Self::Out { brand, last4 })
71        }
72    }
73
74    impl Map for Builder<'_> {
75        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
76            self.builder.key(k)
77        }
78
79        fn finish(&mut self) -> Result<()> {
80            *self.out = self.builder.take_out();
81            Ok(())
82        }
83    }
84
85    impl ObjectDeser for PaymentMethodKrCard {
86        type Builder = PaymentMethodKrCardBuilder;
87    }
88
89    impl FromValueOpt for PaymentMethodKrCard {
90        fn from_value(v: Value) -> Option<Self> {
91            let Value::Object(obj) = v else {
92                return None;
93            };
94            let mut b = PaymentMethodKrCardBuilder::deser_default();
95            for (k, v) in obj {
96                match k.as_str() {
97                    "brand" => b.brand = FromValueOpt::from_value(v),
98                    "last4" => b.last4 = FromValueOpt::from_value(v),
99                    _ => {}
100                }
101            }
102            b.take_out()
103        }
104    }
105};
106/// The local credit or debit card brand.
107#[derive(Clone, Eq, PartialEq)]
108#[non_exhaustive]
109pub enum PaymentMethodKrCardBrand {
110    Bc,
111    Citi,
112    Hana,
113    Hyundai,
114    Jeju,
115    Jeonbuk,
116    Kakaobank,
117    Kbank,
118    Kdbbank,
119    Kookmin,
120    Kwangju,
121    Lotte,
122    Mg,
123    Nh,
124    Post,
125    Samsung,
126    Savingsbank,
127    Shinhan,
128    Shinhyup,
129    Suhyup,
130    Tossbank,
131    Woori,
132    /// An unrecognized value from Stripe. Should not be used as a request parameter.
133    Unknown(String),
134}
135impl PaymentMethodKrCardBrand {
136    pub fn as_str(&self) -> &str {
137        use PaymentMethodKrCardBrand::*;
138        match self {
139            Bc => "bc",
140            Citi => "citi",
141            Hana => "hana",
142            Hyundai => "hyundai",
143            Jeju => "jeju",
144            Jeonbuk => "jeonbuk",
145            Kakaobank => "kakaobank",
146            Kbank => "kbank",
147            Kdbbank => "kdbbank",
148            Kookmin => "kookmin",
149            Kwangju => "kwangju",
150            Lotte => "lotte",
151            Mg => "mg",
152            Nh => "nh",
153            Post => "post",
154            Samsung => "samsung",
155            Savingsbank => "savingsbank",
156            Shinhan => "shinhan",
157            Shinhyup => "shinhyup",
158            Suhyup => "suhyup",
159            Tossbank => "tossbank",
160            Woori => "woori",
161            Unknown(v) => v,
162        }
163    }
164}
165
166impl std::str::FromStr for PaymentMethodKrCardBrand {
167    type Err = std::convert::Infallible;
168    fn from_str(s: &str) -> Result<Self, Self::Err> {
169        use PaymentMethodKrCardBrand::*;
170        match s {
171            "bc" => Ok(Bc),
172            "citi" => Ok(Citi),
173            "hana" => Ok(Hana),
174            "hyundai" => Ok(Hyundai),
175            "jeju" => Ok(Jeju),
176            "jeonbuk" => Ok(Jeonbuk),
177            "kakaobank" => Ok(Kakaobank),
178            "kbank" => Ok(Kbank),
179            "kdbbank" => Ok(Kdbbank),
180            "kookmin" => Ok(Kookmin),
181            "kwangju" => Ok(Kwangju),
182            "lotte" => Ok(Lotte),
183            "mg" => Ok(Mg),
184            "nh" => Ok(Nh),
185            "post" => Ok(Post),
186            "samsung" => Ok(Samsung),
187            "savingsbank" => Ok(Savingsbank),
188            "shinhan" => Ok(Shinhan),
189            "shinhyup" => Ok(Shinhyup),
190            "suhyup" => Ok(Suhyup),
191            "tossbank" => Ok(Tossbank),
192            "woori" => Ok(Woori),
193            v => {
194                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PaymentMethodKrCardBrand");
195                Ok(Unknown(v.to_owned()))
196            }
197        }
198    }
199}
200impl std::fmt::Display for PaymentMethodKrCardBrand {
201    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
202        f.write_str(self.as_str())
203    }
204}
205
206impl std::fmt::Debug for PaymentMethodKrCardBrand {
207    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
208        f.write_str(self.as_str())
209    }
210}
211#[cfg(feature = "serialize")]
212impl serde::Serialize for PaymentMethodKrCardBrand {
213    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
214    where
215        S: serde::Serializer,
216    {
217        serializer.serialize_str(self.as_str())
218    }
219}
220impl miniserde::Deserialize for PaymentMethodKrCardBrand {
221    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
222        crate::Place::new(out)
223    }
224}
225
226impl miniserde::de::Visitor for crate::Place<PaymentMethodKrCardBrand> {
227    fn string(&mut self, s: &str) -> miniserde::Result<()> {
228        use std::str::FromStr;
229        self.out = Some(PaymentMethodKrCardBrand::from_str(s).expect("infallible"));
230        Ok(())
231    }
232}
233
234stripe_types::impl_from_val_with_from_str!(PaymentMethodKrCardBrand);
235#[cfg(feature = "deserialize")]
236impl<'de> serde::Deserialize<'de> for PaymentMethodKrCardBrand {
237    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
238        use std::str::FromStr;
239        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
240        Ok(Self::from_str(&s).expect("infallible"))
241    }
242}