Skip to main content

stripe_shared/
source_redirect_flow.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 SourceRedirectFlow {
6    /// 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).
7    /// Present only if the redirect status is `failed`.
8    pub failure_reason: Option<String>,
9    /// The URL you provide to redirect the customer to after they authenticated their payment.
10    pub return_url: String,
11    /// 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).
12    pub status: String,
13    /// The URL provided to you to redirect a customer to as part of a `redirect` authentication flow.
14    pub url: String,
15}
16#[cfg(feature = "redact-generated-debug")]
17impl std::fmt::Debug for SourceRedirectFlow {
18    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19        f.debug_struct("SourceRedirectFlow").finish_non_exhaustive()
20    }
21}
22#[doc(hidden)]
23pub struct SourceRedirectFlowBuilder {
24    failure_reason: Option<Option<String>>,
25    return_url: Option<String>,
26    status: Option<String>,
27    url: Option<String>,
28}
29
30#[allow(
31    unused_variables,
32    irrefutable_let_patterns,
33    clippy::let_unit_value,
34    clippy::match_single_binding,
35    clippy::single_match
36)]
37const _: () = {
38    use miniserde::de::{Map, Visitor};
39    use miniserde::json::Value;
40    use miniserde::{Deserialize, Result, make_place};
41    use stripe_types::miniserde_helpers::FromValueOpt;
42    use stripe_types::{MapBuilder, ObjectDeser};
43
44    make_place!(Place);
45
46    impl Deserialize for SourceRedirectFlow {
47        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
48            Place::new(out)
49        }
50    }
51
52    struct Builder<'a> {
53        out: &'a mut Option<SourceRedirectFlow>,
54        builder: SourceRedirectFlowBuilder,
55    }
56
57    impl Visitor for Place<SourceRedirectFlow> {
58        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59            Ok(Box::new(Builder {
60                out: &mut self.out,
61                builder: SourceRedirectFlowBuilder::deser_default(),
62            }))
63        }
64    }
65
66    impl MapBuilder for SourceRedirectFlowBuilder {
67        type Out = SourceRedirectFlow;
68        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
69            Ok(match k {
70                "failure_reason" => Deserialize::begin(&mut self.failure_reason),
71                "return_url" => Deserialize::begin(&mut self.return_url),
72                "status" => Deserialize::begin(&mut self.status),
73                "url" => Deserialize::begin(&mut self.url),
74                _ => <dyn Visitor>::ignore(),
75            })
76        }
77
78        fn deser_default() -> Self {
79            Self {
80                failure_reason: Deserialize::default(),
81                return_url: Deserialize::default(),
82                status: Deserialize::default(),
83                url: Deserialize::default(),
84            }
85        }
86
87        fn take_out(&mut self) -> Option<Self::Out> {
88            let (Some(failure_reason), Some(return_url), Some(status), Some(url)) = (
89                self.failure_reason.take(),
90                self.return_url.take(),
91                self.status.take(),
92                self.url.take(),
93            ) else {
94                return None;
95            };
96            Some(Self::Out { failure_reason, return_url, status, url })
97        }
98    }
99
100    impl Map for Builder<'_> {
101        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
102            self.builder.key(k)
103        }
104
105        fn finish(&mut self) -> Result<()> {
106            *self.out = self.builder.take_out();
107            Ok(())
108        }
109    }
110
111    impl ObjectDeser for SourceRedirectFlow {
112        type Builder = SourceRedirectFlowBuilder;
113    }
114
115    impl FromValueOpt for SourceRedirectFlow {
116        fn from_value(v: Value) -> Option<Self> {
117            let Value::Object(obj) = v else {
118                return None;
119            };
120            let mut b = SourceRedirectFlowBuilder::deser_default();
121            for (k, v) in obj {
122                match k.as_str() {
123                    "failure_reason" => b.failure_reason = FromValueOpt::from_value(v),
124                    "return_url" => b.return_url = FromValueOpt::from_value(v),
125                    "status" => b.status = FromValueOpt::from_value(v),
126                    "url" => b.url = FromValueOpt::from_value(v),
127                    _ => {}
128                }
129            }
130            b.take_out()
131        }
132    }
133};