stripe_shared/
payment_pages_checkout_session_customer_details.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionCustomerDetails {
5    /// The customer's address after a completed Checkout Session.
6    /// Note: This property is populated only for sessions on or after March 30, 2022.
7    pub address: Option<stripe_shared::Address>,
8    /// The customer's business name after a completed Checkout Session.
9    pub business_name: Option<String>,
10    /// The email associated with the Customer, if one exists, on the Checkout Session after a completed Checkout Session or at time of session expiry.
11    /// Otherwise, if the customer has consented to promotional content, this value is the most recent valid email provided by the customer on the Checkout form.
12    pub email: Option<String>,
13    /// The customer's individual name after a completed Checkout Session.
14    pub individual_name: Option<String>,
15    /// The customer's name after a completed Checkout Session.
16    /// Note: This property is populated only for sessions on or after March 30, 2022.
17    pub name: Option<String>,
18    /// The customer's phone number after a completed Checkout Session.
19    pub phone: Option<String>,
20    /// The customer’s tax exempt status after a completed Checkout Session.
21    pub tax_exempt: Option<PaymentPagesCheckoutSessionCustomerDetailsTaxExempt>,
22    /// The customer’s tax IDs after a completed Checkout Session.
23    pub tax_ids: Option<Vec<stripe_shared::PaymentPagesCheckoutSessionTaxId>>,
24}
25#[doc(hidden)]
26pub struct PaymentPagesCheckoutSessionCustomerDetailsBuilder {
27    address: Option<Option<stripe_shared::Address>>,
28    business_name: Option<Option<String>>,
29    email: Option<Option<String>>,
30    individual_name: Option<Option<String>>,
31    name: Option<Option<String>>,
32    phone: Option<Option<String>>,
33    tax_exempt: Option<Option<PaymentPagesCheckoutSessionCustomerDetailsTaxExempt>>,
34    tax_ids: Option<Option<Vec<stripe_shared::PaymentPagesCheckoutSessionTaxId>>>,
35}
36
37#[allow(
38    unused_variables,
39    irrefutable_let_patterns,
40    clippy::let_unit_value,
41    clippy::match_single_binding,
42    clippy::single_match
43)]
44const _: () = {
45    use miniserde::de::{Map, Visitor};
46    use miniserde::json::Value;
47    use miniserde::{Deserialize, Result, make_place};
48    use stripe_types::miniserde_helpers::FromValueOpt;
49    use stripe_types::{MapBuilder, ObjectDeser};
50
51    make_place!(Place);
52
53    impl Deserialize for PaymentPagesCheckoutSessionCustomerDetails {
54        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
55            Place::new(out)
56        }
57    }
58
59    struct Builder<'a> {
60        out: &'a mut Option<PaymentPagesCheckoutSessionCustomerDetails>,
61        builder: PaymentPagesCheckoutSessionCustomerDetailsBuilder,
62    }
63
64    impl Visitor for Place<PaymentPagesCheckoutSessionCustomerDetails> {
65        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
66            Ok(Box::new(Builder {
67                out: &mut self.out,
68                builder: PaymentPagesCheckoutSessionCustomerDetailsBuilder::deser_default(),
69            }))
70        }
71    }
72
73    impl MapBuilder for PaymentPagesCheckoutSessionCustomerDetailsBuilder {
74        type Out = PaymentPagesCheckoutSessionCustomerDetails;
75        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
76            Ok(match k {
77                "address" => Deserialize::begin(&mut self.address),
78                "business_name" => Deserialize::begin(&mut self.business_name),
79                "email" => Deserialize::begin(&mut self.email),
80                "individual_name" => Deserialize::begin(&mut self.individual_name),
81                "name" => Deserialize::begin(&mut self.name),
82                "phone" => Deserialize::begin(&mut self.phone),
83                "tax_exempt" => Deserialize::begin(&mut self.tax_exempt),
84                "tax_ids" => Deserialize::begin(&mut self.tax_ids),
85                _ => <dyn Visitor>::ignore(),
86            })
87        }
88
89        fn deser_default() -> Self {
90            Self {
91                address: Deserialize::default(),
92                business_name: Deserialize::default(),
93                email: Deserialize::default(),
94                individual_name: Deserialize::default(),
95                name: Deserialize::default(),
96                phone: Deserialize::default(),
97                tax_exempt: Deserialize::default(),
98                tax_ids: Deserialize::default(),
99            }
100        }
101
102        fn take_out(&mut self) -> Option<Self::Out> {
103            let (
104                Some(address),
105                Some(business_name),
106                Some(email),
107                Some(individual_name),
108                Some(name),
109                Some(phone),
110                Some(tax_exempt),
111                Some(tax_ids),
112            ) = (
113                self.address.take(),
114                self.business_name.take(),
115                self.email.take(),
116                self.individual_name.take(),
117                self.name.take(),
118                self.phone.take(),
119                self.tax_exempt.take(),
120                self.tax_ids.take(),
121            )
122            else {
123                return None;
124            };
125            Some(Self::Out {
126                address,
127                business_name,
128                email,
129                individual_name,
130                name,
131                phone,
132                tax_exempt,
133                tax_ids,
134            })
135        }
136    }
137
138    impl Map for Builder<'_> {
139        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
140            self.builder.key(k)
141        }
142
143        fn finish(&mut self) -> Result<()> {
144            *self.out = self.builder.take_out();
145            Ok(())
146        }
147    }
148
149    impl ObjectDeser for PaymentPagesCheckoutSessionCustomerDetails {
150        type Builder = PaymentPagesCheckoutSessionCustomerDetailsBuilder;
151    }
152
153    impl FromValueOpt for PaymentPagesCheckoutSessionCustomerDetails {
154        fn from_value(v: Value) -> Option<Self> {
155            let Value::Object(obj) = v else {
156                return None;
157            };
158            let mut b = PaymentPagesCheckoutSessionCustomerDetailsBuilder::deser_default();
159            for (k, v) in obj {
160                match k.as_str() {
161                    "address" => b.address = FromValueOpt::from_value(v),
162                    "business_name" => b.business_name = FromValueOpt::from_value(v),
163                    "email" => b.email = FromValueOpt::from_value(v),
164                    "individual_name" => b.individual_name = FromValueOpt::from_value(v),
165                    "name" => b.name = FromValueOpt::from_value(v),
166                    "phone" => b.phone = FromValueOpt::from_value(v),
167                    "tax_exempt" => b.tax_exempt = FromValueOpt::from_value(v),
168                    "tax_ids" => b.tax_ids = FromValueOpt::from_value(v),
169                    _ => {}
170                }
171            }
172            b.take_out()
173        }
174    }
175};
176/// The customer’s tax exempt status after a completed Checkout Session.
177#[derive(Clone, Eq, PartialEq)]
178#[non_exhaustive]
179pub enum PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
180    Exempt,
181    None,
182    Reverse,
183    /// An unrecognized value from Stripe. Should not be used as a request parameter.
184    Unknown(String),
185}
186impl PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
187    pub fn as_str(&self) -> &str {
188        use PaymentPagesCheckoutSessionCustomerDetailsTaxExempt::*;
189        match self {
190            Exempt => "exempt",
191            None => "none",
192            Reverse => "reverse",
193            Unknown(v) => v,
194        }
195    }
196}
197
198impl std::str::FromStr for PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
199    type Err = std::convert::Infallible;
200    fn from_str(s: &str) -> Result<Self, Self::Err> {
201        use PaymentPagesCheckoutSessionCustomerDetailsTaxExempt::*;
202        match s {
203            "exempt" => Ok(Exempt),
204            "none" => Ok(None),
205            "reverse" => Ok(Reverse),
206            v => {
207                tracing::warn!(
208                    "Unknown value '{}' for enum '{}'",
209                    v,
210                    "PaymentPagesCheckoutSessionCustomerDetailsTaxExempt"
211                );
212                Ok(Unknown(v.to_owned()))
213            }
214        }
215    }
216}
217impl std::fmt::Display for PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
218    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
219        f.write_str(self.as_str())
220    }
221}
222
223impl std::fmt::Debug for PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
224    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
225        f.write_str(self.as_str())
226    }
227}
228#[cfg(feature = "serialize")]
229impl serde::Serialize for PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
230    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
231    where
232        S: serde::Serializer,
233    {
234        serializer.serialize_str(self.as_str())
235    }
236}
237impl miniserde::Deserialize for PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
238    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
239        crate::Place::new(out)
240    }
241}
242
243impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionCustomerDetailsTaxExempt> {
244    fn string(&mut self, s: &str) -> miniserde::Result<()> {
245        use std::str::FromStr;
246        self.out = Some(
247            PaymentPagesCheckoutSessionCustomerDetailsTaxExempt::from_str(s).expect("infallible"),
248        );
249        Ok(())
250    }
251}
252
253stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionCustomerDetailsTaxExempt);
254#[cfg(feature = "deserialize")]
255impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionCustomerDetailsTaxExempt {
256    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
257        use std::str::FromStr;
258        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
259        Ok(Self::from_str(&s).expect("infallible"))
260    }
261}