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