stripe_shared/
subscription_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 SubscriptionAutomaticTax {
5    /// If Stripe disabled automatic tax, this enum describes why.
6    pub disabled_reason: Option<SubscriptionAutomaticTaxDisabledReason>,
7    /// Whether Stripe automatically computes tax on this subscription.
8    pub enabled: bool,
9    /// The account that's liable for tax.
10    /// If set, the business address and tax registrations required to perform the tax calculation are loaded from this account.
11    /// The tax transaction is returned in the report of the connected account.
12    pub liability: Option<stripe_shared::ConnectAccountReference>,
13}
14#[doc(hidden)]
15pub struct SubscriptionAutomaticTaxBuilder {
16    disabled_reason: Option<Option<SubscriptionAutomaticTaxDisabledReason>>,
17    enabled: Option<bool>,
18    liability: Option<Option<stripe_shared::ConnectAccountReference>>,
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 SubscriptionAutomaticTax {
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<SubscriptionAutomaticTax>,
45        builder: SubscriptionAutomaticTaxBuilder,
46    }
47
48    impl Visitor for Place<SubscriptionAutomaticTax> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: SubscriptionAutomaticTaxBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for SubscriptionAutomaticTaxBuilder {
58        type Out = SubscriptionAutomaticTax;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "disabled_reason" => Deserialize::begin(&mut self.disabled_reason),
62                "enabled" => Deserialize::begin(&mut self.enabled),
63                "liability" => Deserialize::begin(&mut self.liability),
64
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                disabled_reason: Deserialize::default(),
72                enabled: Deserialize::default(),
73                liability: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(disabled_reason), Some(enabled), Some(liability)) =
79                (self.disabled_reason, self.enabled, self.liability.take())
80            else {
81                return None;
82            };
83            Some(Self::Out { disabled_reason, enabled, liability })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for SubscriptionAutomaticTax {
99        type Builder = SubscriptionAutomaticTaxBuilder;
100    }
101
102    impl FromValueOpt for SubscriptionAutomaticTax {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = SubscriptionAutomaticTaxBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "disabled_reason" => b.disabled_reason = FromValueOpt::from_value(v),
111                    "enabled" => b.enabled = FromValueOpt::from_value(v),
112                    "liability" => b.liability = FromValueOpt::from_value(v),
113
114                    _ => {}
115                }
116            }
117            b.take_out()
118        }
119    }
120};
121/// If Stripe disabled automatic tax, this enum describes why.
122#[derive(Copy, Clone, Eq, PartialEq)]
123pub enum SubscriptionAutomaticTaxDisabledReason {
124    RequiresLocationInputs,
125}
126impl SubscriptionAutomaticTaxDisabledReason {
127    pub fn as_str(self) -> &'static str {
128        use SubscriptionAutomaticTaxDisabledReason::*;
129        match self {
130            RequiresLocationInputs => "requires_location_inputs",
131        }
132    }
133}
134
135impl std::str::FromStr for SubscriptionAutomaticTaxDisabledReason {
136    type Err = stripe_types::StripeParseError;
137    fn from_str(s: &str) -> Result<Self, Self::Err> {
138        use SubscriptionAutomaticTaxDisabledReason::*;
139        match s {
140            "requires_location_inputs" => Ok(RequiresLocationInputs),
141            _ => Err(stripe_types::StripeParseError),
142        }
143    }
144}
145impl std::fmt::Display for SubscriptionAutomaticTaxDisabledReason {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150
151impl std::fmt::Debug for SubscriptionAutomaticTaxDisabledReason {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156#[cfg(feature = "serialize")]
157impl serde::Serialize for SubscriptionAutomaticTaxDisabledReason {
158    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
159    where
160        S: serde::Serializer,
161    {
162        serializer.serialize_str(self.as_str())
163    }
164}
165impl miniserde::Deserialize for SubscriptionAutomaticTaxDisabledReason {
166    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
167        crate::Place::new(out)
168    }
169}
170
171impl miniserde::de::Visitor for crate::Place<SubscriptionAutomaticTaxDisabledReason> {
172    fn string(&mut self, s: &str) -> miniserde::Result<()> {
173        use std::str::FromStr;
174        self.out = Some(
175            SubscriptionAutomaticTaxDisabledReason::from_str(s).map_err(|_| miniserde::Error)?,
176        );
177        Ok(())
178    }
179}
180
181stripe_types::impl_from_val_with_from_str!(SubscriptionAutomaticTaxDisabledReason);
182#[cfg(feature = "deserialize")]
183impl<'de> serde::Deserialize<'de> for SubscriptionAutomaticTaxDisabledReason {
184    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
185        use std::str::FromStr;
186        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
187        Self::from_str(&s).map_err(|_| {
188            serde::de::Error::custom("Unknown value for SubscriptionAutomaticTaxDisabledReason")
189        })
190    }
191}