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(Clone, Eq, PartialEq)]
270#[non_exhaustive]
271pub enum SetupAttemptFlowDirections {
272    Inbound,
273    Outbound,
274    /// An unrecognized value from Stripe. Should not be used as a request parameter.
275    Unknown(String),
276}
277impl SetupAttemptFlowDirections {
278    pub fn as_str(&self) -> &str {
279        use SetupAttemptFlowDirections::*;
280        match self {
281            Inbound => "inbound",
282            Outbound => "outbound",
283            Unknown(v) => v,
284        }
285    }
286}
287
288impl std::str::FromStr for SetupAttemptFlowDirections {
289    type Err = std::convert::Infallible;
290    fn from_str(s: &str) -> Result<Self, Self::Err> {
291        use SetupAttemptFlowDirections::*;
292        match s {
293            "inbound" => Ok(Inbound),
294            "outbound" => Ok(Outbound),
295            v => {
296                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SetupAttemptFlowDirections");
297                Ok(Unknown(v.to_owned()))
298            }
299        }
300    }
301}
302impl std::fmt::Display for SetupAttemptFlowDirections {
303    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
304        f.write_str(self.as_str())
305    }
306}
307
308impl std::fmt::Debug for SetupAttemptFlowDirections {
309    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
310        f.write_str(self.as_str())
311    }
312}
313#[cfg(feature = "serialize")]
314impl serde::Serialize for SetupAttemptFlowDirections {
315    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
316    where
317        S: serde::Serializer,
318    {
319        serializer.serialize_str(self.as_str())
320    }
321}
322impl miniserde::Deserialize for SetupAttemptFlowDirections {
323    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
324        crate::Place::new(out)
325    }
326}
327
328impl miniserde::de::Visitor for crate::Place<SetupAttemptFlowDirections> {
329    fn string(&mut self, s: &str) -> miniserde::Result<()> {
330        use std::str::FromStr;
331        self.out = Some(SetupAttemptFlowDirections::from_str(s).expect("infallible"));
332        Ok(())
333    }
334}
335
336stripe_types::impl_from_val_with_from_str!(SetupAttemptFlowDirections);
337#[cfg(feature = "deserialize")]
338impl<'de> serde::Deserialize<'de> for SetupAttemptFlowDirections {
339    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
340        use std::str::FromStr;
341        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
342        Ok(Self::from_str(&s).expect("infallible"))
343    }
344}
345impl stripe_types::Object for SetupAttempt {
346    type Id = stripe_shared::SetupAttemptId;
347    fn id(&self) -> &Self::Id {
348        &self.id
349    }
350
351    fn into_id(self) -> Self::Id {
352        self.id
353    }
354}
355stripe_types::def_id!(SetupAttemptId);