stripe_shared/
payment_pages_checkout_session_tax_id_collection.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionTaxIdCollection {
5    /// Indicates whether tax ID collection is enabled for the session
6    pub enabled: bool,
7    /// Indicates whether a tax ID is required on the payment page
8    pub required: PaymentPagesCheckoutSessionTaxIdCollectionRequired,
9}
10#[doc(hidden)]
11pub struct PaymentPagesCheckoutSessionTaxIdCollectionBuilder {
12    enabled: Option<bool>,
13    required: Option<PaymentPagesCheckoutSessionTaxIdCollectionRequired>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for PaymentPagesCheckoutSessionTaxIdCollection {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<PaymentPagesCheckoutSessionTaxIdCollection>,
40        builder: PaymentPagesCheckoutSessionTaxIdCollectionBuilder,
41    }
42
43    impl Visitor for Place<PaymentPagesCheckoutSessionTaxIdCollection> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: PaymentPagesCheckoutSessionTaxIdCollectionBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for PaymentPagesCheckoutSessionTaxIdCollectionBuilder {
53        type Out = PaymentPagesCheckoutSessionTaxIdCollection;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "enabled" => Deserialize::begin(&mut self.enabled),
57                "required" => Deserialize::begin(&mut self.required),
58
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { enabled: Deserialize::default(), required: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(enabled), Some(required)) = (self.enabled, self.required) else {
69                return None;
70            };
71            Some(Self::Out { enabled, required })
72        }
73    }
74
75    impl Map for Builder<'_> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for PaymentPagesCheckoutSessionTaxIdCollection {
87        type Builder = PaymentPagesCheckoutSessionTaxIdCollectionBuilder;
88    }
89
90    impl FromValueOpt for PaymentPagesCheckoutSessionTaxIdCollection {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = PaymentPagesCheckoutSessionTaxIdCollectionBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "enabled" => b.enabled = FromValueOpt::from_value(v),
99                    "required" => b.required = FromValueOpt::from_value(v),
100
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// Indicates whether a tax ID is required on the payment page
109#[derive(Copy, Clone, Eq, PartialEq)]
110pub enum PaymentPagesCheckoutSessionTaxIdCollectionRequired {
111    IfSupported,
112    Never,
113}
114impl PaymentPagesCheckoutSessionTaxIdCollectionRequired {
115    pub fn as_str(self) -> &'static str {
116        use PaymentPagesCheckoutSessionTaxIdCollectionRequired::*;
117        match self {
118            IfSupported => "if_supported",
119            Never => "never",
120        }
121    }
122}
123
124impl std::str::FromStr for PaymentPagesCheckoutSessionTaxIdCollectionRequired {
125    type Err = stripe_types::StripeParseError;
126    fn from_str(s: &str) -> Result<Self, Self::Err> {
127        use PaymentPagesCheckoutSessionTaxIdCollectionRequired::*;
128        match s {
129            "if_supported" => Ok(IfSupported),
130            "never" => Ok(Never),
131            _ => Err(stripe_types::StripeParseError),
132        }
133    }
134}
135impl std::fmt::Display for PaymentPagesCheckoutSessionTaxIdCollectionRequired {
136    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
137        f.write_str(self.as_str())
138    }
139}
140
141impl std::fmt::Debug for PaymentPagesCheckoutSessionTaxIdCollectionRequired {
142    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
143        f.write_str(self.as_str())
144    }
145}
146#[cfg(feature = "serialize")]
147impl serde::Serialize for PaymentPagesCheckoutSessionTaxIdCollectionRequired {
148    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
149    where
150        S: serde::Serializer,
151    {
152        serializer.serialize_str(self.as_str())
153    }
154}
155impl miniserde::Deserialize for PaymentPagesCheckoutSessionTaxIdCollectionRequired {
156    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
157        crate::Place::new(out)
158    }
159}
160
161impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionTaxIdCollectionRequired> {
162    fn string(&mut self, s: &str) -> miniserde::Result<()> {
163        use std::str::FromStr;
164        self.out = Some(
165            PaymentPagesCheckoutSessionTaxIdCollectionRequired::from_str(s)
166                .map_err(|_| miniserde::Error)?,
167        );
168        Ok(())
169    }
170}
171
172stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionTaxIdCollectionRequired);
173#[cfg(feature = "deserialize")]
174impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionTaxIdCollectionRequired {
175    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
176        use std::str::FromStr;
177        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
178        Self::from_str(&s).map_err(|_| {
179            serde::de::Error::custom(
180                "Unknown value for PaymentPagesCheckoutSessionTaxIdCollectionRequired",
181            )
182        })
183    }
184}