stripe_shared/
payment_pages_checkout_session_consent.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionConsent {
5    /// If `opt_in`, the customer consents to receiving promotional communications
6    /// from the merchant about this Checkout Session.
7    pub promotions: Option<PaymentPagesCheckoutSessionConsentPromotions>,
8    /// If `accepted`, the customer in this Checkout Session has agreed to the merchant's terms of service.
9    pub terms_of_service: Option<PaymentPagesCheckoutSessionConsentTermsOfService>,
10}
11#[doc(hidden)]
12pub struct PaymentPagesCheckoutSessionConsentBuilder {
13    promotions: Option<Option<PaymentPagesCheckoutSessionConsentPromotions>>,
14    terms_of_service: Option<Option<PaymentPagesCheckoutSessionConsentTermsOfService>>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{Deserialize, Result, make_place};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for PaymentPagesCheckoutSessionConsent {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<PaymentPagesCheckoutSessionConsent>,
41        builder: PaymentPagesCheckoutSessionConsentBuilder,
42    }
43
44    impl Visitor for Place<PaymentPagesCheckoutSessionConsent> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: PaymentPagesCheckoutSessionConsentBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for PaymentPagesCheckoutSessionConsentBuilder {
54        type Out = PaymentPagesCheckoutSessionConsent;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "promotions" => Deserialize::begin(&mut self.promotions),
58                "terms_of_service" => Deserialize::begin(&mut self.terms_of_service),
59
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { promotions: Deserialize::default(), terms_of_service: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(promotions), Some(terms_of_service)) =
70                (self.promotions, self.terms_of_service)
71            else {
72                return None;
73            };
74            Some(Self::Out { promotions, terms_of_service })
75        }
76    }
77
78    impl Map for Builder<'_> {
79        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80            self.builder.key(k)
81        }
82
83        fn finish(&mut self) -> Result<()> {
84            *self.out = self.builder.take_out();
85            Ok(())
86        }
87    }
88
89    impl ObjectDeser for PaymentPagesCheckoutSessionConsent {
90        type Builder = PaymentPagesCheckoutSessionConsentBuilder;
91    }
92
93    impl FromValueOpt for PaymentPagesCheckoutSessionConsent {
94        fn from_value(v: Value) -> Option<Self> {
95            let Value::Object(obj) = v else {
96                return None;
97            };
98            let mut b = PaymentPagesCheckoutSessionConsentBuilder::deser_default();
99            for (k, v) in obj {
100                match k.as_str() {
101                    "promotions" => b.promotions = FromValueOpt::from_value(v),
102                    "terms_of_service" => b.terms_of_service = FromValueOpt::from_value(v),
103
104                    _ => {}
105                }
106            }
107            b.take_out()
108        }
109    }
110};
111/// If `opt_in`, the customer consents to receiving promotional communications
112/// from the merchant about this Checkout Session.
113#[derive(Copy, Clone, Eq, PartialEq)]
114pub enum PaymentPagesCheckoutSessionConsentPromotions {
115    OptIn,
116    OptOut,
117}
118impl PaymentPagesCheckoutSessionConsentPromotions {
119    pub fn as_str(self) -> &'static str {
120        use PaymentPagesCheckoutSessionConsentPromotions::*;
121        match self {
122            OptIn => "opt_in",
123            OptOut => "opt_out",
124        }
125    }
126}
127
128impl std::str::FromStr for PaymentPagesCheckoutSessionConsentPromotions {
129    type Err = stripe_types::StripeParseError;
130    fn from_str(s: &str) -> Result<Self, Self::Err> {
131        use PaymentPagesCheckoutSessionConsentPromotions::*;
132        match s {
133            "opt_in" => Ok(OptIn),
134            "opt_out" => Ok(OptOut),
135            _ => Err(stripe_types::StripeParseError),
136        }
137    }
138}
139impl std::fmt::Display for PaymentPagesCheckoutSessionConsentPromotions {
140    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141        f.write_str(self.as_str())
142    }
143}
144
145impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentPromotions {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150#[cfg(feature = "serialize")]
151impl serde::Serialize for PaymentPagesCheckoutSessionConsentPromotions {
152    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
153    where
154        S: serde::Serializer,
155    {
156        serializer.serialize_str(self.as_str())
157    }
158}
159impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentPromotions {
160    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
161        crate::Place::new(out)
162    }
163}
164
165impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionConsentPromotions> {
166    fn string(&mut self, s: &str) -> miniserde::Result<()> {
167        use std::str::FromStr;
168        self.out = Some(
169            PaymentPagesCheckoutSessionConsentPromotions::from_str(s)
170                .map_err(|_| miniserde::Error)?,
171        );
172        Ok(())
173    }
174}
175
176stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionConsentPromotions);
177#[cfg(feature = "deserialize")]
178impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentPromotions {
179    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
180        use std::str::FromStr;
181        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
182        Self::from_str(&s).map_err(|_| {
183            serde::de::Error::custom(
184                "Unknown value for PaymentPagesCheckoutSessionConsentPromotions",
185            )
186        })
187    }
188}
189/// If `accepted`, the customer in this Checkout Session has agreed to the merchant's terms of service.
190#[derive(Copy, Clone, Eq, PartialEq)]
191pub enum PaymentPagesCheckoutSessionConsentTermsOfService {
192    Accepted,
193}
194impl PaymentPagesCheckoutSessionConsentTermsOfService {
195    pub fn as_str(self) -> &'static str {
196        use PaymentPagesCheckoutSessionConsentTermsOfService::*;
197        match self {
198            Accepted => "accepted",
199        }
200    }
201}
202
203impl std::str::FromStr for PaymentPagesCheckoutSessionConsentTermsOfService {
204    type Err = stripe_types::StripeParseError;
205    fn from_str(s: &str) -> Result<Self, Self::Err> {
206        use PaymentPagesCheckoutSessionConsentTermsOfService::*;
207        match s {
208            "accepted" => Ok(Accepted),
209            _ => Err(stripe_types::StripeParseError),
210        }
211    }
212}
213impl std::fmt::Display for PaymentPagesCheckoutSessionConsentTermsOfService {
214    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
215        f.write_str(self.as_str())
216    }
217}
218
219impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentTermsOfService {
220    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
221        f.write_str(self.as_str())
222    }
223}
224#[cfg(feature = "serialize")]
225impl serde::Serialize for PaymentPagesCheckoutSessionConsentTermsOfService {
226    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
227    where
228        S: serde::Serializer,
229    {
230        serializer.serialize_str(self.as_str())
231    }
232}
233impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentTermsOfService {
234    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
235        crate::Place::new(out)
236    }
237}
238
239impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionConsentTermsOfService> {
240    fn string(&mut self, s: &str) -> miniserde::Result<()> {
241        use std::str::FromStr;
242        self.out = Some(
243            PaymentPagesCheckoutSessionConsentTermsOfService::from_str(s)
244                .map_err(|_| miniserde::Error)?,
245        );
246        Ok(())
247    }
248}
249
250stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionConsentTermsOfService);
251#[cfg(feature = "deserialize")]
252impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentTermsOfService {
253    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
254        use std::str::FromStr;
255        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
256        Self::from_str(&s).map_err(|_| {
257            serde::de::Error::custom(
258                "Unknown value for PaymentPagesCheckoutSessionConsentTermsOfService",
259            )
260        })
261    }
262}