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