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.take(),
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(Clone, Eq, PartialEq)]
156#[non_exhaustive]
157pub enum TaxProductResourceTaxRateDetailsRateType {
158    FlatAmount,
159    Percentage,
160    /// An unrecognized value from Stripe. Should not be used as a request parameter.
161    Unknown(String),
162}
163impl TaxProductResourceTaxRateDetailsRateType {
164    pub fn as_str(&self) -> &str {
165        use TaxProductResourceTaxRateDetailsRateType::*;
166        match self {
167            FlatAmount => "flat_amount",
168            Percentage => "percentage",
169            Unknown(v) => v,
170        }
171    }
172}
173
174impl std::str::FromStr for TaxProductResourceTaxRateDetailsRateType {
175    type Err = std::convert::Infallible;
176    fn from_str(s: &str) -> Result<Self, Self::Err> {
177        use TaxProductResourceTaxRateDetailsRateType::*;
178        match s {
179            "flat_amount" => Ok(FlatAmount),
180            "percentage" => Ok(Percentage),
181            v => {
182                tracing::warn!(
183                    "Unknown value '{}' for enum '{}'",
184                    v,
185                    "TaxProductResourceTaxRateDetailsRateType"
186                );
187                Ok(Unknown(v.to_owned()))
188            }
189        }
190    }
191}
192impl std::fmt::Display for TaxProductResourceTaxRateDetailsRateType {
193    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
194        f.write_str(self.as_str())
195    }
196}
197
198impl std::fmt::Debug for TaxProductResourceTaxRateDetailsRateType {
199    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
200        f.write_str(self.as_str())
201    }
202}
203#[cfg(feature = "serialize")]
204impl serde::Serialize for TaxProductResourceTaxRateDetailsRateType {
205    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
206    where
207        S: serde::Serializer,
208    {
209        serializer.serialize_str(self.as_str())
210    }
211}
212impl miniserde::Deserialize for TaxProductResourceTaxRateDetailsRateType {
213    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
214        crate::Place::new(out)
215    }
216}
217
218impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxRateDetailsRateType> {
219    fn string(&mut self, s: &str) -> miniserde::Result<()> {
220        use std::str::FromStr;
221        self.out = Some(TaxProductResourceTaxRateDetailsRateType::from_str(s).expect("infallible"));
222        Ok(())
223    }
224}
225
226stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxRateDetailsRateType);
227#[cfg(feature = "deserialize")]
228impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxRateDetailsRateType {
229    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
230        use std::str::FromStr;
231        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
232        Ok(Self::from_str(&s).expect("infallible"))
233    }
234}
235/// The tax type, such as `vat` or `sales_tax`.
236#[derive(Clone, Eq, PartialEq)]
237#[non_exhaustive]
238pub enum TaxProductResourceTaxRateDetailsTaxType {
239    AmusementTax,
240    CommunicationsTax,
241    Gst,
242    Hst,
243    Igst,
244    Jct,
245    LeaseTax,
246    Pst,
247    Qst,
248    RetailDeliveryFee,
249    Rst,
250    SalesTax,
251    ServiceTax,
252    Vat,
253    /// An unrecognized value from Stripe. Should not be used as a request parameter.
254    Unknown(String),
255}
256impl TaxProductResourceTaxRateDetailsTaxType {
257    pub fn as_str(&self) -> &str {
258        use TaxProductResourceTaxRateDetailsTaxType::*;
259        match self {
260            AmusementTax => "amusement_tax",
261            CommunicationsTax => "communications_tax",
262            Gst => "gst",
263            Hst => "hst",
264            Igst => "igst",
265            Jct => "jct",
266            LeaseTax => "lease_tax",
267            Pst => "pst",
268            Qst => "qst",
269            RetailDeliveryFee => "retail_delivery_fee",
270            Rst => "rst",
271            SalesTax => "sales_tax",
272            ServiceTax => "service_tax",
273            Vat => "vat",
274            Unknown(v) => v,
275        }
276    }
277}
278
279impl std::str::FromStr for TaxProductResourceTaxRateDetailsTaxType {
280    type Err = std::convert::Infallible;
281    fn from_str(s: &str) -> Result<Self, Self::Err> {
282        use TaxProductResourceTaxRateDetailsTaxType::*;
283        match s {
284            "amusement_tax" => Ok(AmusementTax),
285            "communications_tax" => Ok(CommunicationsTax),
286            "gst" => Ok(Gst),
287            "hst" => Ok(Hst),
288            "igst" => Ok(Igst),
289            "jct" => Ok(Jct),
290            "lease_tax" => Ok(LeaseTax),
291            "pst" => Ok(Pst),
292            "qst" => Ok(Qst),
293            "retail_delivery_fee" => Ok(RetailDeliveryFee),
294            "rst" => Ok(Rst),
295            "sales_tax" => Ok(SalesTax),
296            "service_tax" => Ok(ServiceTax),
297            "vat" => Ok(Vat),
298            v => {
299                tracing::warn!(
300                    "Unknown value '{}' for enum '{}'",
301                    v,
302                    "TaxProductResourceTaxRateDetailsTaxType"
303                );
304                Ok(Unknown(v.to_owned()))
305            }
306        }
307    }
308}
309impl std::fmt::Display for TaxProductResourceTaxRateDetailsTaxType {
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 TaxProductResourceTaxRateDetailsTaxType {
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 TaxProductResourceTaxRateDetailsTaxType {
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 TaxProductResourceTaxRateDetailsTaxType {
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<TaxProductResourceTaxRateDetailsTaxType> {
336    fn string(&mut self, s: &str) -> miniserde::Result<()> {
337        use std::str::FromStr;
338        self.out = Some(TaxProductResourceTaxRateDetailsTaxType::from_str(s).expect("infallible"));
339        Ok(())
340    }
341}
342
343stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxRateDetailsTaxType);
344#[cfg(feature = "deserialize")]
345impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxRateDetailsTaxType {
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).expect("infallible"))
350    }
351}