stripe_misc/
tax_product_resource_tax_settings_defaults.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxProductResourceTaxSettingsDefaults {
5    /// The tax calculation provider this account uses.
6    /// Defaults to `stripe` when not using a [third-party provider](/tax/third-party-apps).
7    pub provider: TaxProductResourceTaxSettingsDefaultsProvider,
8    /// Default [tax behavior](https://stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#tax-behavior) used to specify whether the price is considered inclusive of taxes or exclusive of taxes.
9    /// If the item's price has a tax behavior set, it will take precedence over the default tax behavior.
10    pub tax_behavior: Option<TaxProductResourceTaxSettingsDefaultsTaxBehavior>,
11    /// Default [tax code](https://stripe.com/docs/tax/tax-categories) used to classify your products and prices.
12    pub tax_code: Option<String>,
13}
14#[doc(hidden)]
15pub struct TaxProductResourceTaxSettingsDefaultsBuilder {
16    provider: Option<TaxProductResourceTaxSettingsDefaultsProvider>,
17    tax_behavior: Option<Option<TaxProductResourceTaxSettingsDefaultsTaxBehavior>>,
18    tax_code: Option<Option<String>>,
19}
20
21#[allow(
22    unused_variables,
23    irrefutable_let_patterns,
24    clippy::let_unit_value,
25    clippy::match_single_binding,
26    clippy::single_match
27)]
28const _: () = {
29    use miniserde::de::{Map, Visitor};
30    use miniserde::json::Value;
31    use miniserde::{Deserialize, Result, make_place};
32    use stripe_types::miniserde_helpers::FromValueOpt;
33    use stripe_types::{MapBuilder, ObjectDeser};
34
35    make_place!(Place);
36
37    impl Deserialize for TaxProductResourceTaxSettingsDefaults {
38        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39            Place::new(out)
40        }
41    }
42
43    struct Builder<'a> {
44        out: &'a mut Option<TaxProductResourceTaxSettingsDefaults>,
45        builder: TaxProductResourceTaxSettingsDefaultsBuilder,
46    }
47
48    impl Visitor for Place<TaxProductResourceTaxSettingsDefaults> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: TaxProductResourceTaxSettingsDefaultsBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for TaxProductResourceTaxSettingsDefaultsBuilder {
58        type Out = TaxProductResourceTaxSettingsDefaults;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "provider" => Deserialize::begin(&mut self.provider),
62                "tax_behavior" => Deserialize::begin(&mut self.tax_behavior),
63                "tax_code" => Deserialize::begin(&mut self.tax_code),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                provider: Deserialize::default(),
71                tax_behavior: Deserialize::default(),
72                tax_code: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(provider), Some(tax_behavior), Some(tax_code)) =
78                (self.provider.take(), self.tax_behavior.take(), self.tax_code.take())
79            else {
80                return None;
81            };
82            Some(Self::Out { provider, tax_behavior, tax_code })
83        }
84    }
85
86    impl Map for Builder<'_> {
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            self.builder.key(k)
89        }
90
91        fn finish(&mut self) -> Result<()> {
92            *self.out = self.builder.take_out();
93            Ok(())
94        }
95    }
96
97    impl ObjectDeser for TaxProductResourceTaxSettingsDefaults {
98        type Builder = TaxProductResourceTaxSettingsDefaultsBuilder;
99    }
100
101    impl FromValueOpt for TaxProductResourceTaxSettingsDefaults {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = TaxProductResourceTaxSettingsDefaultsBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "provider" => b.provider = FromValueOpt::from_value(v),
110                    "tax_behavior" => b.tax_behavior = FromValueOpt::from_value(v),
111                    "tax_code" => b.tax_code = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// The tax calculation provider this account uses.
120/// Defaults to `stripe` when not using a [third-party provider](/tax/third-party-apps).
121#[derive(Clone, Eq, PartialEq)]
122#[non_exhaustive]
123pub enum TaxProductResourceTaxSettingsDefaultsProvider {
124    Anrok,
125    Avalara,
126    Sphere,
127    Stripe,
128    /// An unrecognized value from Stripe. Should not be used as a request parameter.
129    Unknown(String),
130}
131impl TaxProductResourceTaxSettingsDefaultsProvider {
132    pub fn as_str(&self) -> &str {
133        use TaxProductResourceTaxSettingsDefaultsProvider::*;
134        match self {
135            Anrok => "anrok",
136            Avalara => "avalara",
137            Sphere => "sphere",
138            Stripe => "stripe",
139            Unknown(v) => v,
140        }
141    }
142}
143
144impl std::str::FromStr for TaxProductResourceTaxSettingsDefaultsProvider {
145    type Err = std::convert::Infallible;
146    fn from_str(s: &str) -> Result<Self, Self::Err> {
147        use TaxProductResourceTaxSettingsDefaultsProvider::*;
148        match s {
149            "anrok" => Ok(Anrok),
150            "avalara" => Ok(Avalara),
151            "sphere" => Ok(Sphere),
152            "stripe" => Ok(Stripe),
153            v => {
154                tracing::warn!(
155                    "Unknown value '{}' for enum '{}'",
156                    v,
157                    "TaxProductResourceTaxSettingsDefaultsProvider"
158                );
159                Ok(Unknown(v.to_owned()))
160            }
161        }
162    }
163}
164impl std::fmt::Display for TaxProductResourceTaxSettingsDefaultsProvider {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169
170impl std::fmt::Debug for TaxProductResourceTaxSettingsDefaultsProvider {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175#[cfg(feature = "serialize")]
176impl serde::Serialize for TaxProductResourceTaxSettingsDefaultsProvider {
177    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
178    where
179        S: serde::Serializer,
180    {
181        serializer.serialize_str(self.as_str())
182    }
183}
184impl miniserde::Deserialize for TaxProductResourceTaxSettingsDefaultsProvider {
185    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
186        crate::Place::new(out)
187    }
188}
189
190impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxSettingsDefaultsProvider> {
191    fn string(&mut self, s: &str) -> miniserde::Result<()> {
192        use std::str::FromStr;
193        self.out =
194            Some(TaxProductResourceTaxSettingsDefaultsProvider::from_str(s).expect("infallible"));
195        Ok(())
196    }
197}
198
199stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxSettingsDefaultsProvider);
200#[cfg(feature = "deserialize")]
201impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxSettingsDefaultsProvider {
202    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
203        use std::str::FromStr;
204        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
205        Ok(Self::from_str(&s).expect("infallible"))
206    }
207}
208/// Default [tax behavior](https://stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#tax-behavior) used to specify whether the price is considered inclusive of taxes or exclusive of taxes.
209/// If the item's price has a tax behavior set, it will take precedence over the default tax behavior.
210#[derive(Clone, Eq, PartialEq)]
211#[non_exhaustive]
212pub enum TaxProductResourceTaxSettingsDefaultsTaxBehavior {
213    Exclusive,
214    Inclusive,
215    InferredByCurrency,
216    /// An unrecognized value from Stripe. Should not be used as a request parameter.
217    Unknown(String),
218}
219impl TaxProductResourceTaxSettingsDefaultsTaxBehavior {
220    pub fn as_str(&self) -> &str {
221        use TaxProductResourceTaxSettingsDefaultsTaxBehavior::*;
222        match self {
223            Exclusive => "exclusive",
224            Inclusive => "inclusive",
225            InferredByCurrency => "inferred_by_currency",
226            Unknown(v) => v,
227        }
228    }
229}
230
231impl std::str::FromStr for TaxProductResourceTaxSettingsDefaultsTaxBehavior {
232    type Err = std::convert::Infallible;
233    fn from_str(s: &str) -> Result<Self, Self::Err> {
234        use TaxProductResourceTaxSettingsDefaultsTaxBehavior::*;
235        match s {
236            "exclusive" => Ok(Exclusive),
237            "inclusive" => Ok(Inclusive),
238            "inferred_by_currency" => Ok(InferredByCurrency),
239            v => {
240                tracing::warn!(
241                    "Unknown value '{}' for enum '{}'",
242                    v,
243                    "TaxProductResourceTaxSettingsDefaultsTaxBehavior"
244                );
245                Ok(Unknown(v.to_owned()))
246            }
247        }
248    }
249}
250impl std::fmt::Display for TaxProductResourceTaxSettingsDefaultsTaxBehavior {
251    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
252        f.write_str(self.as_str())
253    }
254}
255
256impl std::fmt::Debug for TaxProductResourceTaxSettingsDefaultsTaxBehavior {
257    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
258        f.write_str(self.as_str())
259    }
260}
261#[cfg(feature = "serialize")]
262impl serde::Serialize for TaxProductResourceTaxSettingsDefaultsTaxBehavior {
263    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
264    where
265        S: serde::Serializer,
266    {
267        serializer.serialize_str(self.as_str())
268    }
269}
270impl miniserde::Deserialize for TaxProductResourceTaxSettingsDefaultsTaxBehavior {
271    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
272        crate::Place::new(out)
273    }
274}
275
276impl miniserde::de::Visitor for crate::Place<TaxProductResourceTaxSettingsDefaultsTaxBehavior> {
277    fn string(&mut self, s: &str) -> miniserde::Result<()> {
278        use std::str::FromStr;
279        self.out = Some(
280            TaxProductResourceTaxSettingsDefaultsTaxBehavior::from_str(s).expect("infallible"),
281        );
282        Ok(())
283    }
284}
285
286stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxSettingsDefaultsTaxBehavior);
287#[cfg(feature = "deserialize")]
288impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxSettingsDefaultsTaxBehavior {
289    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
290        use std::str::FromStr;
291        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
292        Ok(Self::from_str(&s).expect("infallible"))
293    }
294}