Skip to main content

stripe_shared/
payment_flows_automatic_payment_methods_setup_intent.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentFlowsAutomaticPaymentMethodsSetupIntent {
6    /// Controls whether this SetupIntent will accept redirect-based payment methods.
7    ///
8    /// Redirect-based payment methods may require your customer to be redirected to a payment method's app or site for authentication or additional steps.
9    /// To [confirm](https://docs.stripe.com/api/setup_intents/confirm) this SetupIntent, you may be required to provide a `return_url` to redirect customers back to your site after they authenticate or complete the setup.
10    pub allow_redirects: Option<PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects>,
11    /// Automatically calculates compatible payment methods
12    pub enabled: Option<bool>,
13}
14#[cfg(feature = "redact-generated-debug")]
15impl std::fmt::Debug for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
16    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17        f.debug_struct("PaymentFlowsAutomaticPaymentMethodsSetupIntent").finish_non_exhaustive()
18    }
19}
20#[doc(hidden)]
21pub struct PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder {
22    allow_redirects: Option<Option<PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects>>,
23    enabled: Option<Option<bool>>,
24}
25
26#[allow(
27    unused_variables,
28    irrefutable_let_patterns,
29    clippy::let_unit_value,
30    clippy::match_single_binding,
31    clippy::single_match
32)]
33const _: () = {
34    use miniserde::de::{Map, Visitor};
35    use miniserde::json::Value;
36    use miniserde::{Deserialize, Result, make_place};
37    use stripe_types::miniserde_helpers::FromValueOpt;
38    use stripe_types::{MapBuilder, ObjectDeser};
39
40    make_place!(Place);
41
42    impl Deserialize for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
43        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
44            Place::new(out)
45        }
46    }
47
48    struct Builder<'a> {
49        out: &'a mut Option<PaymentFlowsAutomaticPaymentMethodsSetupIntent>,
50        builder: PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder,
51    }
52
53    impl Visitor for Place<PaymentFlowsAutomaticPaymentMethodsSetupIntent> {
54        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
55            Ok(Box::new(Builder {
56                out: &mut self.out,
57                builder: PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder::deser_default(),
58            }))
59        }
60    }
61
62    impl MapBuilder for PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder {
63        type Out = PaymentFlowsAutomaticPaymentMethodsSetupIntent;
64        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
65            Ok(match k {
66                "allow_redirects" => Deserialize::begin(&mut self.allow_redirects),
67                "enabled" => Deserialize::begin(&mut self.enabled),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self { allow_redirects: Deserialize::default(), enabled: Deserialize::default() }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(allow_redirects), Some(enabled)) =
78                (self.allow_redirects.take(), self.enabled)
79            else {
80                return None;
81            };
82            Some(Self::Out { allow_redirects, enabled })
83        }
84    }
85
86    impl Map for Builder<'_> {
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            self.builder.key(k)
89        }
90
91        fn finish(&mut self) -> Result<()> {
92            *self.out = self.builder.take_out();
93            Ok(())
94        }
95    }
96
97    impl ObjectDeser for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
98        type Builder = PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder;
99    }
100
101    impl FromValueOpt for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "allow_redirects" => b.allow_redirects = FromValueOpt::from_value(v),
110                    "enabled" => b.enabled = FromValueOpt::from_value(v),
111                    _ => {}
112                }
113            }
114            b.take_out()
115        }
116    }
117};
118/// Controls whether this SetupIntent will accept redirect-based payment methods.
119///
120/// Redirect-based payment methods may require your customer to be redirected to a payment method's app or site for authentication or additional steps.
121/// To [confirm](https://docs.stripe.com/api/setup_intents/confirm) this SetupIntent, you may be required to provide a `return_url` to redirect customers back to your site after they authenticate or complete the setup.
122#[derive(Clone, Eq, PartialEq)]
123#[non_exhaustive]
124pub enum PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
125    Always,
126    Never,
127    /// An unrecognized value from Stripe. Should not be used as a request parameter.
128    Unknown(String),
129}
130impl PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
131    pub fn as_str(&self) -> &str {
132        use PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::*;
133        match self {
134            Always => "always",
135            Never => "never",
136            Unknown(v) => v,
137        }
138    }
139}
140
141impl std::str::FromStr for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
142    type Err = std::convert::Infallible;
143    fn from_str(s: &str) -> Result<Self, Self::Err> {
144        use PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::*;
145        match s {
146            "always" => Ok(Always),
147            "never" => Ok(Never),
148            v => {
149                tracing::warn!(
150                    "Unknown value '{}' for enum '{}'",
151                    v,
152                    "PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects"
153                );
154                Ok(Unknown(v.to_owned()))
155            }
156        }
157    }
158}
159impl std::fmt::Display for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164
165#[cfg(not(feature = "redact-generated-debug"))]
166impl std::fmt::Debug for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171#[cfg(feature = "redact-generated-debug")]
172impl std::fmt::Debug for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.debug_struct(stringify!(PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects))
175            .finish_non_exhaustive()
176    }
177}
178#[cfg(feature = "serialize")]
179impl serde::Serialize for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
180    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
181    where
182        S: serde::Serializer,
183    {
184        serializer.serialize_str(self.as_str())
185    }
186}
187impl miniserde::Deserialize for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
188    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
189        crate::Place::new(out)
190    }
191}
192
193impl miniserde::de::Visitor
194    for crate::Place<PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects>
195{
196    fn string(&mut self, s: &str) -> miniserde::Result<()> {
197        use std::str::FromStr;
198        self.out = Some(
199            PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::from_str(s)
200                .expect("infallible"),
201        );
202        Ok(())
203    }
204}
205
206stripe_types::impl_from_val_with_from_str!(
207    PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects
208);
209#[cfg(feature = "deserialize")]
210impl<'de> serde::Deserialize<'de> for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
211    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
212        use std::str::FromStr;
213        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
214        Ok(Self::from_str(&s).expect("infallible"))
215    }
216}