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::{make_place, Deserialize, Result};
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
84                _ => <dyn Visitor>::ignore(),
85            })
86        }
87
88        fn deser_default() -> Self {
89            Self {
90                cashapp_handle_redirect_or_display_qr_code: Deserialize::default(),
91                redirect_to_url: Deserialize::default(),
92                type_: Deserialize::default(),
93                use_stripe_sdk: Deserialize::default(),
94                verify_with_microdeposits: Deserialize::default(),
95            }
96        }
97
98        fn take_out(&mut self) -> Option<Self::Out> {
99            let (
100                Some(cashapp_handle_redirect_or_display_qr_code),
101                Some(redirect_to_url),
102                Some(type_),
103                Some(use_stripe_sdk),
104                Some(verify_with_microdeposits),
105            ) = (
106                self.cashapp_handle_redirect_or_display_qr_code.take(),
107                self.redirect_to_url.take(),
108                self.type_.take(),
109                self.use_stripe_sdk.take(),
110                self.verify_with_microdeposits.take(),
111            )
112            else {
113                return None;
114            };
115            Some(Self::Out {
116                cashapp_handle_redirect_or_display_qr_code,
117                redirect_to_url,
118                type_,
119                use_stripe_sdk,
120                verify_with_microdeposits,
121            })
122        }
123    }
124
125    impl Map for Builder<'_> {
126        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
127            self.builder.key(k)
128        }
129
130        fn finish(&mut self) -> Result<()> {
131            *self.out = self.builder.take_out();
132            Ok(())
133        }
134    }
135
136    impl ObjectDeser for SetupIntentNextAction {
137        type Builder = SetupIntentNextActionBuilder;
138    }
139
140    impl FromValueOpt for SetupIntentNextAction {
141        fn from_value(v: Value) -> Option<Self> {
142            let Value::Object(obj) = v else {
143                return None;
144            };
145            let mut b = SetupIntentNextActionBuilder::deser_default();
146            for (k, v) in obj {
147                match k.as_str() {
148                    "cashapp_handle_redirect_or_display_qr_code" => {
149                        b.cashapp_handle_redirect_or_display_qr_code = FromValueOpt::from_value(v)
150                    }
151                    "redirect_to_url" => b.redirect_to_url = FromValueOpt::from_value(v),
152                    "type" => b.type_ = FromValueOpt::from_value(v),
153                    "use_stripe_sdk" => b.use_stripe_sdk = FromValueOpt::from_value(v),
154                    "verify_with_microdeposits" => {
155                        b.verify_with_microdeposits = FromValueOpt::from_value(v)
156                    }
157
158                    _ => {}
159                }
160            }
161            b.take_out()
162        }
163    }
164};