stripe_misc/
tax_product_resource_tax_breakdown.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxProductResourceTaxBreakdown {
5    /// The amount of tax, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
6    pub amount: i64,
7    /// Specifies whether the tax amount is included in the line item amount.
8    pub inclusive: bool,
9    pub tax_rate_details: stripe_misc::TaxProductResourceTaxRateDetails,
10    /// The reasoning behind this tax, for example, if the product is tax exempt.
11    /// We might extend the possible values for this field to support new tax rules.
12    pub taxability_reason: TaxProductResourceTaxBreakdownTaxabilityReason,
13    /// The amount on which tax is calculated, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
14    pub taxable_amount: i64,
15}
16#[doc(hidden)]
17pub struct TaxProductResourceTaxBreakdownBuilder {
18    amount: Option<i64>,
19    inclusive: Option<bool>,
20    tax_rate_details: Option<stripe_misc::TaxProductResourceTaxRateDetails>,
21    taxability_reason: Option<TaxProductResourceTaxBreakdownTaxabilityReason>,
22    taxable_amount: Option<i64>,
23}
24
25#[allow(
26    unused_variables,
27    irrefutable_let_patterns,
28    clippy::let_unit_value,
29    clippy::match_single_binding,
30    clippy::single_match
31)]
32const _: () = {
33    use miniserde::de::{Map, Visitor};
34    use miniserde::json::Value;
35    use miniserde::{Deserialize, Result, make_place};
36    use stripe_types::miniserde_helpers::FromValueOpt;
37    use stripe_types::{MapBuilder, ObjectDeser};
38
39    make_place!(Place);
40
41    impl Deserialize for TaxProductResourceTaxBreakdown {
42        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
43            Place::new(out)
44        }
45    }
46
47    struct Builder<'a> {
48        out: &'a mut Option<TaxProductResourceTaxBreakdown>,
49        builder: TaxProductResourceTaxBreakdownBuilder,
50    }
51
52    impl Visitor for Place<TaxProductResourceTaxBreakdown> {
53        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54            Ok(Box::new(Builder {
55                out: &mut self.out,
56                builder: TaxProductResourceTaxBreakdownBuilder::deser_default(),
57            }))
58        }
59    }
60
61    impl MapBuilder for TaxProductResourceTaxBreakdownBuilder {
62        type Out = TaxProductResourceTaxBreakdown;
63        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
64            Ok(match k {
65                "amount" => Deserialize::begin(&mut self.amount),
66                "inclusive" => Deserialize::begin(&mut self.inclusive),
67                "tax_rate_details" => Deserialize::begin(&mut self.tax_rate_details),
68                "taxability_reason" => Deserialize::begin(&mut self.taxability_reason),
69                "taxable_amount" => Deserialize::begin(&mut self.taxable_amount),
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                amount: Deserialize::default(),
77                inclusive: Deserialize::default(),
78                tax_rate_details: Deserialize::default(),
79                taxability_reason: Deserialize::default(),
80                taxable_amount: Deserialize::default(),
81            }
82        }
83
84        fn take_out(&mut self) -> Option<Self::Out> {
85            let (
86                Some(amount),
87                Some(inclusive),
88                Some(tax_rate_details),
89                Some(taxability_reason),
90                Some(taxable_amount),
91            ) = (
92                self.amount,
93                self.inclusive,
94                self.tax_rate_details.take(),
95                self.taxability_reason.take(),
96                self.taxable_amount,
97            )
98            else {
99                return None;
100            };
101            Some(Self::Out {
102                amount,
103                inclusive,
104                tax_rate_details,
105                taxability_reason,
106                taxable_amount,
107            })
108        }
109    }
110
111    impl Map for Builder<'_> {
112        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
113            self.builder.key(k)
114        }
115
116        fn finish(&mut self) -> Result<()> {
117            *self.out = self.builder.take_out();
118            Ok(())
119        }
120    }
121
122    impl ObjectDeser for TaxProductResourceTaxBreakdown {
123        type Builder = TaxProductResourceTaxBreakdownBuilder;
124    }
125
126    impl FromValueOpt for TaxProductResourceTaxBreakdown {
127        fn from_value(v: Value) -> Option<Self> {
128            let Value::Object(obj) = v else {
129                return None;
130            };
131            let mut b = TaxProductResourceTaxBreakdownBuilder::deser_default();
132            for (k, v) in obj {
133                match k.as_str() {
134                    "amount" => b.amount = FromValueOpt::from_value(v),
135                    "inclusive" => b.inclusive = FromValueOpt::from_value(v),
136                    "tax_rate_details" => b.tax_rate_details = FromValueOpt::from_value(v),
137                    "taxability_reason" => b.taxability_reason = FromValueOpt::from_value(v),
138                    "taxable_amount" => b.taxable_amount = FromValueOpt::from_value(v),
139                    _ => {}
140                }
141            }
142            b.take_out()
143        }
144    }
145};
146/// The reasoning behind this tax, for example, if the product is tax exempt.
147/// We might extend the possible values for this field to support new tax rules.
148#[derive(Clone, Eq, PartialEq)]
149#[non_exhaustive]
150pub enum TaxProductResourceTaxBreakdownTaxabilityReason {
151    CustomerExempt,
152    NotCollecting,
153    NotSubjectToTax,
154    NotSupported,
155    PortionProductExempt,
156    PortionReducedRated,
157    PortionStandardRated,
158    ProductExempt,
159    ProductExemptHoliday,
160    ProportionallyRated,
161    ReducedRated,
162    ReverseCharge,
163    StandardRated,
164    TaxableBasisReduced,
165    ZeroRated,
166    /// An unrecognized value from Stripe. Should not be used as a request parameter.
167    Unknown(String),
168}
169impl TaxProductResourceTaxBreakdownTaxabilityReason {
170    pub fn as_str(&self) -> &str {
171        use TaxProductResourceTaxBreakdownTaxabilityReason::*;
172        match self {
173            CustomerExempt => "customer_exempt",
174            NotCollecting => "not_collecting",
175            NotSubjectToTax => "not_subject_to_tax",
176            NotSupported => "not_supported",
177            PortionProductExempt => "portion_product_exempt",
178            PortionReducedRated => "portion_reduced_rated",
179            PortionStandardRated => "portion_standard_rated",
180            ProductExempt => "product_exempt",
181            ProductExemptHoliday => "product_exempt_holiday",
182            ProportionallyRated => "proportionally_rated",
183            ReducedRated => "reduced_rated",
184            ReverseCharge => "reverse_charge",
185            StandardRated => "standard_rated",
186            TaxableBasisReduced => "taxable_basis_reduced",
187            ZeroRated => "zero_rated",
188            Unknown(v) => v,
189        }
190    }
191}
192
193impl std::str::FromStr for TaxProductResourceTaxBreakdownTaxabilityReason {
194    type Err = std::convert::Infallible;
195    fn from_str(s: &str) -> Result<Self, Self::Err> {
196        use TaxProductResourceTaxBreakdownTaxabilityReason::*;
197        match s {
198            "customer_exempt" => Ok(CustomerExempt),
199            "not_collecting" => Ok(NotCollecting),
200            "not_subject_to_tax" => Ok(NotSubjectToTax),
201            "not_supported" => Ok(NotSupported),
202            "portion_product_exempt" => Ok(PortionProductExempt),
203            "portion_reduced_rated" => Ok(PortionReducedRated),
204            "portion_standard_rated" => Ok(PortionStandardRated),
205            "product_exempt" => Ok(ProductExempt),
206            "product_exempt_holiday" => Ok(ProductExemptHoliday),
207            "proportionally_rated" => Ok(ProportionallyRated),
208            "reduced_rated" => Ok(ReducedRated),
209            "reverse_charge" => Ok(ReverseCharge),
210            "standard_rated" => Ok(StandardRated),
211            "taxable_basis_reduced" => Ok(TaxableBasisReduced),
212            "zero_rated" => Ok(ZeroRated),
213            v => {
214                tracing::warn!(
215                    "Unknown value '{}' for enum '{}'",
216                    v,
217                    "TaxProductResourceTaxBreakdownTaxabilityReason"
218                );
219                Ok(Unknown(v.to_owned()))
220            }
221        }
222    }
223}
224impl std::fmt::Display for TaxProductResourceTaxBreakdownTaxabilityReason {
225    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
226        f.write_str(self.as_str())
227    }
228}
229
230impl std::fmt::Debug for TaxProductResourceTaxBreakdownTaxabilityReason {
231    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232        f.write_str(self.as_str())
233    }
234}
235#[cfg(feature = "serialize")]
236impl serde::Serialize for TaxProductResourceTaxBreakdownTaxabilityReason {
237    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
238    where
239        S: serde::Serializer,
240    {
241        serializer.serialize_str(self.as_str())
242    }
243}
244impl miniserde::Deserialize for TaxProductResourceTaxBreakdownTaxabilityReason {
245    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
246        crate::Place::new(out)
247    }
248}
249
250impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxBreakdownTaxabilityReason> {
251    fn string(&mut self, s: &str) -> miniserde::Result<()> {
252        use std::str::FromStr;
253        self.out =
254            Some(TaxProductResourceTaxBreakdownTaxabilityReason::from_str(s).expect("infallible"));
255        Ok(())
256    }
257}
258
259stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxBreakdownTaxabilityReason);
260#[cfg(feature = "deserialize")]
261impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxBreakdownTaxabilityReason {
262    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
263        use std::str::FromStr;
264        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
265        Ok(Self::from_str(&s).expect("infallible"))
266    }
267}