stripe_shared/
payment_pages_checkout_session_consent_collection.rs

1#[derive(Copy, 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
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                payment_method_reuse_agreement: Deserialize::default(),
77                promotions: Deserialize::default(),
78                terms_of_service: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (Some(payment_method_reuse_agreement), Some(promotions), Some(terms_of_service)) =
84                (self.payment_method_reuse_agreement, self.promotions, self.terms_of_service)
85            else {
86                return None;
87            };
88            Some(Self::Out { payment_method_reuse_agreement, promotions, terms_of_service })
89        }
90    }
91
92    impl Map for Builder<'_> {
93        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
94            self.builder.key(k)
95        }
96
97        fn finish(&mut self) -> Result<()> {
98            *self.out = self.builder.take_out();
99            Ok(())
100        }
101    }
102
103    impl ObjectDeser for PaymentPagesCheckoutSessionConsentCollection {
104        type Builder = PaymentPagesCheckoutSessionConsentCollectionBuilder;
105    }
106
107    impl FromValueOpt for PaymentPagesCheckoutSessionConsentCollection {
108        fn from_value(v: Value) -> Option<Self> {
109            let Value::Object(obj) = v else {
110                return None;
111            };
112            let mut b = PaymentPagesCheckoutSessionConsentCollectionBuilder::deser_default();
113            for (k, v) in obj {
114                match k.as_str() {
115                    "payment_method_reuse_agreement" => {
116                        b.payment_method_reuse_agreement = FromValueOpt::from_value(v)
117                    }
118                    "promotions" => b.promotions = FromValueOpt::from_value(v),
119                    "terms_of_service" => b.terms_of_service = FromValueOpt::from_value(v),
120
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(Copy, Clone, Eq, PartialEq)]
133pub enum PaymentPagesCheckoutSessionConsentCollectionPromotions {
134    Auto,
135    None,
136}
137impl PaymentPagesCheckoutSessionConsentCollectionPromotions {
138    pub fn as_str(self) -> &'static str {
139        use PaymentPagesCheckoutSessionConsentCollectionPromotions::*;
140        match self {
141            Auto => "auto",
142            None => "none",
143        }
144    }
145}
146
147impl std::str::FromStr for PaymentPagesCheckoutSessionConsentCollectionPromotions {
148    type Err = stripe_types::StripeParseError;
149    fn from_str(s: &str) -> Result<Self, Self::Err> {
150        use PaymentPagesCheckoutSessionConsentCollectionPromotions::*;
151        match s {
152            "auto" => Ok(Auto),
153            "none" => Ok(None),
154            _ => Err(stripe_types::StripeParseError),
155        }
156    }
157}
158impl std::fmt::Display for PaymentPagesCheckoutSessionConsentCollectionPromotions {
159    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
160        f.write_str(self.as_str())
161    }
162}
163
164impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentCollectionPromotions {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169#[cfg(feature = "serialize")]
170impl serde::Serialize for PaymentPagesCheckoutSessionConsentCollectionPromotions {
171    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
172    where
173        S: serde::Serializer,
174    {
175        serializer.serialize_str(self.as_str())
176    }
177}
178impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentCollectionPromotions {
179    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
180        crate::Place::new(out)
181    }
182}
183
184impl miniserde::de::Visitor
185    for crate::Place<PaymentPagesCheckoutSessionConsentCollectionPromotions>
186{
187    fn string(&mut self, s: &str) -> miniserde::Result<()> {
188        use std::str::FromStr;
189        self.out = Some(
190            PaymentPagesCheckoutSessionConsentCollectionPromotions::from_str(s)
191                .map_err(|_| miniserde::Error)?,
192        );
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(PaymentPagesCheckoutSessionConsentCollectionPromotions);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentCollectionPromotions {
200    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
201        use std::str::FromStr;
202        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
203        Self::from_str(&s).map_err(|_| {
204            serde::de::Error::custom(
205                "Unknown value for PaymentPagesCheckoutSessionConsentCollectionPromotions",
206            )
207        })
208    }
209}
210/// If set to `required`, it requires customers to accept the terms of service before being able to pay.
211#[derive(Copy, Clone, Eq, PartialEq)]
212pub enum PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
213    None,
214    Required,
215}
216impl PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
217    pub fn as_str(self) -> &'static str {
218        use PaymentPagesCheckoutSessionConsentCollectionTermsOfService::*;
219        match self {
220            None => "none",
221            Required => "required",
222        }
223    }
224}
225
226impl std::str::FromStr for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
227    type Err = stripe_types::StripeParseError;
228    fn from_str(s: &str) -> Result<Self, Self::Err> {
229        use PaymentPagesCheckoutSessionConsentCollectionTermsOfService::*;
230        match s {
231            "none" => Ok(None),
232            "required" => Ok(Required),
233            _ => Err(stripe_types::StripeParseError),
234        }
235    }
236}
237impl std::fmt::Display for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
238    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
239        f.write_str(self.as_str())
240    }
241}
242
243impl std::fmt::Debug for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
244    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
245        f.write_str(self.as_str())
246    }
247}
248#[cfg(feature = "serialize")]
249impl serde::Serialize for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
250    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
251    where
252        S: serde::Serializer,
253    {
254        serializer.serialize_str(self.as_str())
255    }
256}
257impl miniserde::Deserialize for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
258    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
259        crate::Place::new(out)
260    }
261}
262
263impl miniserde::de::Visitor
264    for crate::Place<PaymentPagesCheckoutSessionConsentCollectionTermsOfService>
265{
266    fn string(&mut self, s: &str) -> miniserde::Result<()> {
267        use std::str::FromStr;
268        self.out = Some(
269            PaymentPagesCheckoutSessionConsentCollectionTermsOfService::from_str(s)
270                .map_err(|_| miniserde::Error)?,
271        );
272        Ok(())
273    }
274}
275
276stripe_types::impl_from_val_with_from_str!(
277    PaymentPagesCheckoutSessionConsentCollectionTermsOfService
278);
279#[cfg(feature = "deserialize")]
280impl<'de> serde::Deserialize<'de> for PaymentPagesCheckoutSessionConsentCollectionTermsOfService {
281    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
282        use std::str::FromStr;
283        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
284        Self::from_str(&s).map_err(|_| {
285            serde::de::Error::custom(
286                "Unknown value for PaymentPagesCheckoutSessionConsentCollectionTermsOfService",
287            )
288        })
289    }
290}