1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct LineItemsTaxAmount {
5 pub amount: i64,
7 pub rate: stripe_shared::TaxRate,
8 pub taxability_reason: Option<LineItemsTaxAmountTaxabilityReason>,
11 pub taxable_amount: Option<i64>,
13}
14#[doc(hidden)]
15pub struct LineItemsTaxAmountBuilder {
16 amount: Option<i64>,
17 rate: Option<stripe_shared::TaxRate>,
18 taxability_reason: Option<Option<LineItemsTaxAmountTaxabilityReason>>,
19 taxable_amount: Option<Option<i64>>,
20}
21
22#[allow(
23 unused_variables,
24 irrefutable_let_patterns,
25 clippy::let_unit_value,
26 clippy::match_single_binding,
27 clippy::single_match
28)]
29const _: () = {
30 use miniserde::de::{Map, Visitor};
31 use miniserde::json::Value;
32 use miniserde::{Deserialize, Result, make_place};
33 use stripe_types::miniserde_helpers::FromValueOpt;
34 use stripe_types::{MapBuilder, ObjectDeser};
35
36 make_place!(Place);
37
38 impl Deserialize for LineItemsTaxAmount {
39 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40 Place::new(out)
41 }
42 }
43
44 struct Builder<'a> {
45 out: &'a mut Option<LineItemsTaxAmount>,
46 builder: LineItemsTaxAmountBuilder,
47 }
48
49 impl Visitor for Place<LineItemsTaxAmount> {
50 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51 Ok(Box::new(Builder {
52 out: &mut self.out,
53 builder: LineItemsTaxAmountBuilder::deser_default(),
54 }))
55 }
56 }
57
58 impl MapBuilder for LineItemsTaxAmountBuilder {
59 type Out = LineItemsTaxAmount;
60 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61 Ok(match k {
62 "amount" => Deserialize::begin(&mut self.amount),
63 "rate" => Deserialize::begin(&mut self.rate),
64 "taxability_reason" => Deserialize::begin(&mut self.taxability_reason),
65 "taxable_amount" => Deserialize::begin(&mut self.taxable_amount),
66
67 _ => <dyn Visitor>::ignore(),
68 })
69 }
70
71 fn deser_default() -> Self {
72 Self {
73 amount: Deserialize::default(),
74 rate: Deserialize::default(),
75 taxability_reason: Deserialize::default(),
76 taxable_amount: Deserialize::default(),
77 }
78 }
79
80 fn take_out(&mut self) -> Option<Self::Out> {
81 let (Some(amount), Some(rate), Some(taxability_reason), Some(taxable_amount)) =
82 (self.amount, self.rate.take(), self.taxability_reason.take(), self.taxable_amount)
83 else {
84 return None;
85 };
86 Some(Self::Out { amount, rate, taxability_reason, taxable_amount })
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 LineItemsTaxAmount {
102 type Builder = LineItemsTaxAmountBuilder;
103 }
104
105 impl FromValueOpt for LineItemsTaxAmount {
106 fn from_value(v: Value) -> Option<Self> {
107 let Value::Object(obj) = v else {
108 return None;
109 };
110 let mut b = LineItemsTaxAmountBuilder::deser_default();
111 for (k, v) in obj {
112 match k.as_str() {
113 "amount" => b.amount = FromValueOpt::from_value(v),
114 "rate" => b.rate = FromValueOpt::from_value(v),
115 "taxability_reason" => b.taxability_reason = FromValueOpt::from_value(v),
116 "taxable_amount" => b.taxable_amount = FromValueOpt::from_value(v),
117
118 _ => {}
119 }
120 }
121 b.take_out()
122 }
123 }
124};
125#[derive(Clone, Eq, PartialEq)]
128#[non_exhaustive]
129pub enum LineItemsTaxAmountTaxabilityReason {
130 CustomerExempt,
131 NotCollecting,
132 NotSubjectToTax,
133 NotSupported,
134 PortionProductExempt,
135 PortionReducedRated,
136 PortionStandardRated,
137 ProductExempt,
138 ProductExemptHoliday,
139 ProportionallyRated,
140 ReducedRated,
141 ReverseCharge,
142 StandardRated,
143 TaxableBasisReduced,
144 ZeroRated,
145 Unknown(String),
147}
148impl LineItemsTaxAmountTaxabilityReason {
149 pub fn as_str(&self) -> &str {
150 use LineItemsTaxAmountTaxabilityReason::*;
151 match self {
152 CustomerExempt => "customer_exempt",
153 NotCollecting => "not_collecting",
154 NotSubjectToTax => "not_subject_to_tax",
155 NotSupported => "not_supported",
156 PortionProductExempt => "portion_product_exempt",
157 PortionReducedRated => "portion_reduced_rated",
158 PortionStandardRated => "portion_standard_rated",
159 ProductExempt => "product_exempt",
160 ProductExemptHoliday => "product_exempt_holiday",
161 ProportionallyRated => "proportionally_rated",
162 ReducedRated => "reduced_rated",
163 ReverseCharge => "reverse_charge",
164 StandardRated => "standard_rated",
165 TaxableBasisReduced => "taxable_basis_reduced",
166 ZeroRated => "zero_rated",
167 Unknown(v) => v,
168 }
169 }
170}
171
172impl std::str::FromStr for LineItemsTaxAmountTaxabilityReason {
173 type Err = std::convert::Infallible;
174 fn from_str(s: &str) -> Result<Self, Self::Err> {
175 use LineItemsTaxAmountTaxabilityReason::*;
176 match s {
177 "customer_exempt" => Ok(CustomerExempt),
178 "not_collecting" => Ok(NotCollecting),
179 "not_subject_to_tax" => Ok(NotSubjectToTax),
180 "not_supported" => Ok(NotSupported),
181 "portion_product_exempt" => Ok(PortionProductExempt),
182 "portion_reduced_rated" => Ok(PortionReducedRated),
183 "portion_standard_rated" => Ok(PortionStandardRated),
184 "product_exempt" => Ok(ProductExempt),
185 "product_exempt_holiday" => Ok(ProductExemptHoliday),
186 "proportionally_rated" => Ok(ProportionallyRated),
187 "reduced_rated" => Ok(ReducedRated),
188 "reverse_charge" => Ok(ReverseCharge),
189 "standard_rated" => Ok(StandardRated),
190 "taxable_basis_reduced" => Ok(TaxableBasisReduced),
191 "zero_rated" => Ok(ZeroRated),
192 v => Ok(Unknown(v.to_owned())),
193 }
194 }
195}
196impl std::fmt::Display for LineItemsTaxAmountTaxabilityReason {
197 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
198 f.write_str(self.as_str())
199 }
200}
201
202impl std::fmt::Debug for LineItemsTaxAmountTaxabilityReason {
203 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
204 f.write_str(self.as_str())
205 }
206}
207#[cfg(feature = "serialize")]
208impl serde::Serialize for LineItemsTaxAmountTaxabilityReason {
209 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
210 where
211 S: serde::Serializer,
212 {
213 serializer.serialize_str(self.as_str())
214 }
215}
216impl miniserde::Deserialize for LineItemsTaxAmountTaxabilityReason {
217 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
218 crate::Place::new(out)
219 }
220}
221
222impl miniserde::de::Visitor for crate::Place<LineItemsTaxAmountTaxabilityReason> {
223 fn string(&mut self, s: &str) -> miniserde::Result<()> {
224 use std::str::FromStr;
225 self.out = Some(LineItemsTaxAmountTaxabilityReason::from_str(s).unwrap());
226 Ok(())
227 }
228}
229
230stripe_types::impl_from_val_with_from_str!(LineItemsTaxAmountTaxabilityReason);
231#[cfg(feature = "deserialize")]
232impl<'de> serde::Deserialize<'de> for LineItemsTaxAmountTaxabilityReason {
233 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
234 use std::str::FromStr;
235 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
236 Ok(Self::from_str(&s).unwrap())
237 }
238}