stripe_shared/
issuing_network_token_device.rs

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