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