stripe_shared/
setup_intent_next_action.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SetupIntentNextAction {
5    pub cashapp_handle_redirect_or_display_qr_code:
6        Option<stripe_shared::PaymentIntentNextActionCashappHandleRedirectOrDisplayQrCode>,
7    pub redirect_to_url: Option<stripe_shared::SetupIntentNextActionRedirectToUrl>,
8    /// Type of the next action to perform.
9    /// Refer to the other child attributes under `next_action` for available values.
10    /// Examples include: `redirect_to_url`, `use_stripe_sdk`, `alipay_handle_redirect`, `oxxo_display_details`, or `verify_with_microdeposits`.
11    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
12    pub type_: String,
13    /// When confirming a SetupIntent with Stripe.js, Stripe.js depends on the contents of this dictionary to invoke authentication flows.
14    /// The shape of the contents is subject to change and is only intended to be used by Stripe.js.
15    #[cfg_attr(
16        any(feature = "deserialize", feature = "serialize"),
17        serde(with = "stripe_types::with_serde_json_opt")
18    )]
19    pub use_stripe_sdk: Option<miniserde::json::Value>,
20    pub verify_with_microdeposits:
21        Option<stripe_shared::SetupIntentNextActionVerifyWithMicrodeposits>,
22}
23#[doc(hidden)]
24pub struct SetupIntentNextActionBuilder {
25    cashapp_handle_redirect_or_display_qr_code:
26        Option<Option<stripe_shared::PaymentIntentNextActionCashappHandleRedirectOrDisplayQrCode>>,
27    redirect_to_url: Option<Option<stripe_shared::SetupIntentNextActionRedirectToUrl>>,
28    type_: Option<String>,
29    use_stripe_sdk: Option<Option<miniserde::json::Value>>,
30    verify_with_microdeposits:
31        Option<Option<stripe_shared::SetupIntentNextActionVerifyWithMicrodeposits>>,
32}
33
34#[allow(
35    unused_variables,
36    irrefutable_let_patterns,
37    clippy::let_unit_value,
38    clippy::match_single_binding,
39    clippy::single_match
40)]
41const _: () = {
42    use miniserde::de::{Map, Visitor};
43    use miniserde::json::Value;
44    use miniserde::{Deserialize, Result, make_place};
45    use stripe_types::miniserde_helpers::FromValueOpt;
46    use stripe_types::{MapBuilder, ObjectDeser};
47
48    make_place!(Place);
49
50    impl Deserialize for SetupIntentNextAction {
51        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
52            Place::new(out)
53        }
54    }
55
56    struct Builder<'a> {
57        out: &'a mut Option<SetupIntentNextAction>,
58        builder: SetupIntentNextActionBuilder,
59    }
60
61    impl Visitor for Place<SetupIntentNextAction> {
62        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
63            Ok(Box::new(Builder {
64                out: &mut self.out,
65                builder: SetupIntentNextActionBuilder::deser_default(),
66            }))
67        }
68    }
69
70    impl MapBuilder for SetupIntentNextActionBuilder {
71        type Out = SetupIntentNextAction;
72        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
73            Ok(match k {
74                "cashapp_handle_redirect_or_display_qr_code" => {
75                    Deserialize::begin(&mut self.cashapp_handle_redirect_or_display_qr_code)
76                }
77                "redirect_to_url" => Deserialize::begin(&mut self.redirect_to_url),
78                "type" => Deserialize::begin(&mut self.type_),
79                "use_stripe_sdk" => Deserialize::begin(&mut self.use_stripe_sdk),
80                "verify_with_microdeposits" => {
81                    Deserialize::begin(&mut self.verify_with_microdeposits)
82                }
83                _ => <dyn Visitor>::ignore(),
84            })
85        }
86
87        fn deser_default() -> Self {
88            Self {
89                cashapp_handle_redirect_or_display_qr_code: Deserialize::default(),
90                redirect_to_url: Deserialize::default(),
91                type_: Deserialize::default(),
92                use_stripe_sdk: Deserialize::default(),
93                verify_with_microdeposits: Deserialize::default(),
94            }
95        }
96
97        fn take_out(&mut self) -> Option<Self::Out> {
98            let (
99                Some(cashapp_handle_redirect_or_display_qr_code),
100                Some(redirect_to_url),
101                Some(type_),
102                Some(use_stripe_sdk),
103                Some(verify_with_microdeposits),
104            ) = (
105                self.cashapp_handle_redirect_or_display_qr_code.take(),
106                self.redirect_to_url.take(),
107                self.type_.take(),
108                self.use_stripe_sdk.take(),
109                self.verify_with_microdeposits.take(),
110            )
111            else {
112                return None;
113            };
114            Some(Self::Out {
115                cashapp_handle_redirect_or_display_qr_code,
116                redirect_to_url,
117                type_,
118                use_stripe_sdk,
119                verify_with_microdeposits,
120            })
121        }
122    }
123
124    impl Map for Builder<'_> {
125        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
126            self.builder.key(k)
127        }
128
129        fn finish(&mut self) -> Result<()> {
130            *self.out = self.builder.take_out();
131            Ok(())
132        }
133    }
134
135    impl ObjectDeser for SetupIntentNextAction {
136        type Builder = SetupIntentNextActionBuilder;
137    }
138
139    impl FromValueOpt for SetupIntentNextAction {
140        fn from_value(v: Value) -> Option<Self> {
141            let Value::Object(obj) = v else {
142                return None;
143            };
144            let mut b = SetupIntentNextActionBuilder::deser_default();
145            for (k, v) in obj {
146                match k.as_str() {
147                    "cashapp_handle_redirect_or_display_qr_code" => {
148                        b.cashapp_handle_redirect_or_display_qr_code = FromValueOpt::from_value(v)
149                    }
150                    "redirect_to_url" => b.redirect_to_url = FromValueOpt::from_value(v),
151                    "type" => b.type_ = FromValueOpt::from_value(v),
152                    "use_stripe_sdk" => b.use_stripe_sdk = FromValueOpt::from_value(v),
153                    "verify_with_microdeposits" => {
154                        b.verify_with_microdeposits = FromValueOpt::from_value(v)
155                    }
156                    _ => {}
157                }
158            }
159            b.take_out()
160        }
161    }
162};