stripe_shared/
payment_pages_checkout_session_consent_collection.rs

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