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