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