1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CustomerTax {
5 pub automatic_tax: CustomerTaxAutomaticTax,
7 pub ip_address: Option<String>,
9 pub location: Option<stripe_shared::CustomerTaxLocation>,
11 pub provider: CustomerTaxProvider,
14}
15#[doc(hidden)]
16pub struct CustomerTaxBuilder {
17 automatic_tax: Option<CustomerTaxAutomaticTax>,
18 ip_address: Option<Option<String>>,
19 location: Option<Option<stripe_shared::CustomerTaxLocation>>,
20 provider: Option<CustomerTaxProvider>,
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 CustomerTax {
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<CustomerTax>,
47 builder: CustomerTaxBuilder,
48 }
49
50 impl Visitor for Place<CustomerTax> {
51 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52 Ok(Box::new(Builder {
53 out: &mut self.out,
54 builder: CustomerTaxBuilder::deser_default(),
55 }))
56 }
57 }
58
59 impl MapBuilder for CustomerTaxBuilder {
60 type Out = CustomerTax;
61 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62 Ok(match k {
63 "automatic_tax" => Deserialize::begin(&mut self.automatic_tax),
64 "ip_address" => Deserialize::begin(&mut self.ip_address),
65 "location" => Deserialize::begin(&mut self.location),
66 "provider" => Deserialize::begin(&mut self.provider),
67 _ => <dyn Visitor>::ignore(),
68 })
69 }
70
71 fn deser_default() -> Self {
72 Self {
73 automatic_tax: Deserialize::default(),
74 ip_address: Deserialize::default(),
75 location: Deserialize::default(),
76 provider: Deserialize::default(),
77 }
78 }
79
80 fn take_out(&mut self) -> Option<Self::Out> {
81 let (Some(automatic_tax), Some(ip_address), Some(location), Some(provider)) =
82 (self.automatic_tax, self.ip_address.take(), self.location.take(), self.provider)
83 else {
84 return None;
85 };
86 Some(Self::Out { automatic_tax, ip_address, location, provider })
87 }
88 }
89
90 impl Map for Builder<'_> {
91 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
92 self.builder.key(k)
93 }
94
95 fn finish(&mut self) -> Result<()> {
96 *self.out = self.builder.take_out();
97 Ok(())
98 }
99 }
100
101 impl ObjectDeser for CustomerTax {
102 type Builder = CustomerTaxBuilder;
103 }
104
105 impl FromValueOpt for CustomerTax {
106 fn from_value(v: Value) -> Option<Self> {
107 let Value::Object(obj) = v else {
108 return None;
109 };
110 let mut b = CustomerTaxBuilder::deser_default();
111 for (k, v) in obj {
112 match k.as_str() {
113 "automatic_tax" => b.automatic_tax = FromValueOpt::from_value(v),
114 "ip_address" => b.ip_address = FromValueOpt::from_value(v),
115 "location" => b.location = FromValueOpt::from_value(v),
116 "provider" => b.provider = FromValueOpt::from_value(v),
117 _ => {}
118 }
119 }
120 b.take_out()
121 }
122 }
123};
124#[derive(Copy, Clone, Eq, PartialEq)]
126pub enum CustomerTaxAutomaticTax {
127 Failed,
128 NotCollecting,
129 Supported,
130 UnrecognizedLocation,
131}
132impl CustomerTaxAutomaticTax {
133 pub fn as_str(self) -> &'static str {
134 use CustomerTaxAutomaticTax::*;
135 match self {
136 Failed => "failed",
137 NotCollecting => "not_collecting",
138 Supported => "supported",
139 UnrecognizedLocation => "unrecognized_location",
140 }
141 }
142}
143
144impl std::str::FromStr for CustomerTaxAutomaticTax {
145 type Err = stripe_types::StripeParseError;
146 fn from_str(s: &str) -> Result<Self, Self::Err> {
147 use CustomerTaxAutomaticTax::*;
148 match s {
149 "failed" => Ok(Failed),
150 "not_collecting" => Ok(NotCollecting),
151 "supported" => Ok(Supported),
152 "unrecognized_location" => Ok(UnrecognizedLocation),
153 _ => Err(stripe_types::StripeParseError),
154 }
155 }
156}
157impl std::fmt::Display for CustomerTaxAutomaticTax {
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 CustomerTaxAutomaticTax {
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 CustomerTaxAutomaticTax {
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 CustomerTaxAutomaticTax {
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<CustomerTaxAutomaticTax> {
184 fn string(&mut self, s: &str) -> miniserde::Result<()> {
185 use std::str::FromStr;
186 self.out = Some(CustomerTaxAutomaticTax::from_str(s).map_err(|_| miniserde::Error)?);
187 Ok(())
188 }
189}
190
191stripe_types::impl_from_val_with_from_str!(CustomerTaxAutomaticTax);
192#[cfg(feature = "deserialize")]
193impl<'de> serde::Deserialize<'de> for CustomerTaxAutomaticTax {
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 Self::from_str(&s)
198 .map_err(|_| serde::de::Error::custom("Unknown value for CustomerTaxAutomaticTax"))
199 }
200}
201#[derive(Copy, Clone, Eq, PartialEq)]
204pub enum CustomerTaxProvider {
205 Anrok,
206 Avalara,
207 Sphere,
208 Stripe,
209}
210impl CustomerTaxProvider {
211 pub fn as_str(self) -> &'static str {
212 use CustomerTaxProvider::*;
213 match self {
214 Anrok => "anrok",
215 Avalara => "avalara",
216 Sphere => "sphere",
217 Stripe => "stripe",
218 }
219 }
220}
221
222impl std::str::FromStr for CustomerTaxProvider {
223 type Err = stripe_types::StripeParseError;
224 fn from_str(s: &str) -> Result<Self, Self::Err> {
225 use CustomerTaxProvider::*;
226 match s {
227 "anrok" => Ok(Anrok),
228 "avalara" => Ok(Avalara),
229 "sphere" => Ok(Sphere),
230 "stripe" => Ok(Stripe),
231 _ => Err(stripe_types::StripeParseError),
232 }
233 }
234}
235impl std::fmt::Display for CustomerTaxProvider {
236 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
237 f.write_str(self.as_str())
238 }
239}
240
241impl std::fmt::Debug for CustomerTaxProvider {
242 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
243 f.write_str(self.as_str())
244 }
245}
246#[cfg(feature = "serialize")]
247impl serde::Serialize for CustomerTaxProvider {
248 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
249 where
250 S: serde::Serializer,
251 {
252 serializer.serialize_str(self.as_str())
253 }
254}
255impl miniserde::Deserialize for CustomerTaxProvider {
256 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
257 crate::Place::new(out)
258 }
259}
260
261impl miniserde::de::Visitor for crate::Place<CustomerTaxProvider> {
262 fn string(&mut self, s: &str) -> miniserde::Result<()> {
263 use std::str::FromStr;
264 self.out = Some(CustomerTaxProvider::from_str(s).map_err(|_| miniserde::Error)?);
265 Ok(())
266 }
267}
268
269stripe_types::impl_from_val_with_from_str!(CustomerTaxProvider);
270#[cfg(feature = "deserialize")]
271impl<'de> serde::Deserialize<'de> for CustomerTaxProvider {
272 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
273 use std::str::FromStr;
274 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
275 Self::from_str(&s)
276 .map_err(|_| serde::de::Error::custom("Unknown value for CustomerTaxProvider"))
277 }
278}