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                _ => <dyn Visitor>::ignore(),
79            })
80        }
81
82        fn deser_default() -> Self {
83            Self {
84                country: Deserialize::default(),
85                flat_amount: Deserialize::default(),
86                percentage_decimal: Deserialize::default(),
87                rate_type: Deserialize::default(),
88                state: Deserialize::default(),
89                tax_type: Deserialize::default(),
90            }
91        }
92
93        fn take_out(&mut self) -> Option<Self::Out> {
94            let (
95                Some(country),
96                Some(flat_amount),
97                Some(percentage_decimal),
98                Some(rate_type),
99                Some(state),
100                Some(tax_type),
101            ) = (
102                self.country.take(),
103                self.flat_amount.take(),
104                self.percentage_decimal.take(),
105                self.rate_type,
106                self.state.take(),
107                self.tax_type.take(),
108            )
109            else {
110                return None;
111            };
112            Some(Self::Out { country, flat_amount, percentage_decimal, rate_type, state, tax_type })
113        }
114    }
115
116    impl Map for Builder<'_> {
117        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
118            self.builder.key(k)
119        }
120
121        fn finish(&mut self) -> Result<()> {
122            *self.out = self.builder.take_out();
123            Ok(())
124        }
125    }
126
127    impl ObjectDeser for TaxProductResourceTaxRateDetails {
128        type Builder = TaxProductResourceTaxRateDetailsBuilder;
129    }
130
131    impl FromValueOpt for TaxProductResourceTaxRateDetails {
132        fn from_value(v: Value) -> Option<Self> {
133            let Value::Object(obj) = v else {
134                return None;
135            };
136            let mut b = TaxProductResourceTaxRateDetailsBuilder::deser_default();
137            for (k, v) in obj {
138                match k.as_str() {
139                    "country" => b.country = FromValueOpt::from_value(v),
140                    "flat_amount" => b.flat_amount = FromValueOpt::from_value(v),
141                    "percentage_decimal" => b.percentage_decimal = FromValueOpt::from_value(v),
142                    "rate_type" => b.rate_type = FromValueOpt::from_value(v),
143                    "state" => b.state = FromValueOpt::from_value(v),
144                    "tax_type" => b.tax_type = FromValueOpt::from_value(v),
145                    _ => {}
146                }
147            }
148            b.take_out()
149        }
150    }
151};
152/// Indicates the type of tax rate applied to the taxable amount.
153/// This value can be `null` when no tax applies to the location.
154/// This field is only present for TaxRates created by Stripe Tax.
155#[derive(Copy, Clone, Eq, PartialEq)]
156pub enum TaxProductResourceTaxRateDetailsRateType {
157    FlatAmount,
158    Percentage,
159}
160impl TaxProductResourceTaxRateDetailsRateType {
161    pub fn as_str(self) -> &'static str {
162        use TaxProductResourceTaxRateDetailsRateType::*;
163        match self {
164            FlatAmount => "flat_amount",
165            Percentage => "percentage",
166        }
167    }
168}
169
170impl std::str::FromStr for TaxProductResourceTaxRateDetailsRateType {
171    type Err = stripe_types::StripeParseError;
172    fn from_str(s: &str) -> Result<Self, Self::Err> {
173        use TaxProductResourceTaxRateDetailsRateType::*;
174        match s {
175            "flat_amount" => Ok(FlatAmount),
176            "percentage" => Ok(Percentage),
177            _ => Err(stripe_types::StripeParseError),
178        }
179    }
180}
181impl std::fmt::Display for TaxProductResourceTaxRateDetailsRateType {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.write_str(self.as_str())
184    }
185}
186
187impl std::fmt::Debug for TaxProductResourceTaxRateDetailsRateType {
188    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
189        f.write_str(self.as_str())
190    }
191}
192#[cfg(feature = "serialize")]
193impl serde::Serialize for TaxProductResourceTaxRateDetailsRateType {
194    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
195    where
196        S: serde::Serializer,
197    {
198        serializer.serialize_str(self.as_str())
199    }
200}
201impl miniserde::Deserialize for TaxProductResourceTaxRateDetailsRateType {
202    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
203        crate::Place::new(out)
204    }
205}
206
207impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxRateDetailsRateType> {
208    fn string(&mut self, s: &str) -> miniserde::Result<()> {
209        use std::str::FromStr;
210        self.out = Some(
211            TaxProductResourceTaxRateDetailsRateType::from_str(s).map_err(|_| miniserde::Error)?,
212        );
213        Ok(())
214    }
215}
216
217stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxRateDetailsRateType);
218#[cfg(feature = "deserialize")]
219impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxRateDetailsRateType {
220    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
221        use std::str::FromStr;
222        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
223        Self::from_str(&s).map_err(|_| {
224            serde::de::Error::custom("Unknown value for TaxProductResourceTaxRateDetailsRateType")
225        })
226    }
227}
228/// The tax type, such as `vat` or `sales_tax`.
229#[derive(Clone, Eq, PartialEq)]
230#[non_exhaustive]
231pub enum TaxProductResourceTaxRateDetailsTaxType {
232    AmusementTax,
233    CommunicationsTax,
234    Gst,
235    Hst,
236    Igst,
237    Jct,
238    LeaseTax,
239    Pst,
240    Qst,
241    RetailDeliveryFee,
242    Rst,
243    SalesTax,
244    ServiceTax,
245    Vat,
246    /// An unrecognized value from Stripe. Should not be used as a request parameter.
247    Unknown(String),
248}
249impl TaxProductResourceTaxRateDetailsTaxType {
250    pub fn as_str(&self) -> &str {
251        use TaxProductResourceTaxRateDetailsTaxType::*;
252        match self {
253            AmusementTax => "amusement_tax",
254            CommunicationsTax => "communications_tax",
255            Gst => "gst",
256            Hst => "hst",
257            Igst => "igst",
258            Jct => "jct",
259            LeaseTax => "lease_tax",
260            Pst => "pst",
261            Qst => "qst",
262            RetailDeliveryFee => "retail_delivery_fee",
263            Rst => "rst",
264            SalesTax => "sales_tax",
265            ServiceTax => "service_tax",
266            Vat => "vat",
267            Unknown(v) => v,
268        }
269    }
270}
271
272impl std::str::FromStr for TaxProductResourceTaxRateDetailsTaxType {
273    type Err = std::convert::Infallible;
274    fn from_str(s: &str) -> Result<Self, Self::Err> {
275        use TaxProductResourceTaxRateDetailsTaxType::*;
276        match s {
277            "amusement_tax" => Ok(AmusementTax),
278            "communications_tax" => Ok(CommunicationsTax),
279            "gst" => Ok(Gst),
280            "hst" => Ok(Hst),
281            "igst" => Ok(Igst),
282            "jct" => Ok(Jct),
283            "lease_tax" => Ok(LeaseTax),
284            "pst" => Ok(Pst),
285            "qst" => Ok(Qst),
286            "retail_delivery_fee" => Ok(RetailDeliveryFee),
287            "rst" => Ok(Rst),
288            "sales_tax" => Ok(SalesTax),
289            "service_tax" => Ok(ServiceTax),
290            "vat" => Ok(Vat),
291            v => Ok(Unknown(v.to_owned())),
292        }
293    }
294}
295impl std::fmt::Display for TaxProductResourceTaxRateDetailsTaxType {
296    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
297        f.write_str(self.as_str())
298    }
299}
300
301impl std::fmt::Debug for TaxProductResourceTaxRateDetailsTaxType {
302    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
303        f.write_str(self.as_str())
304    }
305}
306#[cfg(feature = "serialize")]
307impl serde::Serialize for TaxProductResourceTaxRateDetailsTaxType {
308    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
309    where
310        S: serde::Serializer,
311    {
312        serializer.serialize_str(self.as_str())
313    }
314}
315impl miniserde::Deserialize for TaxProductResourceTaxRateDetailsTaxType {
316    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
317        crate::Place::new(out)
318    }
319}
320
321impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxRateDetailsTaxType> {
322    fn string(&mut self, s: &str) -> miniserde::Result<()> {
323        use std::str::FromStr;
324        self.out = Some(TaxProductResourceTaxRateDetailsTaxType::from_str(s).unwrap());
325        Ok(())
326    }
327}
328
329stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxRateDetailsTaxType);
330#[cfg(feature = "deserialize")]
331impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxRateDetailsTaxType {
332    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
333        use std::str::FromStr;
334        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
335        Ok(Self::from_str(&s).unwrap())
336    }
337}