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::{make_place, Deserialize, Result};
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
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self { allow_redirects: Deserialize::default(), enabled: Deserialize::default() }
68        }
69
70        fn take_out(&mut self) -> Option<Self::Out> {
71            let (Some(allow_redirects), Some(enabled)) = (self.allow_redirects, self.enabled)
72            else {
73                return None;
74            };
75            Some(Self::Out { allow_redirects, enabled })
76        }
77    }
78
79    impl<'a> Map for Builder<'a> {
80        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81            self.builder.key(k)
82        }
83
84        fn finish(&mut self) -> Result<()> {
85            *self.out = self.builder.take_out();
86            Ok(())
87        }
88    }
89
90    impl ObjectDeser for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
91        type Builder = PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder;
92    }
93
94    impl FromValueOpt for PaymentFlowsAutomaticPaymentMethodsSetupIntent {
95        fn from_value(v: Value) -> Option<Self> {
96            let Value::Object(obj) = v else {
97                return None;
98            };
99            let mut b = PaymentFlowsAutomaticPaymentMethodsSetupIntentBuilder::deser_default();
100            for (k, v) in obj {
101                match k.as_str() {
102                    "allow_redirects" => b.allow_redirects = FromValueOpt::from_value(v),
103                    "enabled" => b.enabled = FromValueOpt::from_value(v),
104
105                    _ => {}
106                }
107            }
108            b.take_out()
109        }
110    }
111};
112/// Controls whether this SetupIntent will accept redirect-based payment methods.
113///
114/// Redirect-based payment methods may require your customer to be redirected to a payment method's app or site for authentication or additional steps.
115/// 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.
116#[derive(Copy, Clone, Eq, PartialEq)]
117pub enum PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
118    Always,
119    Never,
120}
121impl PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
122    pub fn as_str(self) -> &'static str {
123        use PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::*;
124        match self {
125            Always => "always",
126            Never => "never",
127        }
128    }
129}
130
131impl std::str::FromStr for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
132    type Err = stripe_types::StripeParseError;
133    fn from_str(s: &str) -> Result<Self, Self::Err> {
134        use PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::*;
135        match s {
136            "always" => Ok(Always),
137            "never" => Ok(Never),
138            _ => Err(stripe_types::StripeParseError),
139        }
140    }
141}
142impl std::fmt::Display for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
143    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
144        f.write_str(self.as_str())
145    }
146}
147
148impl std::fmt::Debug for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
149    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
150        f.write_str(self.as_str())
151    }
152}
153#[cfg(feature = "serialize")]
154impl serde::Serialize for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
155    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
156    where
157        S: serde::Serializer,
158    {
159        serializer.serialize_str(self.as_str())
160    }
161}
162impl miniserde::Deserialize for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
163    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
164        crate::Place::new(out)
165    }
166}
167
168impl miniserde::de::Visitor
169    for crate::Place<PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects>
170{
171    fn string(&mut self, s: &str) -> miniserde::Result<()> {
172        use std::str::FromStr;
173        self.out = Some(
174            PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects::from_str(s)
175                .map_err(|_| miniserde::Error)?,
176        );
177        Ok(())
178    }
179}
180
181stripe_types::impl_from_val_with_from_str!(
182    PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects
183);
184#[cfg(feature = "deserialize")]
185impl<'de> serde::Deserialize<'de> for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects {
186    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
187        use std::str::FromStr;
188        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
189        Self::from_str(&s).map_err(|_| {
190            serde::de::Error::custom(
191                "Unknown value for PaymentFlowsAutomaticPaymentMethodsSetupIntentAllowRedirects",
192            )
193        })
194    }
195}