stripe_misc/
tax_product_resource_tax_rate_details.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxProductResourceTaxRateDetails {
5    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
6    pub country: Option<String>,
7    /// The amount of the tax rate when the `rate_type` is `flat_amount`.
8    /// Tax rates with `rate_type` `percentage` can vary based on the transaction, resulting in this field being `null`.
9    /// This field exposes the amount and currency of the flat tax rate.
10    pub flat_amount: Option<stripe_shared::TaxRateFlatAmount>,
11    /// The tax rate percentage as a string. For example, 8.5% is represented as `"8.5"`.
12    pub percentage_decimal: String,
13    /// Indicates the type of tax rate applied to the taxable amount.
14    /// This value can be `null` when no tax applies to the location.
15    /// This field is only present for TaxRates created by Stripe Tax.
16    pub rate_type: Option<TaxProductResourceTaxRateDetailsRateType>,
17    /// State, county, province, or region.
18    pub state: Option<String>,
19    /// The tax type, such as `vat` or `sales_tax`.
20    pub tax_type: Option<TaxProductResourceTaxRateDetailsTaxType>,
21}
22#[doc(hidden)]
23pub struct TaxProductResourceTaxRateDetailsBuilder {
24    country: Option<Option<String>>,
25    flat_amount: Option<Option<stripe_shared::TaxRateFlatAmount>>,
26    percentage_decimal: Option<String>,
27    rate_type: Option<Option<TaxProductResourceTaxRateDetailsRateType>>,
28    state: Option<Option<String>>,
29    tax_type: Option<Option<TaxProductResourceTaxRateDetailsTaxType>>,
30}
31
32#[allow(
33    unused_variables,
34    irrefutable_let_patterns,
35    clippy::let_unit_value,
36    clippy::match_single_binding,
37    clippy::single_match
38)]
39const _: () = {
40    use miniserde::de::{Map, Visitor};
41    use miniserde::json::Value;
42    use miniserde::{Deserialize, Result, make_place};
43    use stripe_types::miniserde_helpers::FromValueOpt;
44    use stripe_types::{MapBuilder, ObjectDeser};
45
46    make_place!(Place);
47
48    impl Deserialize for TaxProductResourceTaxRateDetails {
49        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50            Place::new(out)
51        }
52    }
53
54    struct Builder<'a> {
55        out: &'a mut Option<TaxProductResourceTaxRateDetails>,
56        builder: TaxProductResourceTaxRateDetailsBuilder,
57    }
58
59    impl Visitor for Place<TaxProductResourceTaxRateDetails> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: TaxProductResourceTaxRateDetailsBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for TaxProductResourceTaxRateDetailsBuilder {
69        type Out = TaxProductResourceTaxRateDetails;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "country" => Deserialize::begin(&mut self.country),
73                "flat_amount" => Deserialize::begin(&mut self.flat_amount),
74                "percentage_decimal" => Deserialize::begin(&mut self.percentage_decimal),
75                "rate_type" => Deserialize::begin(&mut self.rate_type),
76                "state" => Deserialize::begin(&mut self.state),
77                "tax_type" => Deserialize::begin(&mut self.tax_type),
78
79                _ => <dyn Visitor>::ignore(),
80            })
81        }
82
83        fn deser_default() -> Self {
84            Self {
85                country: Deserialize::default(),
86                flat_amount: Deserialize::default(),
87                percentage_decimal: Deserialize::default(),
88                rate_type: Deserialize::default(),
89                state: Deserialize::default(),
90                tax_type: Deserialize::default(),
91            }
92        }
93
94        fn take_out(&mut self) -> Option<Self::Out> {
95            let (
96                Some(country),
97                Some(flat_amount),
98                Some(percentage_decimal),
99                Some(rate_type),
100                Some(state),
101                Some(tax_type),
102            ) = (
103                self.country.take(),
104                self.flat_amount.take(),
105                self.percentage_decimal.take(),
106                self.rate_type,
107                self.state.take(),
108                self.tax_type.take(),
109            )
110            else {
111                return None;
112            };
113            Some(Self::Out { country, flat_amount, percentage_decimal, rate_type, state, tax_type })
114        }
115    }
116
117    impl Map for Builder<'_> {
118        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
119            self.builder.key(k)
120        }
121
122        fn finish(&mut self) -> Result<()> {
123            *self.out = self.builder.take_out();
124            Ok(())
125        }
126    }
127
128    impl ObjectDeser for TaxProductResourceTaxRateDetails {
129        type Builder = TaxProductResourceTaxRateDetailsBuilder;
130    }
131
132    impl FromValueOpt for TaxProductResourceTaxRateDetails {
133        fn from_value(v: Value) -> Option<Self> {
134            let Value::Object(obj) = v else {
135                return None;
136            };
137            let mut b = TaxProductResourceTaxRateDetailsBuilder::deser_default();
138            for (k, v) in obj {
139                match k.as_str() {
140                    "country" => b.country = FromValueOpt::from_value(v),
141                    "flat_amount" => b.flat_amount = FromValueOpt::from_value(v),
142                    "percentage_decimal" => b.percentage_decimal = FromValueOpt::from_value(v),
143                    "rate_type" => b.rate_type = FromValueOpt::from_value(v),
144                    "state" => b.state = FromValueOpt::from_value(v),
145                    "tax_type" => b.tax_type = FromValueOpt::from_value(v),
146
147                    _ => {}
148                }
149            }
150            b.take_out()
151        }
152    }
153};
154/// Indicates the type of tax rate applied to the taxable amount.
155/// This value can be `null` when no tax applies to the location.
156/// This field is only present for TaxRates created by Stripe Tax.
157#[derive(Copy, Clone, Eq, PartialEq)]
158pub enum TaxProductResourceTaxRateDetailsRateType {
159    FlatAmount,
160    Percentage,
161}
162impl TaxProductResourceTaxRateDetailsRateType {
163    pub fn as_str(self) -> &'static str {
164        use TaxProductResourceTaxRateDetailsRateType::*;
165        match self {
166            FlatAmount => "flat_amount",
167            Percentage => "percentage",
168        }
169    }
170}
171
172impl std::str::FromStr for TaxProductResourceTaxRateDetailsRateType {
173    type Err = stripe_types::StripeParseError;
174    fn from_str(s: &str) -> Result<Self, Self::Err> {
175        use TaxProductResourceTaxRateDetailsRateType::*;
176        match s {
177            "flat_amount" => Ok(FlatAmount),
178            "percentage" => Ok(Percentage),
179            _ => Err(stripe_types::StripeParseError),
180        }
181    }
182}
183impl std::fmt::Display for TaxProductResourceTaxRateDetailsRateType {
184    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185        f.write_str(self.as_str())
186    }
187}
188
189impl std::fmt::Debug for TaxProductResourceTaxRateDetailsRateType {
190    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
191        f.write_str(self.as_str())
192    }
193}
194#[cfg(feature = "serialize")]
195impl serde::Serialize for TaxProductResourceTaxRateDetailsRateType {
196    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
197    where
198        S: serde::Serializer,
199    {
200        serializer.serialize_str(self.as_str())
201    }
202}
203impl miniserde::Deserialize for TaxProductResourceTaxRateDetailsRateType {
204    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
205        crate::Place::new(out)
206    }
207}
208
209impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxRateDetailsRateType> {
210    fn string(&mut self, s: &str) -> miniserde::Result<()> {
211        use std::str::FromStr;
212        self.out = Some(
213            TaxProductResourceTaxRateDetailsRateType::from_str(s).map_err(|_| miniserde::Error)?,
214        );
215        Ok(())
216    }
217}
218
219stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxRateDetailsRateType);
220#[cfg(feature = "deserialize")]
221impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxRateDetailsRateType {
222    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
223        use std::str::FromStr;
224        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
225        Self::from_str(&s).map_err(|_| {
226            serde::de::Error::custom("Unknown value for TaxProductResourceTaxRateDetailsRateType")
227        })
228    }
229}
230/// The tax type, such as `vat` or `sales_tax`.
231#[derive(Clone, Eq, PartialEq)]
232#[non_exhaustive]
233pub enum TaxProductResourceTaxRateDetailsTaxType {
234    AmusementTax,
235    CommunicationsTax,
236    Gst,
237    Hst,
238    Igst,
239    Jct,
240    LeaseTax,
241    Pst,
242    Qst,
243    RetailDeliveryFee,
244    Rst,
245    SalesTax,
246    ServiceTax,
247    Vat,
248    /// An unrecognized value from Stripe. Should not be used as a request parameter.
249    Unknown(String),
250}
251impl TaxProductResourceTaxRateDetailsTaxType {
252    pub fn as_str(&self) -> &str {
253        use TaxProductResourceTaxRateDetailsTaxType::*;
254        match self {
255            AmusementTax => "amusement_tax",
256            CommunicationsTax => "communications_tax",
257            Gst => "gst",
258            Hst => "hst",
259            Igst => "igst",
260            Jct => "jct",
261            LeaseTax => "lease_tax",
262            Pst => "pst",
263            Qst => "qst",
264            RetailDeliveryFee => "retail_delivery_fee",
265            Rst => "rst",
266            SalesTax => "sales_tax",
267            ServiceTax => "service_tax",
268            Vat => "vat",
269            Unknown(v) => v,
270        }
271    }
272}
273
274impl std::str::FromStr for TaxProductResourceTaxRateDetailsTaxType {
275    type Err = std::convert::Infallible;
276    fn from_str(s: &str) -> Result<Self, Self::Err> {
277        use TaxProductResourceTaxRateDetailsTaxType::*;
278        match s {
279            "amusement_tax" => Ok(AmusementTax),
280            "communications_tax" => Ok(CommunicationsTax),
281            "gst" => Ok(Gst),
282            "hst" => Ok(Hst),
283            "igst" => Ok(Igst),
284            "jct" => Ok(Jct),
285            "lease_tax" => Ok(LeaseTax),
286            "pst" => Ok(Pst),
287            "qst" => Ok(Qst),
288            "retail_delivery_fee" => Ok(RetailDeliveryFee),
289            "rst" => Ok(Rst),
290            "sales_tax" => Ok(SalesTax),
291            "service_tax" => Ok(ServiceTax),
292            "vat" => Ok(Vat),
293            v => Ok(Unknown(v.to_owned())),
294        }
295    }
296}
297impl std::fmt::Display for TaxProductResourceTaxRateDetailsTaxType {
298    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
299        f.write_str(self.as_str())
300    }
301}
302
303impl std::fmt::Debug for TaxProductResourceTaxRateDetailsTaxType {
304    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
305        f.write_str(self.as_str())
306    }
307}
308#[cfg(feature = "serialize")]
309impl serde::Serialize for TaxProductResourceTaxRateDetailsTaxType {
310    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
311    where
312        S: serde::Serializer,
313    {
314        serializer.serialize_str(self.as_str())
315    }
316}
317impl miniserde::Deserialize for TaxProductResourceTaxRateDetailsTaxType {
318    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
319        crate::Place::new(out)
320    }
321}
322
323impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxRateDetailsTaxType> {
324    fn string(&mut self, s: &str) -> miniserde::Result<()> {
325        use std::str::FromStr;
326        self.out = Some(TaxProductResourceTaxRateDetailsTaxType::from_str(s).unwrap());
327        Ok(())
328    }
329}
330
331stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxRateDetailsTaxType);
332#[cfg(feature = "deserialize")]
333impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxRateDetailsTaxType {
334    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
335        use std::str::FromStr;
336        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
337        Ok(Self::from_str(&s).unwrap())
338    }
339}