stripe_misc/tax_registration/
types.rs1#[derive(Clone, Debug)]
8#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
9pub struct TaxRegistration {
10 pub active_from: stripe_types::Timestamp,
12 pub country: String,
14 pub country_options: stripe_misc::TaxProductRegistrationsResourceCountryOptions,
15 pub created: stripe_types::Timestamp,
17 pub expires_at: Option<stripe_types::Timestamp>,
21 pub id: stripe_misc::TaxRegistrationId,
23 pub livemode: bool,
25 pub status: TaxRegistrationStatus,
28}
29#[doc(hidden)]
30pub struct TaxRegistrationBuilder {
31 active_from: Option<stripe_types::Timestamp>,
32 country: Option<String>,
33 country_options: Option<stripe_misc::TaxProductRegistrationsResourceCountryOptions>,
34 created: Option<stripe_types::Timestamp>,
35 expires_at: Option<Option<stripe_types::Timestamp>>,
36 id: Option<stripe_misc::TaxRegistrationId>,
37 livemode: Option<bool>,
38 status: Option<TaxRegistrationStatus>,
39}
40
41#[allow(
42 unused_variables,
43 irrefutable_let_patterns,
44 clippy::let_unit_value,
45 clippy::match_single_binding,
46 clippy::single_match
47)]
48const _: () = {
49 use miniserde::de::{Map, Visitor};
50 use miniserde::json::Value;
51 use miniserde::{Deserialize, Result, make_place};
52 use stripe_types::miniserde_helpers::FromValueOpt;
53 use stripe_types::{MapBuilder, ObjectDeser};
54
55 make_place!(Place);
56
57 impl Deserialize for TaxRegistration {
58 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
59 Place::new(out)
60 }
61 }
62
63 struct Builder<'a> {
64 out: &'a mut Option<TaxRegistration>,
65 builder: TaxRegistrationBuilder,
66 }
67
68 impl Visitor for Place<TaxRegistration> {
69 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
70 Ok(Box::new(Builder {
71 out: &mut self.out,
72 builder: TaxRegistrationBuilder::deser_default(),
73 }))
74 }
75 }
76
77 impl MapBuilder for TaxRegistrationBuilder {
78 type Out = TaxRegistration;
79 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80 Ok(match k {
81 "active_from" => Deserialize::begin(&mut self.active_from),
82 "country" => Deserialize::begin(&mut self.country),
83 "country_options" => Deserialize::begin(&mut self.country_options),
84 "created" => Deserialize::begin(&mut self.created),
85 "expires_at" => Deserialize::begin(&mut self.expires_at),
86 "id" => Deserialize::begin(&mut self.id),
87 "livemode" => Deserialize::begin(&mut self.livemode),
88 "status" => Deserialize::begin(&mut self.status),
89 _ => <dyn Visitor>::ignore(),
90 })
91 }
92
93 fn deser_default() -> Self {
94 Self {
95 active_from: Deserialize::default(),
96 country: Deserialize::default(),
97 country_options: Deserialize::default(),
98 created: Deserialize::default(),
99 expires_at: Deserialize::default(),
100 id: Deserialize::default(),
101 livemode: Deserialize::default(),
102 status: Deserialize::default(),
103 }
104 }
105
106 fn take_out(&mut self) -> Option<Self::Out> {
107 let (
108 Some(active_from),
109 Some(country),
110 Some(country_options),
111 Some(created),
112 Some(expires_at),
113 Some(id),
114 Some(livemode),
115 Some(status),
116 ) = (
117 self.active_from,
118 self.country.take(),
119 self.country_options.take(),
120 self.created,
121 self.expires_at,
122 self.id.take(),
123 self.livemode,
124 self.status.take(),
125 )
126 else {
127 return None;
128 };
129 Some(Self::Out {
130 active_from,
131 country,
132 country_options,
133 created,
134 expires_at,
135 id,
136 livemode,
137 status,
138 })
139 }
140 }
141
142 impl Map for Builder<'_> {
143 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
144 self.builder.key(k)
145 }
146
147 fn finish(&mut self) -> Result<()> {
148 *self.out = self.builder.take_out();
149 Ok(())
150 }
151 }
152
153 impl ObjectDeser for TaxRegistration {
154 type Builder = TaxRegistrationBuilder;
155 }
156
157 impl FromValueOpt for TaxRegistration {
158 fn from_value(v: Value) -> Option<Self> {
159 let Value::Object(obj) = v else {
160 return None;
161 };
162 let mut b = TaxRegistrationBuilder::deser_default();
163 for (k, v) in obj {
164 match k.as_str() {
165 "active_from" => b.active_from = FromValueOpt::from_value(v),
166 "country" => b.country = FromValueOpt::from_value(v),
167 "country_options" => b.country_options = FromValueOpt::from_value(v),
168 "created" => b.created = FromValueOpt::from_value(v),
169 "expires_at" => b.expires_at = FromValueOpt::from_value(v),
170 "id" => b.id = FromValueOpt::from_value(v),
171 "livemode" => b.livemode = FromValueOpt::from_value(v),
172 "status" => b.status = FromValueOpt::from_value(v),
173 _ => {}
174 }
175 }
176 b.take_out()
177 }
178 }
179};
180#[cfg(feature = "serialize")]
181impl serde::Serialize for TaxRegistration {
182 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
183 use serde::ser::SerializeStruct;
184 let mut s = s.serialize_struct("TaxRegistration", 9)?;
185 s.serialize_field("active_from", &self.active_from)?;
186 s.serialize_field("country", &self.country)?;
187 s.serialize_field("country_options", &self.country_options)?;
188 s.serialize_field("created", &self.created)?;
189 s.serialize_field("expires_at", &self.expires_at)?;
190 s.serialize_field("id", &self.id)?;
191 s.serialize_field("livemode", &self.livemode)?;
192 s.serialize_field("status", &self.status)?;
193
194 s.serialize_field("object", "tax.registration")?;
195 s.end()
196 }
197}
198#[derive(Clone, Eq, PartialEq)]
201#[non_exhaustive]
202pub enum TaxRegistrationStatus {
203 Active,
204 Expired,
205 Scheduled,
206 Unknown(String),
208}
209impl TaxRegistrationStatus {
210 pub fn as_str(&self) -> &str {
211 use TaxRegistrationStatus::*;
212 match self {
213 Active => "active",
214 Expired => "expired",
215 Scheduled => "scheduled",
216 Unknown(v) => v,
217 }
218 }
219}
220
221impl std::str::FromStr for TaxRegistrationStatus {
222 type Err = std::convert::Infallible;
223 fn from_str(s: &str) -> Result<Self, Self::Err> {
224 use TaxRegistrationStatus::*;
225 match s {
226 "active" => Ok(Active),
227 "expired" => Ok(Expired),
228 "scheduled" => Ok(Scheduled),
229 v => {
230 tracing::warn!("Unknown value '{}' for enum '{}'", v, "TaxRegistrationStatus");
231 Ok(Unknown(v.to_owned()))
232 }
233 }
234 }
235}
236impl std::fmt::Display for TaxRegistrationStatus {
237 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
238 f.write_str(self.as_str())
239 }
240}
241
242impl std::fmt::Debug for TaxRegistrationStatus {
243 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
244 f.write_str(self.as_str())
245 }
246}
247#[cfg(feature = "serialize")]
248impl serde::Serialize for TaxRegistrationStatus {
249 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
250 where
251 S: serde::Serializer,
252 {
253 serializer.serialize_str(self.as_str())
254 }
255}
256impl miniserde::Deserialize for TaxRegistrationStatus {
257 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
258 crate::Place::new(out)
259 }
260}
261
262impl miniserde::de::Visitor for crate::Place<TaxRegistrationStatus> {
263 fn string(&mut self, s: &str) -> miniserde::Result<()> {
264 use std::str::FromStr;
265 self.out = Some(TaxRegistrationStatus::from_str(s).expect("infallible"));
266 Ok(())
267 }
268}
269
270stripe_types::impl_from_val_with_from_str!(TaxRegistrationStatus);
271#[cfg(feature = "deserialize")]
272impl<'de> serde::Deserialize<'de> for TaxRegistrationStatus {
273 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
274 use std::str::FromStr;
275 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
276 Ok(Self::from_str(&s).expect("infallible"))
277 }
278}
279impl stripe_types::Object for TaxRegistration {
280 type Id = stripe_misc::TaxRegistrationId;
281 fn id(&self) -> &Self::Id {
282 &self.id
283 }
284
285 fn into_id(self) -> Self::Id {
286 self.id
287 }
288}
289stripe_types::def_id!(TaxRegistrationId);