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