Skip to main content

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