Skip to main content

stripe_shared/
payment_pages_checkout_session_consent_collection.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentPagesCheckoutSessionConsentCollection {
6    /// If set to `hidden`, it will hide legal text related to the reuse of a payment method.
7    pub payment_method_reuse_agreement:
8        Option<stripe_shared::PaymentPagesCheckoutSessionPaymentMethodReuseAgreement>,
9    /// If set to `auto`, enables the collection of customer consent for promotional communications.
10    /// The Checkout.
11    /// Session will determine whether to display an option to opt into promotional communication
12    /// from the merchant depending on the customer's locale.
13    /// Only available to US merchants and US customers.
14    pub promotions: Option<PaymentPagesCheckoutSessionConsentCollectionPromotions>,
15    /// If set to `required`, it requires customers to accept the terms of service before being able to pay.
16    pub terms_of_service: Option<PaymentPagesCheckoutSessionConsentCollectionTermsOfService>,
17}
18#[cfg(feature = "redact-generated-debug")]
19impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentCollection {
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        f.debug_struct("PaymentPagesCheckoutSessionConsentCollection").finish_non_exhaustive()
22    }
23}
24#[doc(hidden)]
25pub struct PaymentPagesCheckoutSessionConsentCollectionBuilder {
26    payment_method_reuse_agreement:
27        Option<Option<stripe_shared::PaymentPagesCheckoutSessionPaymentMethodReuseAgreement>>,
28    promotions: Option<Option<PaymentPagesCheckoutSessionConsentCollectionPromotions>>,
29    terms_of_service: Option<Option<PaymentPagesCheckoutSessionConsentCollectionTermsOfService>>,
30}
31
32#[allow(
33    unused_variables,
34    irrefutable_let_patterns,
35    clippy::let_unit_value,
36    clippy::match_single_binding,
37    clippy::single_match
38)]
39const _: () = {
40    use miniserde::de::{Map, Visitor};
41    use miniserde::json::Value;
42    use miniserde::{Deserialize, Result, make_place};
43    use stripe_types::miniserde_helpers::FromValueOpt;
44    use stripe_types::{MapBuilder, ObjectDeser};
45
46    make_place!(Place);
47
48    impl Deserialize for PaymentPagesCheckoutSessionConsentCollection {
49        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50            Place::new(out)
51        }
52    }
53
54    struct Builder<'a> {
55        out: &'a mut Option<PaymentPagesCheckoutSessionConsentCollection>,
56        builder: PaymentPagesCheckoutSessionConsentCollectionBuilder,
57    }
58
59    impl Visitor for Place<PaymentPagesCheckoutSessionConsentCollection> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: PaymentPagesCheckoutSessionConsentCollectionBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for PaymentPagesCheckoutSessionConsentCollectionBuilder {
69        type Out = PaymentPagesCheckoutSessionConsentCollection;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "payment_method_reuse_agreement" => {
73                    Deserialize::begin(&mut self.payment_method_reuse_agreement)
74                }
75                "promotions" => Deserialize::begin(&mut self.promotions),
76                "terms_of_service" => Deserialize::begin(&mut self.terms_of_service),
77                _ => <dyn Visitor>::ignore(),
78            })
79        }
80
81        fn deser_default() -> Self {
82            Self {
83                payment_method_reuse_agreement: Some(None),
84                promotions: Some(None),
85                terms_of_service: Some(None),
86            }
87        }
88
89        fn take_out(&mut self) -> Option<Self::Out> {
90            let (Some(payment_method_reuse_agreement), Some(promotions), Some(terms_of_service)) = (
91                self.payment_method_reuse_agreement.take(),
92                self.promotions.take(),
93                self.terms_of_service.take(),
94            ) else {
95                return None;
96            };
97            Some(Self::Out { payment_method_reuse_agreement, promotions, terms_of_service })
98        }
99    }
100
101    impl Map for Builder<'_> {
102        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
103            self.builder.key(k)
104        }
105
106        fn finish(&mut self) -> Result<()> {
107            *self.out = self.builder.take_out();
108            Ok(())
109        }
110    }
111
112    impl ObjectDeser for PaymentPagesCheckoutSessionConsentCollection {
113        type Builder = PaymentPagesCheckoutSessionConsentCollectionBuilder;
114    }
115
116    impl FromValueOpt for PaymentPagesCheckoutSessionConsentCollection {
117        fn from_value(v: Value) -> Option<Self> {
118            let Value::Object(obj) = v else {
119                return None;
120            };
121            let mut b = PaymentPagesCheckoutSessionConsentCollectionBuilder::deser_default();
122            for (k, v) in obj {
123                match k.as_str() {
124                    "payment_method_reuse_agreement" => {
125                        b.payment_method_reuse_agreement = FromValueOpt::from_value(v)
126                    }
127                    "promotions" => b.promotions = FromValueOpt::from_value(v),
128                    "terms_of_service" => b.terms_of_service = FromValueOpt::from_value(v),
129                    _ => {}
130                }
131            }
132            b.take_out()
133        }
134    }
135};
136/// If set to `auto`, enables the collection of customer consent for promotional communications.
137/// The Checkout.
138/// Session will determine whether to display an option to opt into promotional communication
139/// from the merchant depending on the customer's locale.
140/// Only available to US merchants and US customers.
141#[derive(Clone, Eq, PartialEq)]
142#[non_exhaustive]
143pub enum PaymentPagesCheckoutSessionConsentCollectionPromotions {
144    Auto,
145    None,
146    /// An unrecognized value from Stripe. Should not be used as a request parameter.
147    Unknown(String),
148}
149impl PaymentPagesCheckoutSessionConsentCollectionPromotions {
150    pub fn as_str(&self) -> &str {
151        use PaymentPagesCheckoutSessionConsentCollectionPromotions::*;
152        match self {
153            Auto => "auto",
154            None => "none",
155            Unknown(v) => v,
156        }
157    }
158}
159
160impl std::str::FromStr for PaymentPagesCheckoutSessionConsentCollectionPromotions {
161    type Err = std::convert::Infallible;
162    fn from_str(s: &str) -> Result<Self, Self::Err> {
163        use PaymentPagesCheckoutSessionConsentCollectionPromotions::*;
164        match s {
165            "auto" => Ok(Auto),
166            "none" => Ok(None),
167            v => {
168                tracing::warn!(
169                    "Unknown value '{}' for enum '{}'",
170                    v,
171                    "PaymentPagesCheckoutSessionConsentCollectionPromotions"
172                );
173                Ok(Unknown(v.to_owned()))
174            }
175        }
176    }
177}
178impl std::fmt::Display for PaymentPagesCheckoutSessionConsentCollectionPromotions {
179    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180        f.write_str(self.as_str())
181    }
182}
183
184#[cfg(not(feature = "redact-generated-debug"))]
185impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentCollectionPromotions {
186    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
187        f.write_str(self.as_str())
188    }
189}
190#[cfg(feature = "redact-generated-debug")]
191impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentCollectionPromotions {
192    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
193        f.debug_struct(stringify!(PaymentPagesCheckoutSessionConsentCollectionPromotions))
194            .finish_non_exhaustive()
195    }
196}
197#[cfg(feature = "serialize")]
198impl serde::Serialize for PaymentPagesCheckoutSessionConsentCollectionPromotions {
199    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
200    where
201        S: serde::Serializer,
202    {
203        serializer.serialize_str(self.as_str())
204    }
205}
206impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentCollectionPromotions {
207    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
208        crate::Place::new(out)
209    }
210}
211
212impl miniserde::de::Visitor
213    for crate::Place<PaymentPagesCheckoutSessionConsentCollectionPromotions>
214{
215    fn string(&mut self, s: &str) -> miniserde::Result<()> {
216        use std::str::FromStr;
217        self.out = Some(
218            PaymentPagesCheckoutSessionConsentCollectionPromotions::from_str(s)
219                .expect("infallible"),
220        );
221        Ok(())
222    }
223}
224
225stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionConsentCollectionPromotions);
226#[cfg(feature = "deserialize")]
227impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentCollectionPromotions {
228    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
229        use std::str::FromStr;
230        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
231        Ok(Self::from_str(&s).expect("infallible"))
232    }
233}
234/// If set to `required`, it requires customers to accept the terms of service before being able to pay.
235#[derive(Clone, Eq, PartialEq)]
236#[non_exhaustive]
237pub enum PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
238    None,
239    Required,
240    /// An unrecognized value from Stripe. Should not be used as a request parameter.
241    Unknown(String),
242}
243impl PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
244    pub fn as_str(&self) -> &str {
245        use PaymentPagesCheckoutSessionConsentCollectionTermsOfService::*;
246        match self {
247            None => "none",
248            Required => "required",
249            Unknown(v) => v,
250        }
251    }
252}
253
254impl std::str::FromStr for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
255    type Err = std::convert::Infallible;
256    fn from_str(s: &str) -> Result<Self, Self::Err> {
257        use PaymentPagesCheckoutSessionConsentCollectionTermsOfService::*;
258        match s {
259            "none" => Ok(None),
260            "required" => Ok(Required),
261            v => {
262                tracing::warn!(
263                    "Unknown value '{}' for enum '{}'",
264                    v,
265                    "PaymentPagesCheckoutSessionConsentCollectionTermsOfService"
266                );
267                Ok(Unknown(v.to_owned()))
268            }
269        }
270    }
271}
272impl std::fmt::Display for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
273    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274        f.write_str(self.as_str())
275    }
276}
277
278#[cfg(not(feature = "redact-generated-debug"))]
279impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
280    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
281        f.write_str(self.as_str())
282    }
283}
284#[cfg(feature = "redact-generated-debug")]
285impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
286    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
287        f.debug_struct(stringify!(PaymentPagesCheckoutSessionConsentCollectionTermsOfService))
288            .finish_non_exhaustive()
289    }
290}
291#[cfg(feature = "serialize")]
292impl serde::Serialize for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
293    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
294    where
295        S: serde::Serializer,
296    {
297        serializer.serialize_str(self.as_str())
298    }
299}
300impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
301    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
302        crate::Place::new(out)
303    }
304}
305
306impl miniserde::de::Visitor
307    for crate::Place<PaymentPagesCheckoutSessionConsentCollectionTermsOfService>
308{
309    fn string(&mut self, s: &str) -> miniserde::Result<()> {
310        use std::str::FromStr;
311        self.out = Some(
312            PaymentPagesCheckoutSessionConsentCollectionTermsOfService::from_str(s)
313                .expect("infallible"),
314        );
315        Ok(())
316    }
317}
318
319stripe_types::impl_from_val_with_from_str!(
320    PaymentPagesCheckoutSessionConsentCollectionTermsOfService
321);
322#[cfg(feature = "deserialize")]
323impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
324    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
325        use std::str::FromStr;
326        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
327        Ok(Self::from_str(&s).expect("infallible"))
328    }
329}