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