stripe_shared/
billing_bill_resource_invoicing_taxes_tax.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct BillingBillResourceInvoicingTaxesTax {
5    /// The amount of the tax, in cents (or local equivalent).
6    pub amount: i64,
7    /// Whether this tax is inclusive or exclusive.
8    pub tax_behavior: BillingBillResourceInvoicingTaxesTaxTaxBehavior,
9    /// Additional details about the tax rate. Only present when `type` is `tax_rate_details`.
10    pub tax_rate_details: Option<stripe_shared::BillingBillResourceInvoicingTaxesTaxRateDetails>,
11    /// The reasoning behind this tax, for example, if the product is tax exempt.
12    /// The possible values for this field may be extended as new tax rules are supported.
13    pub taxability_reason: BillingBillResourceInvoicingTaxesTaxTaxabilityReason,
14    /// The amount on which tax is calculated, in cents (or local equivalent).
15    pub taxable_amount: Option<i64>,
16    /// The type of tax information.
17    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
18    pub type_: BillingBillResourceInvoicingTaxesTaxType,
19}
20#[doc(hidden)]
21pub struct BillingBillResourceInvoicingTaxesTaxBuilder {
22    amount: Option<i64>,
23    tax_behavior: Option<BillingBillResourceInvoicingTaxesTaxTaxBehavior>,
24    tax_rate_details:
25        Option<Option<stripe_shared::BillingBillResourceInvoicingTaxesTaxRateDetails>>,
26    taxability_reason: Option<BillingBillResourceInvoicingTaxesTaxTaxabilityReason>,
27    taxable_amount: Option<Option<i64>>,
28    type_: Option<BillingBillResourceInvoicingTaxesTaxType>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{Deserialize, Result, make_place};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for BillingBillResourceInvoicingTaxesTax {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<BillingBillResourceInvoicingTaxesTax>,
55        builder: BillingBillResourceInvoicingTaxesTaxBuilder,
56    }
57
58    impl Visitor for Place<BillingBillResourceInvoicingTaxesTax> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: BillingBillResourceInvoicingTaxesTaxBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for BillingBillResourceInvoicingTaxesTaxBuilder {
68        type Out = BillingBillResourceInvoicingTaxesTax;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "amount" => Deserialize::begin(&mut self.amount),
72                "tax_behavior" => Deserialize::begin(&mut self.tax_behavior),
73                "tax_rate_details" => Deserialize::begin(&mut self.tax_rate_details),
74                "taxability_reason" => Deserialize::begin(&mut self.taxability_reason),
75                "taxable_amount" => Deserialize::begin(&mut self.taxable_amount),
76                "type" => Deserialize::begin(&mut self.type_),
77                _ => <dyn Visitor>::ignore(),
78            })
79        }
80
81        fn deser_default() -> Self {
82            Self {
83                amount: Deserialize::default(),
84                tax_behavior: Deserialize::default(),
85                tax_rate_details: Deserialize::default(),
86                taxability_reason: Deserialize::default(),
87                taxable_amount: Deserialize::default(),
88                type_: Deserialize::default(),
89            }
90        }
91
92        fn take_out(&mut self) -> Option<Self::Out> {
93            let (
94                Some(amount),
95                Some(tax_behavior),
96                Some(tax_rate_details),
97                Some(taxability_reason),
98                Some(taxable_amount),
99                Some(type_),
100            ) = (
101                self.amount,
102                self.tax_behavior,
103                self.tax_rate_details.take(),
104                self.taxability_reason.take(),
105                self.taxable_amount,
106                self.type_,
107            )
108            else {
109                return None;
110            };
111            Some(Self::Out {
112                amount,
113                tax_behavior,
114                tax_rate_details,
115                taxability_reason,
116                taxable_amount,
117                type_,
118            })
119        }
120    }
121
122    impl Map for Builder<'_> {
123        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
124            self.builder.key(k)
125        }
126
127        fn finish(&mut self) -> Result<()> {
128            *self.out = self.builder.take_out();
129            Ok(())
130        }
131    }
132
133    impl ObjectDeser for BillingBillResourceInvoicingTaxesTax {
134        type Builder = BillingBillResourceInvoicingTaxesTaxBuilder;
135    }
136
137    impl FromValueOpt for BillingBillResourceInvoicingTaxesTax {
138        fn from_value(v: Value) -> Option<Self> {
139            let Value::Object(obj) = v else {
140                return None;
141            };
142            let mut b = BillingBillResourceInvoicingTaxesTaxBuilder::deser_default();
143            for (k, v) in obj {
144                match k.as_str() {
145                    "amount" => b.amount = FromValueOpt::from_value(v),
146                    "tax_behavior" => b.tax_behavior = FromValueOpt::from_value(v),
147                    "tax_rate_details" => b.tax_rate_details = FromValueOpt::from_value(v),
148                    "taxability_reason" => b.taxability_reason = FromValueOpt::from_value(v),
149                    "taxable_amount" => b.taxable_amount = FromValueOpt::from_value(v),
150                    "type" => b.type_ = FromValueOpt::from_value(v),
151                    _ => {}
152                }
153            }
154            b.take_out()
155        }
156    }
157};
158/// Whether this tax is inclusive or exclusive.
159#[derive(Copy, Clone, Eq, PartialEq)]
160pub enum BillingBillResourceInvoicingTaxesTaxTaxBehavior {
161    Exclusive,
162    Inclusive,
163}
164impl BillingBillResourceInvoicingTaxesTaxTaxBehavior {
165    pub fn as_str(self) -> &'static str {
166        use BillingBillResourceInvoicingTaxesTaxTaxBehavior::*;
167        match self {
168            Exclusive => "exclusive",
169            Inclusive => "inclusive",
170        }
171    }
172}
173
174impl std::str::FromStr for BillingBillResourceInvoicingTaxesTaxTaxBehavior {
175    type Err = stripe_types::StripeParseError;
176    fn from_str(s: &str) -> Result<Self, Self::Err> {
177        use BillingBillResourceInvoicingTaxesTaxTaxBehavior::*;
178        match s {
179            "exclusive" => Ok(Exclusive),
180            "inclusive" => Ok(Inclusive),
181            _ => Err(stripe_types::StripeParseError),
182        }
183    }
184}
185impl std::fmt::Display for BillingBillResourceInvoicingTaxesTaxTaxBehavior {
186    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
187        f.write_str(self.as_str())
188    }
189}
190
191impl std::fmt::Debug for BillingBillResourceInvoicingTaxesTaxTaxBehavior {
192    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
193        f.write_str(self.as_str())
194    }
195}
196#[cfg(feature = "serialize")]
197impl serde::Serialize for BillingBillResourceInvoicingTaxesTaxTaxBehavior {
198    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
199    where
200        S: serde::Serializer,
201    {
202        serializer.serialize_str(self.as_str())
203    }
204}
205impl miniserde::Deserialize for BillingBillResourceInvoicingTaxesTaxTaxBehavior {
206    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
207        crate::Place::new(out)
208    }
209}
210
211impl miniserde::de::Visitor for crate::Place<BillingBillResourceInvoicingTaxesTaxTaxBehavior> {
212    fn string(&mut self, s: &str) -> miniserde::Result<()> {
213        use std::str::FromStr;
214        self.out = Some(
215            BillingBillResourceInvoicingTaxesTaxTaxBehavior::from_str(s)
216                .map_err(|_| miniserde::Error)?,
217        );
218        Ok(())
219    }
220}
221
222stripe_types::impl_from_val_with_from_str!(BillingBillResourceInvoicingTaxesTaxTaxBehavior);
223#[cfg(feature = "deserialize")]
224impl<'de> serde::Deserialize<'de> for BillingBillResourceInvoicingTaxesTaxTaxBehavior {
225    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
226        use std::str::FromStr;
227        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
228        Self::from_str(&s).map_err(|_| {
229            serde::de::Error::custom(
230                "Unknown value for BillingBillResourceInvoicingTaxesTaxTaxBehavior",
231            )
232        })
233    }
234}
235/// The reasoning behind this tax, for example, if the product is tax exempt.
236/// The possible values for this field may be extended as new tax rules are supported.
237#[derive(Clone, Eq, PartialEq)]
238#[non_exhaustive]
239pub enum BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
240    CustomerExempt,
241    NotAvailable,
242    NotCollecting,
243    NotSubjectToTax,
244    NotSupported,
245    PortionProductExempt,
246    PortionReducedRated,
247    PortionStandardRated,
248    ProductExempt,
249    ProductExemptHoliday,
250    ProportionallyRated,
251    ReducedRated,
252    ReverseCharge,
253    StandardRated,
254    TaxableBasisReduced,
255    ZeroRated,
256    /// An unrecognized value from Stripe. Should not be used as a request parameter.
257    Unknown(String),
258}
259impl BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
260    pub fn as_str(&self) -> &str {
261        use BillingBillResourceInvoicingTaxesTaxTaxabilityReason::*;
262        match self {
263            CustomerExempt => "customer_exempt",
264            NotAvailable => "not_available",
265            NotCollecting => "not_collecting",
266            NotSubjectToTax => "not_subject_to_tax",
267            NotSupported => "not_supported",
268            PortionProductExempt => "portion_product_exempt",
269            PortionReducedRated => "portion_reduced_rated",
270            PortionStandardRated => "portion_standard_rated",
271            ProductExempt => "product_exempt",
272            ProductExemptHoliday => "product_exempt_holiday",
273            ProportionallyRated => "proportionally_rated",
274            ReducedRated => "reduced_rated",
275            ReverseCharge => "reverse_charge",
276            StandardRated => "standard_rated",
277            TaxableBasisReduced => "taxable_basis_reduced",
278            ZeroRated => "zero_rated",
279            Unknown(v) => v,
280        }
281    }
282}
283
284impl std::str::FromStr for BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
285    type Err = std::convert::Infallible;
286    fn from_str(s: &str) -> Result<Self, Self::Err> {
287        use BillingBillResourceInvoicingTaxesTaxTaxabilityReason::*;
288        match s {
289            "customer_exempt" => Ok(CustomerExempt),
290            "not_available" => Ok(NotAvailable),
291            "not_collecting" => Ok(NotCollecting),
292            "not_subject_to_tax" => Ok(NotSubjectToTax),
293            "not_supported" => Ok(NotSupported),
294            "portion_product_exempt" => Ok(PortionProductExempt),
295            "portion_reduced_rated" => Ok(PortionReducedRated),
296            "portion_standard_rated" => Ok(PortionStandardRated),
297            "product_exempt" => Ok(ProductExempt),
298            "product_exempt_holiday" => Ok(ProductExemptHoliday),
299            "proportionally_rated" => Ok(ProportionallyRated),
300            "reduced_rated" => Ok(ReducedRated),
301            "reverse_charge" => Ok(ReverseCharge),
302            "standard_rated" => Ok(StandardRated),
303            "taxable_basis_reduced" => Ok(TaxableBasisReduced),
304            "zero_rated" => Ok(ZeroRated),
305            v => Ok(Unknown(v.to_owned())),
306        }
307    }
308}
309impl std::fmt::Display for BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
310    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
311        f.write_str(self.as_str())
312    }
313}
314
315impl std::fmt::Debug for BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
316    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
317        f.write_str(self.as_str())
318    }
319}
320#[cfg(feature = "serialize")]
321impl serde::Serialize for BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
322    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
323    where
324        S: serde::Serializer,
325    {
326        serializer.serialize_str(self.as_str())
327    }
328}
329impl miniserde::Deserialize for BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
330    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
331        crate::Place::new(out)
332    }
333}
334
335impl miniserde::de::Visitor for crate::Place<BillingBillResourceInvoicingTaxesTaxTaxabilityReason> {
336    fn string(&mut self, s: &str) -> miniserde::Result<()> {
337        use std::str::FromStr;
338        self.out = Some(BillingBillResourceInvoicingTaxesTaxTaxabilityReason::from_str(s).unwrap());
339        Ok(())
340    }
341}
342
343stripe_types::impl_from_val_with_from_str!(BillingBillResourceInvoicingTaxesTaxTaxabilityReason);
344#[cfg(feature = "deserialize")]
345impl<'de> serde::Deserialize<'de> for BillingBillResourceInvoicingTaxesTaxTaxabilityReason {
346    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
347        use std::str::FromStr;
348        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
349        Ok(Self::from_str(&s).unwrap())
350    }
351}
352/// The type of tax information.
353#[derive(Copy, Clone, Eq, PartialEq)]
354pub enum BillingBillResourceInvoicingTaxesTaxType {
355    TaxRateDetails,
356}
357impl BillingBillResourceInvoicingTaxesTaxType {
358    pub fn as_str(self) -> &'static str {
359        use BillingBillResourceInvoicingTaxesTaxType::*;
360        match self {
361            TaxRateDetails => "tax_rate_details",
362        }
363    }
364}
365
366impl std::str::FromStr for BillingBillResourceInvoicingTaxesTaxType {
367    type Err = stripe_types::StripeParseError;
368    fn from_str(s: &str) -> Result<Self, Self::Err> {
369        use BillingBillResourceInvoicingTaxesTaxType::*;
370        match s {
371            "tax_rate_details" => Ok(TaxRateDetails),
372            _ => Err(stripe_types::StripeParseError),
373        }
374    }
375}
376impl std::fmt::Display for BillingBillResourceInvoicingTaxesTaxType {
377    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
378        f.write_str(self.as_str())
379    }
380}
381
382impl std::fmt::Debug for BillingBillResourceInvoicingTaxesTaxType {
383    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
384        f.write_str(self.as_str())
385    }
386}
387#[cfg(feature = "serialize")]
388impl serde::Serialize for BillingBillResourceInvoicingTaxesTaxType {
389    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
390    where
391        S: serde::Serializer,
392    {
393        serializer.serialize_str(self.as_str())
394    }
395}
396impl miniserde::Deserialize for BillingBillResourceInvoicingTaxesTaxType {
397    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
398        crate::Place::new(out)
399    }
400}
401
402impl miniserde::de::Visitor for crate::Place<BillingBillResourceInvoicingTaxesTaxType> {
403    fn string(&mut self, s: &str) -> miniserde::Result<()> {
404        use std::str::FromStr;
405        self.out = Some(
406            BillingBillResourceInvoicingTaxesTaxType::from_str(s).map_err(|_| miniserde::Error)?,
407        );
408        Ok(())
409    }
410}
411
412stripe_types::impl_from_val_with_from_str!(BillingBillResourceInvoicingTaxesTaxType);
413#[cfg(feature = "deserialize")]
414impl<'de> serde::Deserialize<'de> for BillingBillResourceInvoicingTaxesTaxType {
415    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
416        use std::str::FromStr;
417        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
418        Self::from_str(&s).map_err(|_| {
419            serde::de::Error::custom("Unknown value for BillingBillResourceInvoicingTaxesTaxType")
420        })
421    }
422}