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