stripe_shared/
source_redirect_flow.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SourceRedirectFlow {
5    /// The failure reason for the redirect, either `user_abort` (the customer aborted or dropped out of the redirect flow), `declined` (the authentication failed or the transaction was declined), or `processing_error` (the redirect failed due to a technical error).
6    /// Present only if the redirect status is `failed`.
7    pub failure_reason: Option<String>,
8    /// The URL you provide to redirect the customer to after they authenticated their payment.
9    pub return_url: String,
10    /// The status of the redirect, either `pending` (ready to be used by your customer to authenticate the transaction), `succeeded` (successful authentication, cannot be reused) or `not_required` (redirect should not be used) or `failed` (failed authentication, cannot be reused).
11    pub status: String,
12    /// The URL provided to you to redirect a customer to as part of a `redirect` authentication flow.
13    pub url: String,
14}
15#[doc(hidden)]
16pub struct SourceRedirectFlowBuilder {
17    failure_reason: Option<Option<String>>,
18    return_url: Option<String>,
19    status: Option<String>,
20    url: Option<String>,
21}
22
23#[allow(
24    unused_variables,
25    irrefutable_let_patterns,
26    clippy::let_unit_value,
27    clippy::match_single_binding,
28    clippy::single_match
29)]
30const _: () = {
31    use miniserde::de::{Map, Visitor};
32    use miniserde::json::Value;
33    use miniserde::{Deserialize, Result, make_place};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for SourceRedirectFlow {
40        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41            Place::new(out)
42        }
43    }
44
45    struct Builder<'a> {
46        out: &'a mut Option<SourceRedirectFlow>,
47        builder: SourceRedirectFlowBuilder,
48    }
49
50    impl Visitor for Place<SourceRedirectFlow> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: SourceRedirectFlowBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for SourceRedirectFlowBuilder {
60        type Out = SourceRedirectFlow;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "failure_reason" => Deserialize::begin(&mut self.failure_reason),
64                "return_url" => Deserialize::begin(&mut self.return_url),
65                "status" => Deserialize::begin(&mut self.status),
66                "url" => Deserialize::begin(&mut self.url),
67                _ => <dyn Visitor>::ignore(),
68            })
69        }
70
71        fn deser_default() -> Self {
72            Self {
73                failure_reason: Deserialize::default(),
74                return_url: Deserialize::default(),
75                status: Deserialize::default(),
76                url: Deserialize::default(),
77            }
78        }
79
80        fn take_out(&mut self) -> Option<Self::Out> {
81            let (Some(failure_reason), Some(return_url), Some(status), Some(url)) = (
82                self.failure_reason.take(),
83                self.return_url.take(),
84                self.status.take(),
85                self.url.take(),
86            ) else {
87                return None;
88            };
89            Some(Self::Out { failure_reason, return_url, status, url })
90        }
91    }
92
93    impl Map for Builder<'_> {
94        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
95            self.builder.key(k)
96        }
97
98        fn finish(&mut self) -> Result<()> {
99            *self.out = self.builder.take_out();
100            Ok(())
101        }
102    }
103
104    impl ObjectDeser for SourceRedirectFlow {
105        type Builder = SourceRedirectFlowBuilder;
106    }
107
108    impl FromValueOpt for SourceRedirectFlow {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = SourceRedirectFlowBuilder::deser_default();
114            for (k, v) in obj {
115                match k.as_str() {
116                    "failure_reason" => b.failure_reason = FromValueOpt::from_value(v),
117                    "return_url" => b.return_url = FromValueOpt::from_value(v),
118                    "status" => b.status = FromValueOpt::from_value(v),
119                    "url" => b.url = FromValueOpt::from_value(v),
120                    _ => {}
121                }
122            }
123            b.take_out()
124        }
125    }
126};