stripe_shared/
payment_pages_checkout_session_consent.rs

1#[derive(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.take(), self.terms_of_service.take())
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(Clone, Eq, PartialEq)]
112#[non_exhaustive]
113pub enum PaymentPagesCheckoutSessionConsentPromotions {
114    OptIn,
115    OptOut,
116    /// An unrecognized value from Stripe. Should not be used as a request parameter.
117    Unknown(String),
118}
119impl PaymentPagesCheckoutSessionConsentPromotions {
120    pub fn as_str(&self) -> &str {
121        use PaymentPagesCheckoutSessionConsentPromotions::*;
122        match self {
123            OptIn => "opt_in",
124            OptOut => "opt_out",
125            Unknown(v) => v,
126        }
127    }
128}
129
130impl std::str::FromStr for PaymentPagesCheckoutSessionConsentPromotions {
131    type Err = std::convert::Infallible;
132    fn from_str(s: &str) -> Result<Self, Self::Err> {
133        use PaymentPagesCheckoutSessionConsentPromotions::*;
134        match s {
135            "opt_in" => Ok(OptIn),
136            "opt_out" => Ok(OptOut),
137            v => {
138                tracing::warn!(
139                    "Unknown value '{}' for enum '{}'",
140                    v,
141                    "PaymentPagesCheckoutSessionConsentPromotions"
142                );
143                Ok(Unknown(v.to_owned()))
144            }
145        }
146    }
147}
148impl std::fmt::Display for PaymentPagesCheckoutSessionConsentPromotions {
149    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
150        f.write_str(self.as_str())
151    }
152}
153
154impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentPromotions {
155    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156        f.write_str(self.as_str())
157    }
158}
159#[cfg(feature = "serialize")]
160impl serde::Serialize for PaymentPagesCheckoutSessionConsentPromotions {
161    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
162    where
163        S: serde::Serializer,
164    {
165        serializer.serialize_str(self.as_str())
166    }
167}
168impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentPromotions {
169    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
170        crate::Place::new(out)
171    }
172}
173
174impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionConsentPromotions> {
175    fn string(&mut self, s: &str) -> miniserde::Result<()> {
176        use std::str::FromStr;
177        self.out =
178            Some(PaymentPagesCheckoutSessionConsentPromotions::from_str(s).expect("infallible"));
179        Ok(())
180    }
181}
182
183stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionConsentPromotions);
184#[cfg(feature = "deserialize")]
185impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentPromotions {
186    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
187        use std::str::FromStr;
188        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
189        Ok(Self::from_str(&s).expect("infallible"))
190    }
191}
192/// If `accepted`, the customer in this Checkout Session has agreed to the merchant's terms of service.
193#[derive(Clone, Eq, PartialEq)]
194#[non_exhaustive]
195pub enum PaymentPagesCheckoutSessionConsentTermsOfService {
196    Accepted,
197    /// An unrecognized value from Stripe. Should not be used as a request parameter.
198    Unknown(String),
199}
200impl PaymentPagesCheckoutSessionConsentTermsOfService {
201    pub fn as_str(&self) -> &str {
202        use PaymentPagesCheckoutSessionConsentTermsOfService::*;
203        match self {
204            Accepted => "accepted",
205            Unknown(v) => v,
206        }
207    }
208}
209
210impl std::str::FromStr for PaymentPagesCheckoutSessionConsentTermsOfService {
211    type Err = std::convert::Infallible;
212    fn from_str(s: &str) -> Result<Self, Self::Err> {
213        use PaymentPagesCheckoutSessionConsentTermsOfService::*;
214        match s {
215            "accepted" => Ok(Accepted),
216            v => {
217                tracing::warn!(
218                    "Unknown value '{}' for enum '{}'",
219                    v,
220                    "PaymentPagesCheckoutSessionConsentTermsOfService"
221                );
222                Ok(Unknown(v.to_owned()))
223            }
224        }
225    }
226}
227impl std::fmt::Display for PaymentPagesCheckoutSessionConsentTermsOfService {
228    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
229        f.write_str(self.as_str())
230    }
231}
232
233impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentTermsOfService {
234    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
235        f.write_str(self.as_str())
236    }
237}
238#[cfg(feature = "serialize")]
239impl serde::Serialize for PaymentPagesCheckoutSessionConsentTermsOfService {
240    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
241    where
242        S: serde::Serializer,
243    {
244        serializer.serialize_str(self.as_str())
245    }
246}
247impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentTermsOfService {
248    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
249        crate::Place::new(out)
250    }
251}
252
253impl miniserde::de::Visitor for crate::Place<PaymentPagesCheckoutSessionConsentTermsOfService> {
254    fn string(&mut self, s: &str) -> miniserde::Result<()> {
255        use std::str::FromStr;
256        self.out = Some(
257            PaymentPagesCheckoutSessionConsentTermsOfService::from_str(s).expect("infallible"),
258        );
259        Ok(())
260    }
261}
262
263stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionConsentTermsOfService);
264#[cfg(feature = "deserialize")]
265impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentTermsOfService {
266    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
267        use std::str::FromStr;
268        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
269        Ok(Self::from_str(&s).expect("infallible"))
270    }
271}