stripe_shared/
payment_pages_checkout_session_payment_method_reuse_agreement.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionPaymentMethodReuseAgreement {
5    /// Determines the position and visibility of the payment method reuse agreement in the UI.
6    /// When set to `auto`, Stripe's defaults will be used.
7    ///
8    /// When set to `hidden`, the payment method reuse agreement text will always be hidden in the UI.
9    pub position: PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition,
10}
11#[doc(hidden)]
12pub struct PaymentPagesCheckoutSessionPaymentMethodReuseAgreementBuilder {
13    position: Option<PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for PaymentPagesCheckoutSessionPaymentMethodReuseAgreement {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<PaymentPagesCheckoutSessionPaymentMethodReuseAgreement>,
40        builder: PaymentPagesCheckoutSessionPaymentMethodReuseAgreementBuilder,
41    }
42
43    impl Visitor for Place<PaymentPagesCheckoutSessionPaymentMethodReuseAgreement> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder:
48                    PaymentPagesCheckoutSessionPaymentMethodReuseAgreementBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for PaymentPagesCheckoutSessionPaymentMethodReuseAgreementBuilder {
54        type Out = PaymentPagesCheckoutSessionPaymentMethodReuseAgreement;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "position" => Deserialize::begin(&mut self.position),
58                _ => <dyn Visitor>::ignore(),
59            })
60        }
61
62        fn deser_default() -> Self {
63            Self { position: Deserialize::default() }
64        }
65
66        fn take_out(&mut self) -> Option<Self::Out> {
67            let (Some(position),) = (self.position.take(),) else {
68                return None;
69            };
70            Some(Self::Out { position })
71        }
72    }
73
74    impl Map for Builder<'_> {
75        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
76            self.builder.key(k)
77        }
78
79        fn finish(&mut self) -> Result<()> {
80            *self.out = self.builder.take_out();
81            Ok(())
82        }
83    }
84
85    impl ObjectDeser for PaymentPagesCheckoutSessionPaymentMethodReuseAgreement {
86        type Builder = PaymentPagesCheckoutSessionPaymentMethodReuseAgreementBuilder;
87    }
88
89    impl FromValueOpt for PaymentPagesCheckoutSessionPaymentMethodReuseAgreement {
90        fn from_value(v: Value) -> Option<Self> {
91            let Value::Object(obj) = v else {
92                return None;
93            };
94            let mut b =
95                PaymentPagesCheckoutSessionPaymentMethodReuseAgreementBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "position" => b.position = FromValueOpt::from_value(v),
99                    _ => {}
100                }
101            }
102            b.take_out()
103        }
104    }
105};
106/// Determines the position and visibility of the payment method reuse agreement in the UI.
107/// When set to `auto`, Stripe's defaults will be used.
108///
109/// When set to `hidden`, the payment method reuse agreement text will always be hidden in the UI.
110#[derive(Clone, Eq, PartialEq)]
111#[non_exhaustive]
112pub enum PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition {
113    Auto,
114    Hidden,
115    /// An unrecognized value from Stripe. Should not be used as a request parameter.
116    Unknown(String),
117}
118impl PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition {
119    pub fn as_str(&self) -> &str {
120        use PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition::*;
121        match self {
122            Auto => "auto",
123            Hidden => "hidden",
124            Unknown(v) => v,
125        }
126    }
127}
128
129impl std::str::FromStr for PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition {
130    type Err = std::convert::Infallible;
131    fn from_str(s: &str) -> Result<Self, Self::Err> {
132        use PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition::*;
133        match s {
134            "auto" => Ok(Auto),
135            "hidden" => Ok(Hidden),
136            v => {
137                tracing::warn!(
138                    "Unknown value '{}' for enum '{}'",
139                    v,
140                    "PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition"
141                );
142                Ok(Unknown(v.to_owned()))
143            }
144        }
145    }
146}
147impl std::fmt::Display for PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition {
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.write_str(self.as_str())
150    }
151}
152
153impl std::fmt::Debug for PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition {
154    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155        f.write_str(self.as_str())
156    }
157}
158#[cfg(feature = "serialize")]
159impl serde::Serialize for PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition {
160    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
161    where
162        S: serde::Serializer,
163    {
164        serializer.serialize_str(self.as_str())
165    }
166}
167impl miniserde::Deserialize for PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition {
168    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
169        crate::Place::new(out)
170    }
171}
172
173impl miniserde::de::Visitor
174    for crate::Place<PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition>
175{
176    fn string(&mut self, s: &str) -> miniserde::Result<()> {
177        use std::str::FromStr;
178        self.out = Some(
179            PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition::from_str(s)
180                .expect("infallible"),
181        );
182        Ok(())
183    }
184}
185
186stripe_types::impl_from_val_with_from_str!(
187    PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition
188);
189#[cfg(feature = "deserialize")]
190impl<'de> serde::Deserialize<'de>
191    for PaymentPagesCheckoutSessionPaymentMethodReuseAgreementPosition
192{
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        Ok(Self::from_str(&s).expect("infallible"))
197    }
198}