stripe_shared/
payment_flows_automatic_payment_methods_setup_intent.rs

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