stripe_shared/
setup_attempt.rs

1/// A SetupAttempt describes one attempted confirmation of a SetupIntent,
2/// whether that confirmation is successful or unsuccessful. You can use
3/// SetupAttempts to inspect details of a specific attempt at setting up a
4/// payment method using a SetupIntent.
5///
6/// For more details see <<https://stripe.com/docs/api/setup_attempts/object>>.
7#[derive(Clone, Debug)]
8#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
9pub struct SetupAttempt {
10    /// The value of [application](https://stripe.com/docs/api/setup_intents/object#setup_intent_object-application) on the SetupIntent at the time of this confirmation.
11    pub application: Option<stripe_types::Expandable<stripe_shared::Application>>,
12    /// If present, the SetupIntent's payment method will be attached to the in-context Stripe Account.
13    ///
14    /// It can only be used for this Stripe Account’s own money movement flows like InboundTransfer and OutboundTransfers.
15    /// It cannot be set to true when setting up a PaymentMethod for a Customer, and defaults to false when attaching a PaymentMethod to a Customer.
16    pub attach_to_self: Option<bool>,
17    /// Time at which the object was created. Measured in seconds since the Unix epoch.
18    pub created: stripe_types::Timestamp,
19    /// The value of [customer](https://stripe.com/docs/api/setup_intents/object#setup_intent_object-customer) on the SetupIntent at the time of this confirmation.
20    pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
21    /// Indicates the directions of money movement for which this payment method is intended to be used.
22    ///
23    /// Include `inbound` if you intend to use the payment method as the origin to pull funds from.
24    /// Include `outbound` if you intend to use the payment method as the destination to send funds to.
25    /// You can include both if you intend to use the payment method for both purposes.
26    pub flow_directions: Option<Vec<SetupAttemptFlowDirections>>,
27    /// Unique identifier for the object.
28    pub id: stripe_shared::SetupAttemptId,
29    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
30    pub livemode: bool,
31    /// The value of [on_behalf_of](https://stripe.com/docs/api/setup_intents/object#setup_intent_object-on_behalf_of) on the SetupIntent at the time of this confirmation.
32    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
33    /// ID of the payment method used with this SetupAttempt.
34    pub payment_method: stripe_types::Expandable<stripe_shared::PaymentMethod>,
35    pub payment_method_details: stripe_shared::SetupAttemptPaymentMethodDetails,
36    /// The error encountered during this attempt to confirm the SetupIntent, if any.
37    pub setup_error: Option<Box<stripe_shared::ApiErrors>>,
38    /// ID of the SetupIntent that this attempt belongs to.
39    pub setup_intent: stripe_types::Expandable<stripe_shared::SetupIntent>,
40    /// Status of this SetupAttempt, one of `requires_confirmation`, `requires_action`, `processing`, `succeeded`, `failed`, or `abandoned`.
41    pub status: String,
42    /// The value of [usage](https://stripe.com/docs/api/setup_intents/object#setup_intent_object-usage) on the SetupIntent at the time of this confirmation, one of `off_session` or `on_session`.
43    pub usage: String,
44}
45#[doc(hidden)]
46pub struct SetupAttemptBuilder {
47    application: Option<Option<stripe_types::Expandable<stripe_shared::Application>>>,
48    attach_to_self: Option<Option<bool>>,
49    created: Option<stripe_types::Timestamp>,
50    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
51    flow_directions: Option<Option<Vec<SetupAttemptFlowDirections>>>,
52    id: Option<stripe_shared::SetupAttemptId>,
53    livemode: Option<bool>,
54    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
55    payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
56    payment_method_details: Option<stripe_shared::SetupAttemptPaymentMethodDetails>,
57    setup_error: Option<Option<Box<stripe_shared::ApiErrors>>>,
58    setup_intent: Option<stripe_types::Expandable<stripe_shared::SetupIntent>>,
59    status: Option<String>,
60    usage: Option<String>,
61}
62
63#[allow(
64    unused_variables,
65    irrefutable_let_patterns,
66    clippy::let_unit_value,
67    clippy::match_single_binding,
68    clippy::single_match
69)]
70const _: () = {
71    use miniserde::de::{Map, Visitor};
72    use miniserde::json::Value;
73    use miniserde::{Deserialize, Result, make_place};
74    use stripe_types::miniserde_helpers::FromValueOpt;
75    use stripe_types::{MapBuilder, ObjectDeser};
76
77    make_place!(Place);
78
79    impl Deserialize for SetupAttempt {
80        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
81            Place::new(out)
82        }
83    }
84
85    struct Builder<'a> {
86        out: &'a mut Option<SetupAttempt>,
87        builder: SetupAttemptBuilder,
88    }
89
90    impl Visitor for Place<SetupAttempt> {
91        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
92            Ok(Box::new(Builder {
93                out: &mut self.out,
94                builder: SetupAttemptBuilder::deser_default(),
95            }))
96        }
97    }
98
99    impl MapBuilder for SetupAttemptBuilder {
100        type Out = SetupAttempt;
101        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
102            Ok(match k {
103                "application" => Deserialize::begin(&mut self.application),
104                "attach_to_self" => Deserialize::begin(&mut self.attach_to_self),
105                "created" => Deserialize::begin(&mut self.created),
106                "customer" => Deserialize::begin(&mut self.customer),
107                "flow_directions" => Deserialize::begin(&mut self.flow_directions),
108                "id" => Deserialize::begin(&mut self.id),
109                "livemode" => Deserialize::begin(&mut self.livemode),
110                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
111                "payment_method" => Deserialize::begin(&mut self.payment_method),
112                "payment_method_details" => Deserialize::begin(&mut self.payment_method_details),
113                "setup_error" => Deserialize::begin(&mut self.setup_error),
114                "setup_intent" => Deserialize::begin(&mut self.setup_intent),
115                "status" => Deserialize::begin(&mut self.status),
116                "usage" => Deserialize::begin(&mut self.usage),
117                _ => <dyn Visitor>::ignore(),
118            })
119        }
120
121        fn deser_default() -> Self {
122            Self {
123                application: Deserialize::default(),
124                attach_to_self: Deserialize::default(),
125                created: Deserialize::default(),
126                customer: Deserialize::default(),
127                flow_directions: Deserialize::default(),
128                id: Deserialize::default(),
129                livemode: Deserialize::default(),
130                on_behalf_of: Deserialize::default(),
131                payment_method: Deserialize::default(),
132                payment_method_details: Deserialize::default(),
133                setup_error: Deserialize::default(),
134                setup_intent: Deserialize::default(),
135                status: Deserialize::default(),
136                usage: Deserialize::default(),
137            }
138        }
139
140        fn take_out(&mut self) -> Option<Self::Out> {
141            let (
142                Some(application),
143                Some(attach_to_self),
144                Some(created),
145                Some(customer),
146                Some(flow_directions),
147                Some(id),
148                Some(livemode),
149                Some(on_behalf_of),
150                Some(payment_method),
151                Some(payment_method_details),
152                Some(setup_error),
153                Some(setup_intent),
154                Some(status),
155                Some(usage),
156            ) = (
157                self.application.take(),
158                self.attach_to_self,
159                self.created,
160                self.customer.take(),
161                self.flow_directions.take(),
162                self.id.take(),
163                self.livemode,
164                self.on_behalf_of.take(),
165                self.payment_method.take(),
166                self.payment_method_details.take(),
167                self.setup_error.take(),
168                self.setup_intent.take(),
169                self.status.take(),
170                self.usage.take(),
171            )
172            else {
173                return None;
174            };
175            Some(Self::Out {
176                application,
177                attach_to_self,
178                created,
179                customer,
180                flow_directions,
181                id,
182                livemode,
183                on_behalf_of,
184                payment_method,
185                payment_method_details,
186                setup_error,
187                setup_intent,
188                status,
189                usage,
190            })
191        }
192    }
193
194    impl Map for Builder<'_> {
195        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
196            self.builder.key(k)
197        }
198
199        fn finish(&mut self) -> Result<()> {
200            *self.out = self.builder.take_out();
201            Ok(())
202        }
203    }
204
205    impl ObjectDeser for SetupAttempt {
206        type Builder = SetupAttemptBuilder;
207    }
208
209    impl FromValueOpt for SetupAttempt {
210        fn from_value(v: Value) -> Option<Self> {
211            let Value::Object(obj) = v else {
212                return None;
213            };
214            let mut b = SetupAttemptBuilder::deser_default();
215            for (k, v) in obj {
216                match k.as_str() {
217                    "application" => b.application = FromValueOpt::from_value(v),
218                    "attach_to_self" => b.attach_to_self = FromValueOpt::from_value(v),
219                    "created" => b.created = FromValueOpt::from_value(v),
220                    "customer" => b.customer = FromValueOpt::from_value(v),
221                    "flow_directions" => b.flow_directions = FromValueOpt::from_value(v),
222                    "id" => b.id = FromValueOpt::from_value(v),
223                    "livemode" => b.livemode = FromValueOpt::from_value(v),
224                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
225                    "payment_method" => b.payment_method = FromValueOpt::from_value(v),
226                    "payment_method_details" => {
227                        b.payment_method_details = FromValueOpt::from_value(v)
228                    }
229                    "setup_error" => b.setup_error = FromValueOpt::from_value(v),
230                    "setup_intent" => b.setup_intent = FromValueOpt::from_value(v),
231                    "status" => b.status = FromValueOpt::from_value(v),
232                    "usage" => b.usage = FromValueOpt::from_value(v),
233                    _ => {}
234                }
235            }
236            b.take_out()
237        }
238    }
239};
240#[cfg(feature = "serialize")]
241impl serde::Serialize for SetupAttempt {
242    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
243        use serde::ser::SerializeStruct;
244        let mut s = s.serialize_struct("SetupAttempt", 15)?;
245        s.serialize_field("application", &self.application)?;
246        s.serialize_field("attach_to_self", &self.attach_to_self)?;
247        s.serialize_field("created", &self.created)?;
248        s.serialize_field("customer", &self.customer)?;
249        s.serialize_field("flow_directions", &self.flow_directions)?;
250        s.serialize_field("id", &self.id)?;
251        s.serialize_field("livemode", &self.livemode)?;
252        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
253        s.serialize_field("payment_method", &self.payment_method)?;
254        s.serialize_field("payment_method_details", &self.payment_method_details)?;
255        s.serialize_field("setup_error", &self.setup_error)?;
256        s.serialize_field("setup_intent", &self.setup_intent)?;
257        s.serialize_field("status", &self.status)?;
258        s.serialize_field("usage", &self.usage)?;
259
260        s.serialize_field("object", "setup_attempt")?;
261        s.end()
262    }
263}
264/// Indicates the directions of money movement for which this payment method is intended to be used.
265///
266/// Include `inbound` if you intend to use the payment method as the origin to pull funds from.
267/// Include `outbound` if you intend to use the payment method as the destination to send funds to.
268/// You can include both if you intend to use the payment method for both purposes.
269#[derive(Copy, Clone, Eq, PartialEq)]
270pub enum SetupAttemptFlowDirections {
271    Inbound,
272    Outbound,
273}
274impl SetupAttemptFlowDirections {
275    pub fn as_str(self) -> &'static str {
276        use SetupAttemptFlowDirections::*;
277        match self {
278            Inbound => "inbound",
279            Outbound => "outbound",
280        }
281    }
282}
283
284impl std::str::FromStr for SetupAttemptFlowDirections {
285    type Err = stripe_types::StripeParseError;
286    fn from_str(s: &str) -> Result<Self, Self::Err> {
287        use SetupAttemptFlowDirections::*;
288        match s {
289            "inbound" => Ok(Inbound),
290            "outbound" => Ok(Outbound),
291            _ => Err(stripe_types::StripeParseError),
292        }
293    }
294}
295impl std::fmt::Display for SetupAttemptFlowDirections {
296    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
297        f.write_str(self.as_str())
298    }
299}
300
301impl std::fmt::Debug for SetupAttemptFlowDirections {
302    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
303        f.write_str(self.as_str())
304    }
305}
306#[cfg(feature = "serialize")]
307impl serde::Serialize for SetupAttemptFlowDirections {
308    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
309    where
310        S: serde::Serializer,
311    {
312        serializer.serialize_str(self.as_str())
313    }
314}
315impl miniserde::Deserialize for SetupAttemptFlowDirections {
316    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
317        crate::Place::new(out)
318    }
319}
320
321impl miniserde::de::Visitor for crate::Place<SetupAttemptFlowDirections> {
322    fn string(&mut self, s: &str) -> miniserde::Result<()> {
323        use std::str::FromStr;
324        self.out = Some(SetupAttemptFlowDirections::from_str(s).map_err(|_| miniserde::Error)?);
325        Ok(())
326    }
327}
328
329stripe_types::impl_from_val_with_from_str!(SetupAttemptFlowDirections);
330#[cfg(feature = "deserialize")]
331impl<'de> serde::Deserialize<'de> for SetupAttemptFlowDirections {
332    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
333        use std::str::FromStr;
334        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
335        Self::from_str(&s)
336            .map_err(|_| serde::de::Error::custom("Unknown value for SetupAttemptFlowDirections"))
337    }
338}
339impl stripe_types::Object for SetupAttempt {
340    type Id = stripe_shared::SetupAttemptId;
341    fn id(&self) -> &Self::Id {
342        &self.id
343    }
344
345    fn into_id(self) -> Self::Id {
346        self.id
347    }
348}
349stripe_types::def_id!(SetupAttemptId);