Skip to main content

stripe_shared/
subscription_automatic_tax.rs

1#[derive(Clone)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct SubscriptionAutomaticTax {
6    /// If Stripe disabled automatic tax, this enum describes why.
7    pub disabled_reason: Option<SubscriptionAutomaticTaxDisabledReason>,
8    /// Whether Stripe automatically computes tax on this subscription.
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}
15#[cfg(feature = "redact-generated-debug")]
16impl std::fmt::Debug for SubscriptionAutomaticTax {
17    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
18        f.debug_struct("SubscriptionAutomaticTax").finish_non_exhaustive()
19    }
20}
21#[doc(hidden)]
22pub struct SubscriptionAutomaticTaxBuilder {
23    disabled_reason: Option<Option<SubscriptionAutomaticTaxDisabledReason>>,
24    enabled: Option<bool>,
25    liability: Option<Option<stripe_shared::ConnectAccountReference>>,
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 SubscriptionAutomaticTax {
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<SubscriptionAutomaticTax>,
52        builder: SubscriptionAutomaticTaxBuilder,
53    }
54
55    impl Visitor for Place<SubscriptionAutomaticTax> {
56        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
57            Ok(Box::new(Builder {
58                out: &mut self.out,
59                builder: SubscriptionAutomaticTaxBuilder::deser_default(),
60            }))
61        }
62    }
63
64    impl MapBuilder for SubscriptionAutomaticTaxBuilder {
65        type Out = SubscriptionAutomaticTax;
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                _ => <dyn Visitor>::ignore(),
72            })
73        }
74
75        fn deser_default() -> Self {
76            Self { disabled_reason: Some(None), enabled: None, liability: Some(None) }
77        }
78
79        fn take_out(&mut self) -> Option<Self::Out> {
80            let (Some(disabled_reason), Some(enabled), Some(liability)) =
81                (self.disabled_reason.take(), self.enabled, self.liability.take())
82            else {
83                return None;
84            };
85            Some(Self::Out { disabled_reason, enabled, liability })
86        }
87    }
88
89    impl Map for Builder<'_> {
90        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
91            self.builder.key(k)
92        }
93
94        fn finish(&mut self) -> Result<()> {
95            *self.out = self.builder.take_out();
96            Ok(())
97        }
98    }
99
100    impl ObjectDeser for SubscriptionAutomaticTax {
101        type Builder = SubscriptionAutomaticTaxBuilder;
102    }
103
104    impl FromValueOpt for SubscriptionAutomaticTax {
105        fn from_value(v: Value) -> Option<Self> {
106            let Value::Object(obj) = v else {
107                return None;
108            };
109            let mut b = SubscriptionAutomaticTaxBuilder::deser_default();
110            for (k, v) in obj {
111                match k.as_str() {
112                    "disabled_reason" => b.disabled_reason = FromValueOpt::from_value(v),
113                    "enabled" => b.enabled = FromValueOpt::from_value(v),
114                    "liability" => b.liability = FromValueOpt::from_value(v),
115                    _ => {}
116                }
117            }
118            b.take_out()
119        }
120    }
121};
122/// If Stripe disabled automatic tax, this enum describes why.
123#[derive(Clone, Eq, PartialEq)]
124#[non_exhaustive]
125pub enum SubscriptionAutomaticTaxDisabledReason {
126    RequiresLocationInputs,
127    /// An unrecognized value from Stripe. Should not be used as a request parameter.
128    Unknown(String),
129}
130impl SubscriptionAutomaticTaxDisabledReason {
131    pub fn as_str(&self) -> &str {
132        use SubscriptionAutomaticTaxDisabledReason::*;
133        match self {
134            RequiresLocationInputs => "requires_location_inputs",
135            Unknown(v) => v,
136        }
137    }
138}
139
140impl std::str::FromStr for SubscriptionAutomaticTaxDisabledReason {
141    type Err = std::convert::Infallible;
142    fn from_str(s: &str) -> Result<Self, Self::Err> {
143        use SubscriptionAutomaticTaxDisabledReason::*;
144        match s {
145            "requires_location_inputs" => Ok(RequiresLocationInputs),
146            v => {
147                tracing::warn!(
148                    "Unknown value '{}' for enum '{}'",
149                    v,
150                    "SubscriptionAutomaticTaxDisabledReason"
151                );
152                Ok(Unknown(v.to_owned()))
153            }
154        }
155    }
156}
157impl std::fmt::Display for SubscriptionAutomaticTaxDisabledReason {
158    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159        f.write_str(self.as_str())
160    }
161}
162
163#[cfg(not(feature = "redact-generated-debug"))]
164impl std::fmt::Debug for SubscriptionAutomaticTaxDisabledReason {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169#[cfg(feature = "redact-generated-debug")]
170impl std::fmt::Debug for SubscriptionAutomaticTaxDisabledReason {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.debug_struct(stringify!(SubscriptionAutomaticTaxDisabledReason)).finish_non_exhaustive()
173    }
174}
175#[cfg(feature = "serialize")]
176impl serde::Serialize for SubscriptionAutomaticTaxDisabledReason {
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 SubscriptionAutomaticTaxDisabledReason {
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<SubscriptionAutomaticTaxDisabledReason> {
191    fn string(&mut self, s: &str) -> miniserde::Result<()> {
192        use std::str::FromStr;
193        self.out = Some(SubscriptionAutomaticTaxDisabledReason::from_str(s).expect("infallible"));
194        Ok(())
195    }
196}
197
198stripe_types::impl_from_val_with_from_str!(SubscriptionAutomaticTaxDisabledReason);
199#[cfg(feature = "deserialize")]
200impl<'de> serde::Deserialize<'de> for SubscriptionAutomaticTaxDisabledReason {
201    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
202        use std::str::FromStr;
203        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
204        Ok(Self::from_str(&s).expect("infallible"))
205    }
206}