Skip to main content

stripe_shared/
payment_pages_checkout_session_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 PaymentPagesCheckoutSessionAutomaticTax {
6    /// Indicates whether automatic tax is enabled for the session
7    pub enabled: bool,
8    /// The account that's liable for tax.
9    /// If set, the business address and tax registrations required to perform the tax calculation are loaded from this account.
10    /// The tax transaction is returned in the report of the connected account.
11    pub liability: Option<stripe_shared::ConnectAccountReference>,
12    /// The tax provider powering automatic tax.
13    pub provider: Option<String>,
14    /// The status of the most recent automated tax calculation for this session.
15    pub status: Option<PaymentPagesCheckoutSessionAutomaticTaxStatus>,
16}
17#[cfg(feature = "redact-generated-debug")]
18impl std::fmt::Debug for PaymentPagesCheckoutSessionAutomaticTax {
19    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
20        f.debug_struct("PaymentPagesCheckoutSessionAutomaticTax").finish_non_exhaustive()
21    }
22}
23#[doc(hidden)]
24pub struct PaymentPagesCheckoutSessionAutomaticTaxBuilder {
25    enabled: Option<bool>,
26    liability: Option<Option<stripe_shared::ConnectAccountReference>>,
27    provider: Option<Option<String>>,
28    status: Option<Option<PaymentPagesCheckoutSessionAutomaticTaxStatus>>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{Deserialize, Result, make_place};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for PaymentPagesCheckoutSessionAutomaticTax {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<PaymentPagesCheckoutSessionAutomaticTax>,
55        builder: PaymentPagesCheckoutSessionAutomaticTaxBuilder,
56    }
57
58    impl Visitor for Place<PaymentPagesCheckoutSessionAutomaticTax> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: PaymentPagesCheckoutSessionAutomaticTaxBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for PaymentPagesCheckoutSessionAutomaticTaxBuilder {
68        type Out = PaymentPagesCheckoutSessionAutomaticTax;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "enabled" => Deserialize::begin(&mut self.enabled),
72                "liability" => Deserialize::begin(&mut self.liability),
73                "provider" => Deserialize::begin(&mut self.provider),
74                "status" => Deserialize::begin(&mut self.status),
75                _ => <dyn Visitor>::ignore(),
76            })
77        }
78
79        fn deser_default() -> Self {
80            Self { enabled: None, liability: Some(None), provider: Some(None), status: Some(None) }
81        }
82
83        fn take_out(&mut self) -> Option<Self::Out> {
84            let (Some(enabled), Some(liability), Some(provider), Some(status)) =
85                (self.enabled, self.liability.take(), self.provider.take(), self.status.take())
86            else {
87                return None;
88            };
89            Some(Self::Out { enabled, liability, provider, status })
90        }
91    }
92
93    impl Map for Builder<'_> {
94        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
95            self.builder.key(k)
96        }
97
98        fn finish(&mut self) -> Result<()> {
99            *self.out = self.builder.take_out();
100            Ok(())
101        }
102    }
103
104    impl ObjectDeser for PaymentPagesCheckoutSessionAutomaticTax {
105        type Builder = PaymentPagesCheckoutSessionAutomaticTaxBuilder;
106    }
107
108    impl FromValueOpt for PaymentPagesCheckoutSessionAutomaticTax {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = PaymentPagesCheckoutSessionAutomaticTaxBuilder::deser_default();
114            for (k, v) in obj {
115                match k.as_str() {
116                    "enabled" => b.enabled = FromValueOpt::from_value(v),
117                    "liability" => b.liability = FromValueOpt::from_value(v),
118                    "provider" => b.provider = FromValueOpt::from_value(v),
119                    "status" => b.status = FromValueOpt::from_value(v),
120                    _ => {}
121                }
122            }
123            b.take_out()
124        }
125    }
126};
127/// The status of the most recent automated tax calculation for this session.
128#[derive(Clone, Eq, PartialEq)]
129#[non_exhaustive]
130pub enum PaymentPagesCheckoutSessionAutomaticTaxStatus {
131    Complete,
132    Failed,
133    RequiresLocationInputs,
134    /// An unrecognized value from Stripe. Should not be used as a request parameter.
135    Unknown(String),
136}
137impl PaymentPagesCheckoutSessionAutomaticTaxStatus {
138    pub fn as_str(&self) -> &str {
139        use PaymentPagesCheckoutSessionAutomaticTaxStatus::*;
140        match self {
141            Complete => "complete",
142            Failed => "failed",
143            RequiresLocationInputs => "requires_location_inputs",
144            Unknown(v) => v,
145        }
146    }
147}
148
149impl std::str::FromStr for PaymentPagesCheckoutSessionAutomaticTaxStatus {
150    type Err = std::convert::Infallible;
151    fn from_str(s: &str) -> Result<Self, Self::Err> {
152        use PaymentPagesCheckoutSessionAutomaticTaxStatus::*;
153        match s {
154            "complete" => Ok(Complete),
155            "failed" => Ok(Failed),
156            "requires_location_inputs" => Ok(RequiresLocationInputs),
157            v => {
158                tracing::warn!(
159                    "Unknown value '{}' for enum '{}'",
160                    v,
161                    "PaymentPagesCheckoutSessionAutomaticTaxStatus"
162                );
163                Ok(Unknown(v.to_owned()))
164            }
165        }
166    }
167}
168impl std::fmt::Display for PaymentPagesCheckoutSessionAutomaticTaxStatus {
169    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170        f.write_str(self.as_str())
171    }
172}
173
174#[cfg(not(feature = "redact-generated-debug"))]
175impl std::fmt::Debug for PaymentPagesCheckoutSessionAutomaticTaxStatus {
176    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177        f.write_str(self.as_str())
178    }
179}
180#[cfg(feature = "redact-generated-debug")]
181impl std::fmt::Debug for PaymentPagesCheckoutSessionAutomaticTaxStatus {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.debug_struct(stringify!(PaymentPagesCheckoutSessionAutomaticTaxStatus))
184            .finish_non_exhaustive()
185    }
186}
187#[cfg(feature = "serialize")]
188impl serde::Serialize for PaymentPagesCheckoutSessionAutomaticTaxStatus {
189    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
190    where
191        S: serde::Serializer,
192    {
193        serializer.serialize_str(self.as_str())
194    }
195}
196impl miniserde::Deserialize for PaymentPagesCheckoutSessionAutomaticTaxStatus {
197    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
198        crate::Place::new(out)
199    }
200}
201
202impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionAutomaticTaxStatus> {
203    fn string(&mut self, s: &str) -> miniserde::Result<()> {
204        use std::str::FromStr;
205        self.out =
206            Some(PaymentPagesCheckoutSessionAutomaticTaxStatus::from_str(s).expect("infallible"));
207        Ok(())
208    }
209}
210
211stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionAutomaticTaxStatus);
212#[cfg(feature = "deserialize")]
213impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionAutomaticTaxStatus {
214    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
215        use std::str::FromStr;
216        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
217        Ok(Self::from_str(&s).expect("infallible"))
218    }
219}