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