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::{make_place, Deserialize, Result};
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
74                _ => <dyn Visitor>::ignore(),
75            })
76        }
77
78        fn deser_default() -> Self {
79            Self {
80                disabled_reason: Deserialize::default(),
81                enabled: Deserialize::default(),
82                liability: Deserialize::default(),
83                provider: Deserialize::default(),
84                status: Deserialize::default(),
85            }
86        }
87
88        fn take_out(&mut self) -> Option<Self::Out> {
89            let (
90                Some(disabled_reason),
91                Some(enabled),
92                Some(liability),
93                Some(provider),
94                Some(status),
95            ) = (
96                self.disabled_reason,
97                self.enabled,
98                self.liability.take(),
99                self.provider.take(),
100                self.status,
101            )
102            else {
103                return None;
104            };
105            Some(Self::Out { disabled_reason, enabled, liability, provider, status })
106        }
107    }
108
109    impl<'a> Map for Builder<'a> {
110        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
111            self.builder.key(k)
112        }
113
114        fn finish(&mut self) -> Result<()> {
115            *self.out = self.builder.take_out();
116            Ok(())
117        }
118    }
119
120    impl ObjectDeser for AutomaticTax {
121        type Builder = AutomaticTaxBuilder;
122    }
123
124    impl FromValueOpt for AutomaticTax {
125        fn from_value(v: Value) -> Option<Self> {
126            let Value::Object(obj) = v else {
127                return None;
128            };
129            let mut b = AutomaticTaxBuilder::deser_default();
130            for (k, v) in obj {
131                match k.as_str() {
132                    "disabled_reason" => b.disabled_reason = FromValueOpt::from_value(v),
133                    "enabled" => b.enabled = FromValueOpt::from_value(v),
134                    "liability" => b.liability = FromValueOpt::from_value(v),
135                    "provider" => b.provider = FromValueOpt::from_value(v),
136                    "status" => b.status = FromValueOpt::from_value(v),
137
138                    _ => {}
139                }
140            }
141            b.take_out()
142        }
143    }
144};
145/// If Stripe disabled automatic tax, this enum describes why.
146#[derive(Copy, Clone, Eq, PartialEq)]
147pub enum AutomaticTaxDisabledReason {
148    FinalizationRequiresLocationInputs,
149    FinalizationSystemError,
150}
151impl AutomaticTaxDisabledReason {
152    pub fn as_str(self) -> &'static str {
153        use AutomaticTaxDisabledReason::*;
154        match self {
155            FinalizationRequiresLocationInputs => "finalization_requires_location_inputs",
156            FinalizationSystemError => "finalization_system_error",
157        }
158    }
159}
160
161impl std::str::FromStr for AutomaticTaxDisabledReason {
162    type Err = stripe_types::StripeParseError;
163    fn from_str(s: &str) -> Result<Self, Self::Err> {
164        use AutomaticTaxDisabledReason::*;
165        match s {
166            "finalization_requires_location_inputs" => Ok(FinalizationRequiresLocationInputs),
167            "finalization_system_error" => Ok(FinalizationSystemError),
168            _ => Err(stripe_types::StripeParseError),
169        }
170    }
171}
172impl std::fmt::Display for AutomaticTaxDisabledReason {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177
178impl std::fmt::Debug for AutomaticTaxDisabledReason {
179    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180        f.write_str(self.as_str())
181    }
182}
183#[cfg(feature = "serialize")]
184impl serde::Serialize for AutomaticTaxDisabledReason {
185    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
186    where
187        S: serde::Serializer,
188    {
189        serializer.serialize_str(self.as_str())
190    }
191}
192impl miniserde::Deserialize for AutomaticTaxDisabledReason {
193    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
194        crate::Place::new(out)
195    }
196}
197
198impl miniserde::de::Visitor for crate::Place<AutomaticTaxDisabledReason> {
199    fn string(&mut self, s: &str) -> miniserde::Result<()> {
200        use std::str::FromStr;
201        self.out = Some(AutomaticTaxDisabledReason::from_str(s).map_err(|_| miniserde::Error)?);
202        Ok(())
203    }
204}
205
206stripe_types::impl_from_val_with_from_str!(AutomaticTaxDisabledReason);
207#[cfg(feature = "deserialize")]
208impl<'de> serde::Deserialize<'de> for AutomaticTaxDisabledReason {
209    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
210        use std::str::FromStr;
211        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
212        Self::from_str(&s)
213            .map_err(|_| serde::de::Error::custom("Unknown value for AutomaticTaxDisabledReason"))
214    }
215}
216/// The status of the most recent automated tax calculation for this invoice.
217#[derive(Copy, Clone, Eq, PartialEq)]
218pub enum AutomaticTaxStatus {
219    Complete,
220    Failed,
221    RequiresLocationInputs,
222}
223impl AutomaticTaxStatus {
224    pub fn as_str(self) -> &'static str {
225        use AutomaticTaxStatus::*;
226        match self {
227            Complete => "complete",
228            Failed => "failed",
229            RequiresLocationInputs => "requires_location_inputs",
230        }
231    }
232}
233
234impl std::str::FromStr for AutomaticTaxStatus {
235    type Err = stripe_types::StripeParseError;
236    fn from_str(s: &str) -> Result<Self, Self::Err> {
237        use AutomaticTaxStatus::*;
238        match s {
239            "complete" => Ok(Complete),
240            "failed" => Ok(Failed),
241            "requires_location_inputs" => Ok(RequiresLocationInputs),
242            _ => Err(stripe_types::StripeParseError),
243        }
244    }
245}
246impl std::fmt::Display for AutomaticTaxStatus {
247    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
248        f.write_str(self.as_str())
249    }
250}
251
252impl std::fmt::Debug for AutomaticTaxStatus {
253    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
254        f.write_str(self.as_str())
255    }
256}
257#[cfg(feature = "serialize")]
258impl serde::Serialize for AutomaticTaxStatus {
259    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
260    where
261        S: serde::Serializer,
262    {
263        serializer.serialize_str(self.as_str())
264    }
265}
266impl miniserde::Deserialize for AutomaticTaxStatus {
267    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
268        crate::Place::new(out)
269    }
270}
271
272impl miniserde::de::Visitor for crate::Place<AutomaticTaxStatus> {
273    fn string(&mut self, s: &str) -> miniserde::Result<()> {
274        use std::str::FromStr;
275        self.out = Some(AutomaticTaxStatus::from_str(s).map_err(|_| miniserde::Error)?);
276        Ok(())
277    }
278}
279
280stripe_types::impl_from_val_with_from_str!(AutomaticTaxStatus);
281#[cfg(feature = "deserialize")]
282impl<'de> serde::Deserialize<'de> for AutomaticTaxStatus {
283    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
284        use std::str::FromStr;
285        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
286        Self::from_str(&s)
287            .map_err(|_| serde::de::Error::custom("Unknown value for AutomaticTaxStatus"))
288    }
289}