stripe_shared/
issuing_network_token_network_data.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct IssuingNetworkTokenNetworkData {
5    pub device: Option<stripe_shared::IssuingNetworkTokenDevice>,
6    pub mastercard: Option<stripe_shared::IssuingNetworkTokenMastercard>,
7    /// The network that the token is associated with.
8    /// An additional hash is included with a name matching this value, containing tokenization data specific to the card network.
9    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
10    pub type_: IssuingNetworkTokenNetworkDataType,
11    pub visa: Option<stripe_shared::IssuingNetworkTokenVisa>,
12    pub wallet_provider: Option<stripe_shared::IssuingNetworkTokenWalletProvider>,
13}
14#[doc(hidden)]
15pub struct IssuingNetworkTokenNetworkDataBuilder {
16    device: Option<Option<stripe_shared::IssuingNetworkTokenDevice>>,
17    mastercard: Option<Option<stripe_shared::IssuingNetworkTokenMastercard>>,
18    type_: Option<IssuingNetworkTokenNetworkDataType>,
19    visa: Option<Option<stripe_shared::IssuingNetworkTokenVisa>>,
20    wallet_provider: Option<Option<stripe_shared::IssuingNetworkTokenWalletProvider>>,
21}
22
23#[allow(
24    unused_variables,
25    irrefutable_let_patterns,
26    clippy::let_unit_value,
27    clippy::match_single_binding,
28    clippy::single_match
29)]
30const _: () = {
31    use miniserde::de::{Map, Visitor};
32    use miniserde::json::Value;
33    use miniserde::{Deserialize, Result, make_place};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for IssuingNetworkTokenNetworkData {
40        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41            Place::new(out)
42        }
43    }
44
45    struct Builder<'a> {
46        out: &'a mut Option<IssuingNetworkTokenNetworkData>,
47        builder: IssuingNetworkTokenNetworkDataBuilder,
48    }
49
50    impl Visitor for Place<IssuingNetworkTokenNetworkData> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: IssuingNetworkTokenNetworkDataBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for IssuingNetworkTokenNetworkDataBuilder {
60        type Out = IssuingNetworkTokenNetworkData;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "device" => Deserialize::begin(&mut self.device),
64                "mastercard" => Deserialize::begin(&mut self.mastercard),
65                "type" => Deserialize::begin(&mut self.type_),
66                "visa" => Deserialize::begin(&mut self.visa),
67                "wallet_provider" => Deserialize::begin(&mut self.wallet_provider),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self {
74                device: Deserialize::default(),
75                mastercard: Deserialize::default(),
76                type_: Deserialize::default(),
77                visa: Deserialize::default(),
78                wallet_provider: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (Some(device), Some(mastercard), Some(type_), Some(visa), Some(wallet_provider)) = (
84                self.device.take(),
85                self.mastercard.take(),
86                self.type_.take(),
87                self.visa.take(),
88                self.wallet_provider.take(),
89            ) else {
90                return None;
91            };
92            Some(Self::Out { device, mastercard, type_, visa, wallet_provider })
93        }
94    }
95
96    impl Map for Builder<'_> {
97        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
98            self.builder.key(k)
99        }
100
101        fn finish(&mut self) -> Result<()> {
102            *self.out = self.builder.take_out();
103            Ok(())
104        }
105    }
106
107    impl ObjectDeser for IssuingNetworkTokenNetworkData {
108        type Builder = IssuingNetworkTokenNetworkDataBuilder;
109    }
110
111    impl FromValueOpt for IssuingNetworkTokenNetworkData {
112        fn from_value(v: Value) -> Option<Self> {
113            let Value::Object(obj) = v else {
114                return None;
115            };
116            let mut b = IssuingNetworkTokenNetworkDataBuilder::deser_default();
117            for (k, v) in obj {
118                match k.as_str() {
119                    "device" => b.device = FromValueOpt::from_value(v),
120                    "mastercard" => b.mastercard = FromValueOpt::from_value(v),
121                    "type" => b.type_ = FromValueOpt::from_value(v),
122                    "visa" => b.visa = FromValueOpt::from_value(v),
123                    "wallet_provider" => b.wallet_provider = FromValueOpt::from_value(v),
124                    _ => {}
125                }
126            }
127            b.take_out()
128        }
129    }
130};
131/// The network that the token is associated with.
132/// An additional hash is included with a name matching this value, containing tokenization data specific to the card network.
133#[derive(Clone, Eq, PartialEq)]
134#[non_exhaustive]
135pub enum IssuingNetworkTokenNetworkDataType {
136    Mastercard,
137    Visa,
138    /// An unrecognized value from Stripe. Should not be used as a request parameter.
139    Unknown(String),
140}
141impl IssuingNetworkTokenNetworkDataType {
142    pub fn as_str(&self) -> &str {
143        use IssuingNetworkTokenNetworkDataType::*;
144        match self {
145            Mastercard => "mastercard",
146            Visa => "visa",
147            Unknown(v) => v,
148        }
149    }
150}
151
152impl std::str::FromStr for IssuingNetworkTokenNetworkDataType {
153    type Err = std::convert::Infallible;
154    fn from_str(s: &str) -> Result<Self, Self::Err> {
155        use IssuingNetworkTokenNetworkDataType::*;
156        match s {
157            "mastercard" => Ok(Mastercard),
158            "visa" => Ok(Visa),
159            v => {
160                tracing::warn!(
161                    "Unknown value '{}' for enum '{}'",
162                    v,
163                    "IssuingNetworkTokenNetworkDataType"
164                );
165                Ok(Unknown(v.to_owned()))
166            }
167        }
168    }
169}
170impl std::fmt::Display for IssuingNetworkTokenNetworkDataType {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175
176impl std::fmt::Debug for IssuingNetworkTokenNetworkDataType {
177    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178        f.write_str(self.as_str())
179    }
180}
181#[cfg(feature = "serialize")]
182impl serde::Serialize for IssuingNetworkTokenNetworkDataType {
183    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
184    where
185        S: serde::Serializer,
186    {
187        serializer.serialize_str(self.as_str())
188    }
189}
190impl miniserde::Deserialize for IssuingNetworkTokenNetworkDataType {
191    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
192        crate::Place::new(out)
193    }
194}
195
196impl miniserde::de::Visitor for crate::Place<IssuingNetworkTokenNetworkDataType> {
197    fn string(&mut self, s: &str) -> miniserde::Result<()> {
198        use std::str::FromStr;
199        self.out = Some(IssuingNetworkTokenNetworkDataType::from_str(s).expect("infallible"));
200        Ok(())
201    }
202}
203
204stripe_types::impl_from_val_with_from_str!(IssuingNetworkTokenNetworkDataType);
205#[cfg(feature = "deserialize")]
206impl<'de> serde::Deserialize<'de> for IssuingNetworkTokenNetworkDataType {
207    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
208        use std::str::FromStr;
209        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
210        Ok(Self::from_str(&s).expect("infallible"))
211    }
212}