stripe_shared/
automatic_tax.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct AutomaticTax {
5    /// If Stripe disabled automatic tax, this enum describes why.
6    pub disabled_reason: Option<AutomaticTaxDisabledReason>,
7    /// Whether Stripe automatically computes tax on this invoice.
8    /// Note that incompatible invoice items (invoice items with manually specified [tax rates](https://stripe.com/docs/api/tax_rates), negative amounts, or `tax_behavior=unspecified`) cannot be added to automatic tax invoices.
9    pub enabled: bool,
10    /// The account that's liable for tax.
11    /// If set, the business address and tax registrations required to perform the tax calculation are loaded from this account.
12    /// The tax transaction is returned in the report of the connected account.
13    pub liability: Option<stripe_shared::ConnectAccountReference>,
14    /// The tax provider powering automatic tax.
15    pub provider: Option<String>,
16    /// The status of the most recent automated tax calculation for this invoice.
17    pub status: Option<AutomaticTaxStatus>,
18}
19#[doc(hidden)]
20pub struct AutomaticTaxBuilder {
21    disabled_reason: Option<Option<AutomaticTaxDisabledReason>>,
22    enabled: Option<bool>,
23    liability: Option<Option<stripe_shared::ConnectAccountReference>>,
24    provider: Option<Option<String>>,
25    status: Option<Option<AutomaticTaxStatus>>,
26}
27
28#[allow(
29    unused_variables,
30    irrefutable_let_patterns,
31    clippy::let_unit_value,
32    clippy::match_single_binding,
33    clippy::single_match
34)]
35const _: () = {
36    use miniserde::de::{Map, Visitor};
37    use miniserde::json::Value;
38    use miniserde::{Deserialize, Result, make_place};
39    use stripe_types::miniserde_helpers::FromValueOpt;
40    use stripe_types::{MapBuilder, ObjectDeser};
41
42    make_place!(Place);
43
44    impl Deserialize for AutomaticTax {
45        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
46            Place::new(out)
47        }
48    }
49
50    struct Builder<'a> {
51        out: &'a mut Option<AutomaticTax>,
52        builder: AutomaticTaxBuilder,
53    }
54
55    impl Visitor for Place<AutomaticTax> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: AutomaticTaxBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for AutomaticTaxBuilder {
65        type Out = AutomaticTax;
66        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
67            Ok(match k {
68                "disabled_reason" => Deserialize::begin(&mut self.disabled_reason),
69                "enabled" => Deserialize::begin(&mut self.enabled),
70                "liability" => Deserialize::begin(&mut self.liability),
71                "provider" => Deserialize::begin(&mut self.provider),
72                "status" => Deserialize::begin(&mut self.status),
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self {
79                disabled_reason: Deserialize::default(),
80                enabled: Deserialize::default(),
81                liability: Deserialize::default(),
82                provider: Deserialize::default(),
83                status: Deserialize::default(),
84            }
85        }
86
87        fn take_out(&mut self) -> Option<Self::Out> {
88            let (
89                Some(disabled_reason),
90                Some(enabled),
91                Some(liability),
92                Some(provider),
93                Some(status),
94            ) = (
95                self.disabled_reason,
96                self.enabled,
97                self.liability.take(),
98                self.provider.take(),
99                self.status,
100            )
101            else {
102                return None;
103            };
104            Some(Self::Out { disabled_reason, enabled, liability, provider, status })
105        }
106    }
107
108    impl Map for Builder<'_> {
109        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
110            self.builder.key(k)
111        }
112
113        fn finish(&mut self) -> Result<()> {
114            *self.out = self.builder.take_out();
115            Ok(())
116        }
117    }
118
119    impl ObjectDeser for AutomaticTax {
120        type Builder = AutomaticTaxBuilder;
121    }
122
123    impl FromValueOpt for AutomaticTax {
124        fn from_value(v: Value) -> Option<Self> {
125            let Value::Object(obj) = v else {
126                return None;
127            };
128            let mut b = AutomaticTaxBuilder::deser_default();
129            for (k, v) in obj {
130                match k.as_str() {
131                    "disabled_reason" => b.disabled_reason = FromValueOpt::from_value(v),
132                    "enabled" => b.enabled = FromValueOpt::from_value(v),
133                    "liability" => b.liability = FromValueOpt::from_value(v),
134                    "provider" => b.provider = FromValueOpt::from_value(v),
135                    "status" => b.status = FromValueOpt::from_value(v),
136                    _ => {}
137                }
138            }
139            b.take_out()
140        }
141    }
142};
143/// If Stripe disabled automatic tax, this enum describes why.
144#[derive(Copy, Clone, Eq, PartialEq)]
145pub enum AutomaticTaxDisabledReason {
146    FinalizationRequiresLocationInputs,
147    FinalizationSystemError,
148}
149impl AutomaticTaxDisabledReason {
150    pub fn as_str(self) -> &'static str {
151        use AutomaticTaxDisabledReason::*;
152        match self {
153            FinalizationRequiresLocationInputs => "finalization_requires_location_inputs",
154            FinalizationSystemError => "finalization_system_error",
155        }
156    }
157}
158
159impl std::str::FromStr for AutomaticTaxDisabledReason {
160    type Err = stripe_types::StripeParseError;
161    fn from_str(s: &str) -> Result<Self, Self::Err> {
162        use AutomaticTaxDisabledReason::*;
163        match s {
164            "finalization_requires_location_inputs" => Ok(FinalizationRequiresLocationInputs),
165            "finalization_system_error" => Ok(FinalizationSystemError),
166            _ => Err(stripe_types::StripeParseError),
167        }
168    }
169}
170impl std::fmt::Display for AutomaticTaxDisabledReason {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175
176impl std::fmt::Debug for AutomaticTaxDisabledReason {
177    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178        f.write_str(self.as_str())
179    }
180}
181#[cfg(feature = "serialize")]
182impl serde::Serialize for AutomaticTaxDisabledReason {
183    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
184    where
185        S: serde::Serializer,
186    {
187        serializer.serialize_str(self.as_str())
188    }
189}
190impl miniserde::Deserialize for AutomaticTaxDisabledReason {
191    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
192        crate::Place::new(out)
193    }
194}
195
196impl miniserde::de::Visitor for crate::Place<AutomaticTaxDisabledReason> {
197    fn string(&mut self, s: &str) -> miniserde::Result<()> {
198        use std::str::FromStr;
199        self.out = Some(AutomaticTaxDisabledReason::from_str(s).map_err(|_| miniserde::Error)?);
200        Ok(())
201    }
202}
203
204stripe_types::impl_from_val_with_from_str!(AutomaticTaxDisabledReason);
205#[cfg(feature = "deserialize")]
206impl<'de> serde::Deserialize<'de> for AutomaticTaxDisabledReason {
207    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
208        use std::str::FromStr;
209        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
210        Self::from_str(&s)
211            .map_err(|_| serde::de::Error::custom("Unknown value for AutomaticTaxDisabledReason"))
212    }
213}
214/// The status of the most recent automated tax calculation for this invoice.
215#[derive(Copy, Clone, Eq, PartialEq)]
216pub enum AutomaticTaxStatus {
217    Complete,
218    Failed,
219    RequiresLocationInputs,
220}
221impl AutomaticTaxStatus {
222    pub fn as_str(self) -> &'static str {
223        use AutomaticTaxStatus::*;
224        match self {
225            Complete => "complete",
226            Failed => "failed",
227            RequiresLocationInputs => "requires_location_inputs",
228        }
229    }
230}
231
232impl std::str::FromStr for AutomaticTaxStatus {
233    type Err = stripe_types::StripeParseError;
234    fn from_str(s: &str) -> Result<Self, Self::Err> {
235        use AutomaticTaxStatus::*;
236        match s {
237            "complete" => Ok(Complete),
238            "failed" => Ok(Failed),
239            "requires_location_inputs" => Ok(RequiresLocationInputs),
240            _ => Err(stripe_types::StripeParseError),
241        }
242    }
243}
244impl std::fmt::Display for AutomaticTaxStatus {
245    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
246        f.write_str(self.as_str())
247    }
248}
249
250impl std::fmt::Debug for AutomaticTaxStatus {
251    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
252        f.write_str(self.as_str())
253    }
254}
255#[cfg(feature = "serialize")]
256impl serde::Serialize for AutomaticTaxStatus {
257    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
258    where
259        S: serde::Serializer,
260    {
261        serializer.serialize_str(self.as_str())
262    }
263}
264impl miniserde::Deserialize for AutomaticTaxStatus {
265    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
266        crate::Place::new(out)
267    }
268}
269
270impl miniserde::de::Visitor for crate::Place<AutomaticTaxStatus> {
271    fn string(&mut self, s: &str) -> miniserde::Result<()> {
272        use std::str::FromStr;
273        self.out = Some(AutomaticTaxStatus::from_str(s).map_err(|_| miniserde::Error)?);
274        Ok(())
275    }
276}
277
278stripe_types::impl_from_val_with_from_str!(AutomaticTaxStatus);
279#[cfg(feature = "deserialize")]
280impl<'de> serde::Deserialize<'de> for AutomaticTaxStatus {
281    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
282        use std::str::FromStr;
283        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
284        Self::from_str(&s)
285            .map_err(|_| serde::de::Error::custom("Unknown value for AutomaticTaxStatus"))
286    }
287}