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` (succesful 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::{make_place, Deserialize, Result};
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
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self {
74                failure_reason: Deserialize::default(),
75                return_url: Deserialize::default(),
76                status: Deserialize::default(),
77                url: Deserialize::default(),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (Some(failure_reason), Some(return_url), Some(status), Some(url)) = (
83                self.failure_reason.take(),
84                self.return_url.take(),
85                self.status.take(),
86                self.url.take(),
87            ) else {
88                return None;
89            };
90            Some(Self::Out { failure_reason, return_url, status, url })
91        }
92    }
93
94    impl<'a> Map for Builder<'a> {
95        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96            self.builder.key(k)
97        }
98
99        fn finish(&mut self) -> Result<()> {
100            *self.out = self.builder.take_out();
101            Ok(())
102        }
103    }
104
105    impl ObjectDeser for SourceRedirectFlow {
106        type Builder = SourceRedirectFlowBuilder;
107    }
108
109    impl FromValueOpt for SourceRedirectFlow {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = SourceRedirectFlowBuilder::deser_default();
115            for (k, v) in obj {
116                match k.as_str() {
117                    "failure_reason" => b.failure_reason = FromValueOpt::from_value(v),
118                    "return_url" => b.return_url = FromValueOpt::from_value(v),
119                    "status" => b.status = FromValueOpt::from_value(v),
120                    "url" => b.url = FromValueOpt::from_value(v),
121
122                    _ => {}
123                }
124            }
125            b.take_out()
126        }
127    }
128};