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 _ => <dyn Visitor>::ignore(),
67 })
68 }
69
70 fn deser_default() -> Self {
71 Self {
72 amount: Deserialize::default(),
73 rate: Deserialize::default(),
74 taxability_reason: Deserialize::default(),
75 taxable_amount: Deserialize::default(),
76 }
77 }
78
79 fn take_out(&mut self) -> Option<Self::Out> {
80 let (Some(amount), Some(rate), Some(taxability_reason), Some(taxable_amount)) =
81 (self.amount, self.rate.take(), self.taxability_reason.take(), self.taxable_amount)
82 else {
83 return None;
84 };
85 Some(Self::Out { amount, rate, taxability_reason, taxable_amount })
86 }
87 }
88
89 impl Map for Builder<'_> {
90 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
91 self.builder.key(k)
92 }
93
94 fn finish(&mut self) -> Result<()> {
95 *self.out = self.builder.take_out();
96 Ok(())
97 }
98 }
99
100 impl ObjectDeser for LineItemsTaxAmount {
101 type Builder = LineItemsTaxAmountBuilder;
102 }
103
104 impl FromValueOpt for LineItemsTaxAmount {
105 fn from_value(v: Value) -> Option<Self> {
106 let Value::Object(obj) = v else {
107 return None;
108 };
109 let mut b = LineItemsTaxAmountBuilder::deser_default();
110 for (k, v) in obj {
111 match k.as_str() {
112 "amount" => b.amount = FromValueOpt::from_value(v),
113 "rate" => b.rate = FromValueOpt::from_value(v),
114 "taxability_reason" => b.taxability_reason = FromValueOpt::from_value(v),
115 "taxable_amount" => b.taxable_amount = FromValueOpt::from_value(v),
116 _ => {}
117 }
118 }
119 b.take_out()
120 }
121 }
122};
123#[derive(Clone, Eq, PartialEq)]
126#[non_exhaustive]
127pub enum LineItemsTaxAmountTaxabilityReason {
128 CustomerExempt,
129 NotCollecting,
130 NotSubjectToTax,
131 NotSupported,
132 PortionProductExempt,
133 PortionReducedRated,
134 PortionStandardRated,
135 ProductExempt,
136 ProductExemptHoliday,
137 ProportionallyRated,
138 ReducedRated,
139 ReverseCharge,
140 StandardRated,
141 TaxableBasisReduced,
142 ZeroRated,
143 Unknown(String),
145}
146impl LineItemsTaxAmountTaxabilityReason {
147 pub fn as_str(&self) -> &str {
148 use LineItemsTaxAmountTaxabilityReason::*;
149 match self {
150 CustomerExempt => "customer_exempt",
151 NotCollecting => "not_collecting",
152 NotSubjectToTax => "not_subject_to_tax",
153 NotSupported => "not_supported",
154 PortionProductExempt => "portion_product_exempt",
155 PortionReducedRated => "portion_reduced_rated",
156 PortionStandardRated => "portion_standard_rated",
157 ProductExempt => "product_exempt",
158 ProductExemptHoliday => "product_exempt_holiday",
159 ProportionallyRated => "proportionally_rated",
160 ReducedRated => "reduced_rated",
161 ReverseCharge => "reverse_charge",
162 StandardRated => "standard_rated",
163 TaxableBasisReduced => "taxable_basis_reduced",
164 ZeroRated => "zero_rated",
165 Unknown(v) => v,
166 }
167 }
168}
169
170impl std::str::FromStr for LineItemsTaxAmountTaxabilityReason {
171 type Err = std::convert::Infallible;
172 fn from_str(s: &str) -> Result<Self, Self::Err> {
173 use LineItemsTaxAmountTaxabilityReason::*;
174 match s {
175 "customer_exempt" => Ok(CustomerExempt),
176 "not_collecting" => Ok(NotCollecting),
177 "not_subject_to_tax" => Ok(NotSubjectToTax),
178 "not_supported" => Ok(NotSupported),
179 "portion_product_exempt" => Ok(PortionProductExempt),
180 "portion_reduced_rated" => Ok(PortionReducedRated),
181 "portion_standard_rated" => Ok(PortionStandardRated),
182 "product_exempt" => Ok(ProductExempt),
183 "product_exempt_holiday" => Ok(ProductExemptHoliday),
184 "proportionally_rated" => Ok(ProportionallyRated),
185 "reduced_rated" => Ok(ReducedRated),
186 "reverse_charge" => Ok(ReverseCharge),
187 "standard_rated" => Ok(StandardRated),
188 "taxable_basis_reduced" => Ok(TaxableBasisReduced),
189 "zero_rated" => Ok(ZeroRated),
190 v => Ok(Unknown(v.to_owned())),
191 }
192 }
193}
194impl std::fmt::Display for LineItemsTaxAmountTaxabilityReason {
195 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
196 f.write_str(self.as_str())
197 }
198}
199
200impl std::fmt::Debug for LineItemsTaxAmountTaxabilityReason {
201 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
202 f.write_str(self.as_str())
203 }
204}
205#[cfg(feature = "serialize")]
206impl serde::Serialize for LineItemsTaxAmountTaxabilityReason {
207 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
208 where
209 S: serde::Serializer,
210 {
211 serializer.serialize_str(self.as_str())
212 }
213}
214impl miniserde::Deserialize for LineItemsTaxAmountTaxabilityReason {
215 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
216 crate::Place::new(out)
217 }
218}
219
220impl miniserde::de::Visitor for crate::Place<LineItemsTaxAmountTaxabilityReason> {
221 fn string(&mut self, s: &str) -> miniserde::Result<()> {
222 use std::str::FromStr;
223 self.out = Some(LineItemsTaxAmountTaxabilityReason::from_str(s).unwrap());
224 Ok(())
225 }
226}
227
228stripe_types::impl_from_val_with_from_str!(LineItemsTaxAmountTaxabilityReason);
229#[cfg(feature = "deserialize")]
230impl<'de> serde::Deserialize<'de> for LineItemsTaxAmountTaxabilityReason {
231 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
232 use std::str::FromStr;
233 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
234 Ok(Self::from_str(&s).unwrap())
235 }
236}