stripe_shared/
payment_method_naver_pay.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodNaverPay {
5    /// Uniquely identifies this particular Naver Pay account.
6    /// You can use this attribute to check whether two Naver Pay accounts are the same.
7    pub buyer_id: Option<String>,
8    /// Whether to fund this transaction with Naver Pay points or a card.
9    pub funding: PaymentMethodNaverPayFunding,
10}
11#[doc(hidden)]
12pub struct PaymentMethodNaverPayBuilder {
13    buyer_id: Option<Option<String>>,
14    funding: Option<PaymentMethodNaverPayFunding>,
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 PaymentMethodNaverPay {
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<PaymentMethodNaverPay>,
41        builder: PaymentMethodNaverPayBuilder,
42    }
43
44    impl Visitor for Place<PaymentMethodNaverPay> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: PaymentMethodNaverPayBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for PaymentMethodNaverPayBuilder {
54        type Out = PaymentMethodNaverPay;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "buyer_id" => Deserialize::begin(&mut self.buyer_id),
58                "funding" => Deserialize::begin(&mut self.funding),
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { buyer_id: Deserialize::default(), funding: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(buyer_id), Some(funding)) = (self.buyer_id.take(), self.funding.take())
69            else {
70                return None;
71            };
72            Some(Self::Out { buyer_id, funding })
73        }
74    }
75
76    impl Map for Builder<'_> {
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            self.builder.key(k)
79        }
80
81        fn finish(&mut self) -> Result<()> {
82            *self.out = self.builder.take_out();
83            Ok(())
84        }
85    }
86
87    impl ObjectDeser for PaymentMethodNaverPay {
88        type Builder = PaymentMethodNaverPayBuilder;
89    }
90
91    impl FromValueOpt for PaymentMethodNaverPay {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = PaymentMethodNaverPayBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "buyer_id" => b.buyer_id = FromValueOpt::from_value(v),
100                    "funding" => b.funding = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// Whether to fund this transaction with Naver Pay points or a card.
109#[derive(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum PaymentMethodNaverPayFunding {
112    Card,
113    Points,
114    /// An unrecognized value from Stripe. Should not be used as a request parameter.
115    Unknown(String),
116}
117impl PaymentMethodNaverPayFunding {
118    pub fn as_str(&self) -> &str {
119        use PaymentMethodNaverPayFunding::*;
120        match self {
121            Card => "card",
122            Points => "points",
123            Unknown(v) => v,
124        }
125    }
126}
127
128impl std::str::FromStr for PaymentMethodNaverPayFunding {
129    type Err = std::convert::Infallible;
130    fn from_str(s: &str) -> Result<Self, Self::Err> {
131        use PaymentMethodNaverPayFunding::*;
132        match s {
133            "card" => Ok(Card),
134            "points" => Ok(Points),
135            v => {
136                tracing::warn!(
137                    "Unknown value '{}' for enum '{}'",
138                    v,
139                    "PaymentMethodNaverPayFunding"
140                );
141                Ok(Unknown(v.to_owned()))
142            }
143        }
144    }
145}
146impl std::fmt::Display for PaymentMethodNaverPayFunding {
147    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148        f.write_str(self.as_str())
149    }
150}
151
152impl std::fmt::Debug for PaymentMethodNaverPayFunding {
153    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154        f.write_str(self.as_str())
155    }
156}
157#[cfg(feature = "serialize")]
158impl serde::Serialize for PaymentMethodNaverPayFunding {
159    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
160    where
161        S: serde::Serializer,
162    {
163        serializer.serialize_str(self.as_str())
164    }
165}
166impl miniserde::Deserialize for PaymentMethodNaverPayFunding {
167    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
168        crate::Place::new(out)
169    }
170}
171
172impl miniserde::de::Visitor for crate::Place<PaymentMethodNaverPayFunding> {
173    fn string(&mut self, s: &str) -> miniserde::Result<()> {
174        use std::str::FromStr;
175        self.out = Some(PaymentMethodNaverPayFunding::from_str(s).expect("infallible"));
176        Ok(())
177    }
178}
179
180stripe_types::impl_from_val_with_from_str!(PaymentMethodNaverPayFunding);
181#[cfg(feature = "deserialize")]
182impl<'de> serde::Deserialize<'de> for PaymentMethodNaverPayFunding {
183    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
184        use std::str::FromStr;
185        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
186        Ok(Self::from_str(&s).expect("infallible"))
187    }
188}