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