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::{make_place, Deserialize, Result};
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
118                _ => <dyn Visitor>::ignore(),
119            })
120        }
121
122        fn deser_default() -> Self {
123            Self {
124                application: Deserialize::default(),
125                attach_to_self: Deserialize::default(),
126                created: Deserialize::default(),
127                customer: Deserialize::default(),
128                flow_directions: Deserialize::default(),
129                id: Deserialize::default(),
130                livemode: Deserialize::default(),
131                on_behalf_of: Deserialize::default(),
132                payment_method: Deserialize::default(),
133                payment_method_details: Deserialize::default(),
134                setup_error: Deserialize::default(),
135                setup_intent: Deserialize::default(),
136                status: Deserialize::default(),
137                usage: Deserialize::default(),
138            }
139        }
140
141        fn take_out(&mut self) -> Option<Self::Out> {
142            let (
143                Some(application),
144                Some(attach_to_self),
145                Some(created),
146                Some(customer),
147                Some(flow_directions),
148                Some(id),
149                Some(livemode),
150                Some(on_behalf_of),
151                Some(payment_method),
152                Some(payment_method_details),
153                Some(setup_error),
154                Some(setup_intent),
155                Some(status),
156                Some(usage),
157            ) = (
158                self.application.take(),
159                self.attach_to_self,
160                self.created,
161                self.customer.take(),
162                self.flow_directions.take(),
163                self.id.take(),
164                self.livemode,
165                self.on_behalf_of.take(),
166                self.payment_method.take(),
167                self.payment_method_details.take(),
168                self.setup_error.take(),
169                self.setup_intent.take(),
170                self.status.take(),
171                self.usage.take(),
172            )
173            else {
174                return None;
175            };
176            Some(Self::Out {
177                application,
178                attach_to_self,
179                created,
180                customer,
181                flow_directions,
182                id,
183                livemode,
184                on_behalf_of,
185                payment_method,
186                payment_method_details,
187                setup_error,
188                setup_intent,
189                status,
190                usage,
191            })
192        }
193    }
194
195    impl<'a> Map for Builder<'a> {
196        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
197            self.builder.key(k)
198        }
199
200        fn finish(&mut self) -> Result<()> {
201            *self.out = self.builder.take_out();
202            Ok(())
203        }
204    }
205
206    impl ObjectDeser for SetupAttempt {
207        type Builder = SetupAttemptBuilder;
208    }
209
210    impl FromValueOpt for SetupAttempt {
211        fn from_value(v: Value) -> Option<Self> {
212            let Value::Object(obj) = v else {
213                return None;
214            };
215            let mut b = SetupAttemptBuilder::deser_default();
216            for (k, v) in obj {
217                match k.as_str() {
218                    "application" => b.application = FromValueOpt::from_value(v),
219                    "attach_to_self" => b.attach_to_self = FromValueOpt::from_value(v),
220                    "created" => b.created = FromValueOpt::from_value(v),
221                    "customer" => b.customer = FromValueOpt::from_value(v),
222                    "flow_directions" => b.flow_directions = FromValueOpt::from_value(v),
223                    "id" => b.id = FromValueOpt::from_value(v),
224                    "livemode" => b.livemode = FromValueOpt::from_value(v),
225                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
226                    "payment_method" => b.payment_method = FromValueOpt::from_value(v),
227                    "payment_method_details" => {
228                        b.payment_method_details = FromValueOpt::from_value(v)
229                    }
230                    "setup_error" => b.setup_error = FromValueOpt::from_value(v),
231                    "setup_intent" => b.setup_intent = FromValueOpt::from_value(v),
232                    "status" => b.status = FromValueOpt::from_value(v),
233                    "usage" => b.usage = FromValueOpt::from_value(v),
234
235                    _ => {}
236                }
237            }
238            b.take_out()
239        }
240    }
241};
242#[cfg(feature = "serialize")]
243impl serde::Serialize for SetupAttempt {
244    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
245        use serde::ser::SerializeStruct;
246        let mut s = s.serialize_struct("SetupAttempt", 15)?;
247        s.serialize_field("application", &self.application)?;
248        s.serialize_field("attach_to_self", &self.attach_to_self)?;
249        s.serialize_field("created", &self.created)?;
250        s.serialize_field("customer", &self.customer)?;
251        s.serialize_field("flow_directions", &self.flow_directions)?;
252        s.serialize_field("id", &self.id)?;
253        s.serialize_field("livemode", &self.livemode)?;
254        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
255        s.serialize_field("payment_method", &self.payment_method)?;
256        s.serialize_field("payment_method_details", &self.payment_method_details)?;
257        s.serialize_field("setup_error", &self.setup_error)?;
258        s.serialize_field("setup_intent", &self.setup_intent)?;
259        s.serialize_field("status", &self.status)?;
260        s.serialize_field("usage", &self.usage)?;
261
262        s.serialize_field("object", "setup_attempt")?;
263        s.end()
264    }
265}
266/// Indicates the directions of money movement for which this payment method is intended to be used.
267///
268/// Include `inbound` if you intend to use the payment method as the origin to pull funds from.
269/// Include `outbound` if you intend to use the payment method as the destination to send funds to.
270/// You can include both if you intend to use the payment method for both purposes.
271#[derive(Copy, Clone, Eq, PartialEq)]
272pub enum SetupAttemptFlowDirections {
273    Inbound,
274    Outbound,
275}
276impl SetupAttemptFlowDirections {
277    pub fn as_str(self) -> &'static str {
278        use SetupAttemptFlowDirections::*;
279        match self {
280            Inbound => "inbound",
281            Outbound => "outbound",
282        }
283    }
284}
285
286impl std::str::FromStr for SetupAttemptFlowDirections {
287    type Err = stripe_types::StripeParseError;
288    fn from_str(s: &str) -> Result<Self, Self::Err> {
289        use SetupAttemptFlowDirections::*;
290        match s {
291            "inbound" => Ok(Inbound),
292            "outbound" => Ok(Outbound),
293            _ => Err(stripe_types::StripeParseError),
294        }
295    }
296}
297impl std::fmt::Display for SetupAttemptFlowDirections {
298    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
299        f.write_str(self.as_str())
300    }
301}
302
303impl std::fmt::Debug for SetupAttemptFlowDirections {
304    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
305        f.write_str(self.as_str())
306    }
307}
308#[cfg(feature = "serialize")]
309impl serde::Serialize for SetupAttemptFlowDirections {
310    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
311    where
312        S: serde::Serializer,
313    {
314        serializer.serialize_str(self.as_str())
315    }
316}
317impl miniserde::Deserialize for SetupAttemptFlowDirections {
318    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
319        crate::Place::new(out)
320    }
321}
322
323impl miniserde::de::Visitor for crate::Place<SetupAttemptFlowDirections> {
324    fn string(&mut self, s: &str) -> miniserde::Result<()> {
325        use std::str::FromStr;
326        self.out = Some(SetupAttemptFlowDirections::from_str(s).map_err(|_| miniserde::Error)?);
327        Ok(())
328    }
329}
330
331stripe_types::impl_from_val_with_from_str!(SetupAttemptFlowDirections);
332#[cfg(feature = "deserialize")]
333impl<'de> serde::Deserialize<'de> for SetupAttemptFlowDirections {
334    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
335        use std::str::FromStr;
336        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
337        Self::from_str(&s)
338            .map_err(|_| serde::de::Error::custom("Unknown value for SetupAttemptFlowDirections"))
339    }
340}
341impl stripe_types::Object for SetupAttempt {
342    type Id = stripe_shared::SetupAttemptId;
343    fn id(&self) -> &Self::Id {
344        &self.id
345    }
346
347    fn into_id(self) -> Self::Id {
348        self.id
349    }
350}
351stripe_types::def_id!(SetupAttemptId);