Skip to main content

stripe_shared/
setup_intent.rs

1/// A SetupIntent guides you through the process of setting up and saving a customer's payment credentials for future payments.
2/// For example, you can use a SetupIntent to set up and save your customer's card without immediately collecting a payment.
3/// Later, you can use [PaymentIntents](https://api.stripe.com#payment_intents) to drive the payment flow.
4///
5/// Create a SetupIntent when you're ready to collect your customer's payment credentials.
6/// Don't maintain long-lived, unconfirmed SetupIntents because they might not be valid.
7/// The SetupIntent transitions through multiple [statuses](https://docs.stripe.com/payments/intents#intent-statuses) as it guides.
8/// you through the setup process.
9///
10/// Successful SetupIntents result in payment credentials that are optimized for future payments.
11/// For example, cardholders in [certain regions](https://stripe.com/guides/strong-customer-authentication) might need to be run through.
12/// [Strong Customer Authentication](https://docs.stripe.com/strong-customer-authentication) during payment method collection.
13/// to streamline later [off-session payments](https://docs.stripe.com/payments/setup-intents).
14/// If you use the SetupIntent with a [Customer](https://api.stripe.com#setup_intent_object-customer),
15/// it automatically attaches the resulting payment method to that Customer after successful setup.
16/// We recommend using SetupIntents or [setup_future_usage](https://api.stripe.com#payment_intent_object-setup_future_usage) on.
17/// PaymentIntents to save payment methods to prevent saving invalid or unoptimized payment methods.
18///
19/// By using SetupIntents, you can reduce friction for your customers, even as regulations change over time.
20///
21/// Related guide: [Setup Intents API](https://docs.stripe.com/payments/setup-intents)
22///
23/// For more details see <<https://stripe.com/docs/api/setup_intents/object>>.
24#[derive(Clone)]
25#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
26#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
27pub struct SetupIntent {
28    /// ID of the Connect application that created the SetupIntent.
29    pub application: Option<stripe_types::Expandable<stripe_shared::Application>>,
30    /// If present, the SetupIntent's payment method will be attached to the in-context Stripe Account.
31    ///
32    /// It can only be used for this Stripe Account’s own money movement flows like InboundTransfer and OutboundTransfers.
33    /// 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.
34    pub attach_to_self: Option<bool>,
35    /// Settings for dynamic payment methods compatible with this Setup Intent
36    pub automatic_payment_methods:
37        Option<stripe_shared::PaymentFlowsAutomaticPaymentMethodsSetupIntent>,
38    /// Reason for cancellation of this SetupIntent, one of `abandoned`, `requested_by_customer`, or `duplicate`.
39    pub cancellation_reason: Option<stripe_shared::SetupIntentCancellationReason>,
40    /// The client secret of this SetupIntent. Used for client-side retrieval using a publishable key.
41    ///
42    /// The client secret can be used to complete payment setup from your frontend.
43    /// It should not be stored, logged, or exposed to anyone other than the customer.
44    /// Make sure that you have TLS enabled on any page that includes the client secret.
45    pub client_secret: Option<String>,
46    /// Time at which the object was created. Measured in seconds since the Unix epoch.
47    pub created: stripe_types::Timestamp,
48    /// ID of the Customer this SetupIntent belongs to, if one exists.
49    ///
50    /// If present, the SetupIntent's payment method will be attached to the Customer on successful setup.
51    /// Payment methods attached to other Customers cannot be used with this SetupIntent.
52    pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
53    /// ID of the Account this SetupIntent belongs to, if one exists.
54    ///
55    /// If present, the SetupIntent's payment method will be attached to the Account on successful setup.
56    /// Payment methods attached to other Accounts cannot be used with this SetupIntent.
57    pub customer_account: Option<String>,
58    /// An arbitrary string attached to the object. Often useful for displaying to users.
59    pub description: Option<String>,
60    /// Payment method types that are excluded from this SetupIntent.
61    pub excluded_payment_method_types:
62        Option<Vec<stripe_shared::SetupIntentExcludedPaymentMethodTypes>>,
63    /// Indicates the directions of money movement for which this payment method is intended to be used.
64    ///
65    /// Include `inbound` if you intend to use the payment method as the origin to pull funds from.
66    /// Include `outbound` if you intend to use the payment method as the destination to send funds to.
67    /// You can include both if you intend to use the payment method for both purposes.
68    pub flow_directions: Option<Vec<stripe_shared::SetupIntentFlowDirections>>,
69    /// Unique identifier for the object.
70    pub id: stripe_shared::SetupIntentId,
71    /// The error encountered in the previous SetupIntent confirmation.
72    pub last_setup_error: Option<Box<stripe_shared::ApiErrors>>,
73    /// The most recent SetupAttempt for this SetupIntent.
74    pub latest_attempt: Option<stripe_types::Expandable<stripe_shared::SetupAttempt>>,
75    /// If the object exists in live mode, the value is `true`.
76    /// If the object exists in test mode, the value is `false`.
77    pub livemode: bool,
78    /// ID of the multi use Mandate generated by the SetupIntent.
79    pub mandate: Option<stripe_types::Expandable<stripe_shared::Mandate>>,
80    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
81    /// This can be useful for storing additional information about the object in a structured format.
82    pub metadata: Option<std::collections::HashMap<String, String>>,
83    /// If present, this property tells you what actions you need to take in order for your customer to continue payment setup.
84    pub next_action: Option<stripe_shared::SetupIntentNextAction>,
85    /// The account (if any) for which the setup is intended.
86    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
87    /// ID of the payment method used with this SetupIntent.
88    /// If the payment method is `card_present` and isn't a digital wallet, then the [generated_card](https://docs.stripe.com/api/setup_attempts/object#setup_attempt_object-payment_method_details-card_present-generated_card) associated with the `latest_attempt` is attached to the Customer instead.
89    pub payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
90    /// Information about the [payment method configuration](https://docs.stripe.com/api/payment_method_configurations) used for this Setup Intent.
91    pub payment_method_configuration_details:
92        Option<stripe_shared::PaymentMethodConfigBizPaymentMethodConfigurationDetails>,
93    /// Payment method-specific configuration for this SetupIntent.
94    pub payment_method_options: Option<stripe_shared::SetupIntentPaymentMethodOptions>,
95    /// The list of payment method types (e.g.
96    /// card) that this SetupIntent is allowed to set up.
97    /// A list of valid payment method types can be found [here](https://docs.stripe.com/api/payment_methods/object#payment_method_object-type).
98    pub payment_method_types: Vec<String>,
99    /// ID of the single_use Mandate generated by the SetupIntent.
100    pub single_use_mandate: Option<stripe_types::Expandable<stripe_shared::Mandate>>,
101    /// [Status](https://docs.stripe.com/payments/intents#intent-statuses) of this SetupIntent, one of `requires_payment_method`, `requires_confirmation`, `requires_action`, `processing`, `canceled`, or `succeeded`.
102    pub status: SetupIntentStatus,
103    /// Indicates how the payment method is intended to be used in the future.
104    ///
105    /// Use `on_session` if you intend to only reuse the payment method when the customer is in your checkout flow.
106    /// Use `off_session` if your customer may or may not be in your checkout flow.
107    /// If not provided, this value defaults to `off_session`.
108    pub usage: String,
109}
110#[cfg(feature = "redact-generated-debug")]
111impl std::fmt::Debug for SetupIntent {
112    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
113        f.debug_struct("SetupIntent").finish_non_exhaustive()
114    }
115}
116#[doc(hidden)]
117pub struct SetupIntentBuilder {
118    application: Option<Option<stripe_types::Expandable<stripe_shared::Application>>>,
119    attach_to_self: Option<Option<bool>>,
120    automatic_payment_methods:
121        Option<Option<stripe_shared::PaymentFlowsAutomaticPaymentMethodsSetupIntent>>,
122    cancellation_reason: Option<Option<stripe_shared::SetupIntentCancellationReason>>,
123    client_secret: Option<Option<String>>,
124    created: Option<stripe_types::Timestamp>,
125    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
126    customer_account: Option<Option<String>>,
127    description: Option<Option<String>>,
128    excluded_payment_method_types:
129        Option<Option<Vec<stripe_shared::SetupIntentExcludedPaymentMethodTypes>>>,
130    flow_directions: Option<Option<Vec<stripe_shared::SetupIntentFlowDirections>>>,
131    id: Option<stripe_shared::SetupIntentId>,
132    last_setup_error: Option<Option<Box<stripe_shared::ApiErrors>>>,
133    latest_attempt: Option<Option<stripe_types::Expandable<stripe_shared::SetupAttempt>>>,
134    livemode: Option<bool>,
135    mandate: Option<Option<stripe_types::Expandable<stripe_shared::Mandate>>>,
136    metadata: Option<Option<std::collections::HashMap<String, String>>>,
137    next_action: Option<Option<stripe_shared::SetupIntentNextAction>>,
138    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
139    payment_method: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
140    payment_method_configuration_details:
141        Option<Option<stripe_shared::PaymentMethodConfigBizPaymentMethodConfigurationDetails>>,
142    payment_method_options: Option<Option<stripe_shared::SetupIntentPaymentMethodOptions>>,
143    payment_method_types: Option<Vec<String>>,
144    single_use_mandate: Option<Option<stripe_types::Expandable<stripe_shared::Mandate>>>,
145    status: Option<SetupIntentStatus>,
146    usage: Option<String>,
147}
148
149#[allow(
150    unused_variables,
151    irrefutable_let_patterns,
152    clippy::let_unit_value,
153    clippy::match_single_binding,
154    clippy::single_match
155)]
156const _: () = {
157    use miniserde::de::{Map, Visitor};
158    use miniserde::json::Value;
159    use miniserde::{Deserialize, Result, make_place};
160    use stripe_types::miniserde_helpers::FromValueOpt;
161    use stripe_types::{MapBuilder, ObjectDeser};
162
163    make_place!(Place);
164
165    impl Deserialize for SetupIntent {
166        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
167            Place::new(out)
168        }
169    }
170
171    struct Builder<'a> {
172        out: &'a mut Option<SetupIntent>,
173        builder: SetupIntentBuilder,
174    }
175
176    impl Visitor for Place<SetupIntent> {
177        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
178            Ok(Box::new(Builder {
179                out: &mut self.out,
180                builder: SetupIntentBuilder::deser_default(),
181            }))
182        }
183    }
184
185    impl MapBuilder for SetupIntentBuilder {
186        type Out = SetupIntent;
187        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
188            Ok(match k {
189                "application" => Deserialize::begin(&mut self.application),
190                "attach_to_self" => Deserialize::begin(&mut self.attach_to_self),
191                "automatic_payment_methods" => {
192                    Deserialize::begin(&mut self.automatic_payment_methods)
193                }
194                "cancellation_reason" => Deserialize::begin(&mut self.cancellation_reason),
195                "client_secret" => Deserialize::begin(&mut self.client_secret),
196                "created" => Deserialize::begin(&mut self.created),
197                "customer" => Deserialize::begin(&mut self.customer),
198                "customer_account" => Deserialize::begin(&mut self.customer_account),
199                "description" => Deserialize::begin(&mut self.description),
200                "excluded_payment_method_types" => {
201                    Deserialize::begin(&mut self.excluded_payment_method_types)
202                }
203                "flow_directions" => Deserialize::begin(&mut self.flow_directions),
204                "id" => Deserialize::begin(&mut self.id),
205                "last_setup_error" => Deserialize::begin(&mut self.last_setup_error),
206                "latest_attempt" => Deserialize::begin(&mut self.latest_attempt),
207                "livemode" => Deserialize::begin(&mut self.livemode),
208                "mandate" => Deserialize::begin(&mut self.mandate),
209                "metadata" => Deserialize::begin(&mut self.metadata),
210                "next_action" => Deserialize::begin(&mut self.next_action),
211                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
212                "payment_method" => Deserialize::begin(&mut self.payment_method),
213                "payment_method_configuration_details" => {
214                    Deserialize::begin(&mut self.payment_method_configuration_details)
215                }
216                "payment_method_options" => Deserialize::begin(&mut self.payment_method_options),
217                "payment_method_types" => Deserialize::begin(&mut self.payment_method_types),
218                "single_use_mandate" => Deserialize::begin(&mut self.single_use_mandate),
219                "status" => Deserialize::begin(&mut self.status),
220                "usage" => Deserialize::begin(&mut self.usage),
221                _ => <dyn Visitor>::ignore(),
222            })
223        }
224
225        fn deser_default() -> Self {
226            Self {
227                application: Deserialize::default(),
228                attach_to_self: Deserialize::default(),
229                automatic_payment_methods: Deserialize::default(),
230                cancellation_reason: Deserialize::default(),
231                client_secret: Deserialize::default(),
232                created: Deserialize::default(),
233                customer: Deserialize::default(),
234                customer_account: Deserialize::default(),
235                description: Deserialize::default(),
236                excluded_payment_method_types: Deserialize::default(),
237                flow_directions: Deserialize::default(),
238                id: Deserialize::default(),
239                last_setup_error: Deserialize::default(),
240                latest_attempt: Deserialize::default(),
241                livemode: Deserialize::default(),
242                mandate: Deserialize::default(),
243                metadata: Deserialize::default(),
244                next_action: Deserialize::default(),
245                on_behalf_of: Deserialize::default(),
246                payment_method: Deserialize::default(),
247                payment_method_configuration_details: Deserialize::default(),
248                payment_method_options: Deserialize::default(),
249                payment_method_types: Deserialize::default(),
250                single_use_mandate: Deserialize::default(),
251                status: Deserialize::default(),
252                usage: Deserialize::default(),
253            }
254        }
255
256        fn take_out(&mut self) -> Option<Self::Out> {
257            let (
258                Some(application),
259                Some(attach_to_self),
260                Some(automatic_payment_methods),
261                Some(cancellation_reason),
262                Some(client_secret),
263                Some(created),
264                Some(customer),
265                Some(customer_account),
266                Some(description),
267                Some(excluded_payment_method_types),
268                Some(flow_directions),
269                Some(id),
270                Some(last_setup_error),
271                Some(latest_attempt),
272                Some(livemode),
273                Some(mandate),
274                Some(metadata),
275                Some(next_action),
276                Some(on_behalf_of),
277                Some(payment_method),
278                Some(payment_method_configuration_details),
279                Some(payment_method_options),
280                Some(payment_method_types),
281                Some(single_use_mandate),
282                Some(status),
283                Some(usage),
284            ) = (
285                self.application.take(),
286                self.attach_to_self,
287                self.automatic_payment_methods.take(),
288                self.cancellation_reason.take(),
289                self.client_secret.take(),
290                self.created,
291                self.customer.take(),
292                self.customer_account.take(),
293                self.description.take(),
294                self.excluded_payment_method_types.take(),
295                self.flow_directions.take(),
296                self.id.take(),
297                self.last_setup_error.take(),
298                self.latest_attempt.take(),
299                self.livemode,
300                self.mandate.take(),
301                self.metadata.take(),
302                self.next_action.take(),
303                self.on_behalf_of.take(),
304                self.payment_method.take(),
305                self.payment_method_configuration_details.take(),
306                self.payment_method_options.take(),
307                self.payment_method_types.take(),
308                self.single_use_mandate.take(),
309                self.status.take(),
310                self.usage.take(),
311            )
312            else {
313                return None;
314            };
315            Some(Self::Out {
316                application,
317                attach_to_self,
318                automatic_payment_methods,
319                cancellation_reason,
320                client_secret,
321                created,
322                customer,
323                customer_account,
324                description,
325                excluded_payment_method_types,
326                flow_directions,
327                id,
328                last_setup_error,
329                latest_attempt,
330                livemode,
331                mandate,
332                metadata,
333                next_action,
334                on_behalf_of,
335                payment_method,
336                payment_method_configuration_details,
337                payment_method_options,
338                payment_method_types,
339                single_use_mandate,
340                status,
341                usage,
342            })
343        }
344    }
345
346    impl Map for Builder<'_> {
347        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
348            self.builder.key(k)
349        }
350
351        fn finish(&mut self) -> Result<()> {
352            *self.out = self.builder.take_out();
353            Ok(())
354        }
355    }
356
357    impl ObjectDeser for SetupIntent {
358        type Builder = SetupIntentBuilder;
359    }
360
361    impl FromValueOpt for SetupIntent {
362        fn from_value(v: Value) -> Option<Self> {
363            let Value::Object(obj) = v else {
364                return None;
365            };
366            let mut b = SetupIntentBuilder::deser_default();
367            for (k, v) in obj {
368                match k.as_str() {
369                    "application" => b.application = FromValueOpt::from_value(v),
370                    "attach_to_self" => b.attach_to_self = FromValueOpt::from_value(v),
371                    "automatic_payment_methods" => {
372                        b.automatic_payment_methods = FromValueOpt::from_value(v)
373                    }
374                    "cancellation_reason" => b.cancellation_reason = FromValueOpt::from_value(v),
375                    "client_secret" => b.client_secret = FromValueOpt::from_value(v),
376                    "created" => b.created = FromValueOpt::from_value(v),
377                    "customer" => b.customer = FromValueOpt::from_value(v),
378                    "customer_account" => b.customer_account = FromValueOpt::from_value(v),
379                    "description" => b.description = FromValueOpt::from_value(v),
380                    "excluded_payment_method_types" => {
381                        b.excluded_payment_method_types = FromValueOpt::from_value(v)
382                    }
383                    "flow_directions" => b.flow_directions = FromValueOpt::from_value(v),
384                    "id" => b.id = FromValueOpt::from_value(v),
385                    "last_setup_error" => b.last_setup_error = FromValueOpt::from_value(v),
386                    "latest_attempt" => b.latest_attempt = FromValueOpt::from_value(v),
387                    "livemode" => b.livemode = FromValueOpt::from_value(v),
388                    "mandate" => b.mandate = FromValueOpt::from_value(v),
389                    "metadata" => b.metadata = FromValueOpt::from_value(v),
390                    "next_action" => b.next_action = FromValueOpt::from_value(v),
391                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
392                    "payment_method" => b.payment_method = FromValueOpt::from_value(v),
393                    "payment_method_configuration_details" => {
394                        b.payment_method_configuration_details = FromValueOpt::from_value(v)
395                    }
396                    "payment_method_options" => {
397                        b.payment_method_options = FromValueOpt::from_value(v)
398                    }
399                    "payment_method_types" => b.payment_method_types = FromValueOpt::from_value(v),
400                    "single_use_mandate" => b.single_use_mandate = FromValueOpt::from_value(v),
401                    "status" => b.status = FromValueOpt::from_value(v),
402                    "usage" => b.usage = FromValueOpt::from_value(v),
403                    _ => {}
404                }
405            }
406            b.take_out()
407        }
408    }
409};
410#[cfg(feature = "serialize")]
411impl serde::Serialize for SetupIntent {
412    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
413        use serde::ser::SerializeStruct;
414        let mut s = s.serialize_struct("SetupIntent", 27)?;
415        s.serialize_field("application", &self.application)?;
416        s.serialize_field("attach_to_self", &self.attach_to_self)?;
417        s.serialize_field("automatic_payment_methods", &self.automatic_payment_methods)?;
418        s.serialize_field("cancellation_reason", &self.cancellation_reason)?;
419        s.serialize_field("client_secret", &self.client_secret)?;
420        s.serialize_field("created", &self.created)?;
421        s.serialize_field("customer", &self.customer)?;
422        s.serialize_field("customer_account", &self.customer_account)?;
423        s.serialize_field("description", &self.description)?;
424        s.serialize_field("excluded_payment_method_types", &self.excluded_payment_method_types)?;
425        s.serialize_field("flow_directions", &self.flow_directions)?;
426        s.serialize_field("id", &self.id)?;
427        s.serialize_field("last_setup_error", &self.last_setup_error)?;
428        s.serialize_field("latest_attempt", &self.latest_attempt)?;
429        s.serialize_field("livemode", &self.livemode)?;
430        s.serialize_field("mandate", &self.mandate)?;
431        s.serialize_field("metadata", &self.metadata)?;
432        s.serialize_field("next_action", &self.next_action)?;
433        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
434        s.serialize_field("payment_method", &self.payment_method)?;
435        s.serialize_field(
436            "payment_method_configuration_details",
437            &self.payment_method_configuration_details,
438        )?;
439        s.serialize_field("payment_method_options", &self.payment_method_options)?;
440        s.serialize_field("payment_method_types", &self.payment_method_types)?;
441        s.serialize_field("single_use_mandate", &self.single_use_mandate)?;
442        s.serialize_field("status", &self.status)?;
443        s.serialize_field("usage", &self.usage)?;
444
445        s.serialize_field("object", "setup_intent")?;
446        s.end()
447    }
448}
449/// [Status](https://docs.stripe.com/payments/intents#intent-statuses) of this SetupIntent, one of `requires_payment_method`, `requires_confirmation`, `requires_action`, `processing`, `canceled`, or `succeeded`.
450#[derive(Clone, Eq, PartialEq)]
451#[non_exhaustive]
452pub enum SetupIntentStatus {
453    Canceled,
454    Processing,
455    RequiresAction,
456    RequiresConfirmation,
457    RequiresPaymentMethod,
458    Succeeded,
459    /// An unrecognized value from Stripe. Should not be used as a request parameter.
460    Unknown(String),
461}
462impl SetupIntentStatus {
463    pub fn as_str(&self) -> &str {
464        use SetupIntentStatus::*;
465        match self {
466            Canceled => "canceled",
467            Processing => "processing",
468            RequiresAction => "requires_action",
469            RequiresConfirmation => "requires_confirmation",
470            RequiresPaymentMethod => "requires_payment_method",
471            Succeeded => "succeeded",
472            Unknown(v) => v,
473        }
474    }
475}
476
477impl std::str::FromStr for SetupIntentStatus {
478    type Err = std::convert::Infallible;
479    fn from_str(s: &str) -> Result<Self, Self::Err> {
480        use SetupIntentStatus::*;
481        match s {
482            "canceled" => Ok(Canceled),
483            "processing" => Ok(Processing),
484            "requires_action" => Ok(RequiresAction),
485            "requires_confirmation" => Ok(RequiresConfirmation),
486            "requires_payment_method" => Ok(RequiresPaymentMethod),
487            "succeeded" => Ok(Succeeded),
488            v => {
489                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SetupIntentStatus");
490                Ok(Unknown(v.to_owned()))
491            }
492        }
493    }
494}
495impl std::fmt::Display for SetupIntentStatus {
496    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
497        f.write_str(self.as_str())
498    }
499}
500
501#[cfg(not(feature = "redact-generated-debug"))]
502impl std::fmt::Debug for SetupIntentStatus {
503    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
504        f.write_str(self.as_str())
505    }
506}
507#[cfg(feature = "redact-generated-debug")]
508impl std::fmt::Debug for SetupIntentStatus {
509    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
510        f.debug_struct(stringify!(SetupIntentStatus)).finish_non_exhaustive()
511    }
512}
513#[cfg(feature = "serialize")]
514impl serde::Serialize for SetupIntentStatus {
515    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
516    where
517        S: serde::Serializer,
518    {
519        serializer.serialize_str(self.as_str())
520    }
521}
522impl miniserde::Deserialize for SetupIntentStatus {
523    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
524        crate::Place::new(out)
525    }
526}
527
528impl miniserde::de::Visitor for crate::Place<SetupIntentStatus> {
529    fn string(&mut self, s: &str) -> miniserde::Result<()> {
530        use std::str::FromStr;
531        self.out = Some(SetupIntentStatus::from_str(s).expect("infallible"));
532        Ok(())
533    }
534}
535
536stripe_types::impl_from_val_with_from_str!(SetupIntentStatus);
537#[cfg(feature = "deserialize")]
538impl<'de> serde::Deserialize<'de> for SetupIntentStatus {
539    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
540        use std::str::FromStr;
541        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
542        Ok(Self::from_str(&s).expect("infallible"))
543    }
544}
545impl stripe_types::Object for SetupIntent {
546    type Id = stripe_shared::SetupIntentId;
547    fn id(&self) -> &Self::Id {
548        &self.id
549    }
550
551    fn into_id(self) -> Self::Id {
552        self.id
553    }
554}
555stripe_types::def_id!(SetupIntentId);
556#[derive(Clone, Eq, PartialEq)]
557#[non_exhaustive]
558pub enum SetupIntentCancellationReason {
559    Abandoned,
560    Duplicate,
561    RequestedByCustomer,
562    /// An unrecognized value from Stripe. Should not be used as a request parameter.
563    Unknown(String),
564}
565impl SetupIntentCancellationReason {
566    pub fn as_str(&self) -> &str {
567        use SetupIntentCancellationReason::*;
568        match self {
569            Abandoned => "abandoned",
570            Duplicate => "duplicate",
571            RequestedByCustomer => "requested_by_customer",
572            Unknown(v) => v,
573        }
574    }
575}
576
577impl std::str::FromStr for SetupIntentCancellationReason {
578    type Err = std::convert::Infallible;
579    fn from_str(s: &str) -> Result<Self, Self::Err> {
580        use SetupIntentCancellationReason::*;
581        match s {
582            "abandoned" => Ok(Abandoned),
583            "duplicate" => Ok(Duplicate),
584            "requested_by_customer" => Ok(RequestedByCustomer),
585            v => {
586                tracing::warn!(
587                    "Unknown value '{}' for enum '{}'",
588                    v,
589                    "SetupIntentCancellationReason"
590                );
591                Ok(Unknown(v.to_owned()))
592            }
593        }
594    }
595}
596impl std::fmt::Display for SetupIntentCancellationReason {
597    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
598        f.write_str(self.as_str())
599    }
600}
601
602#[cfg(not(feature = "redact-generated-debug"))]
603impl std::fmt::Debug for SetupIntentCancellationReason {
604    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
605        f.write_str(self.as_str())
606    }
607}
608#[cfg(feature = "redact-generated-debug")]
609impl std::fmt::Debug for SetupIntentCancellationReason {
610    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
611        f.debug_struct(stringify!(SetupIntentCancellationReason)).finish_non_exhaustive()
612    }
613}
614impl serde::Serialize for SetupIntentCancellationReason {
615    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
616    where
617        S: serde::Serializer,
618    {
619        serializer.serialize_str(self.as_str())
620    }
621}
622impl miniserde::Deserialize for SetupIntentCancellationReason {
623    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
624        crate::Place::new(out)
625    }
626}
627
628impl miniserde::de::Visitor for crate::Place<SetupIntentCancellationReason> {
629    fn string(&mut self, s: &str) -> miniserde::Result<()> {
630        use std::str::FromStr;
631        self.out = Some(SetupIntentCancellationReason::from_str(s).expect("infallible"));
632        Ok(())
633    }
634}
635
636stripe_types::impl_from_val_with_from_str!(SetupIntentCancellationReason);
637#[cfg(feature = "deserialize")]
638impl<'de> serde::Deserialize<'de> for SetupIntentCancellationReason {
639    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
640        use std::str::FromStr;
641        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
642        Ok(Self::from_str(&s).expect("infallible"))
643    }
644}
645#[derive(Clone, Eq, PartialEq)]
646#[non_exhaustive]
647pub enum SetupIntentExcludedPaymentMethodTypes {
648    AcssDebit,
649    Affirm,
650    AfterpayClearpay,
651    Alipay,
652    Alma,
653    AmazonPay,
654    AuBecsDebit,
655    BacsDebit,
656    Bancontact,
657    Billie,
658    Blik,
659    Boleto,
660    Card,
661    Cashapp,
662    Crypto,
663    CustomerBalance,
664    Eps,
665    Fpx,
666    Giropay,
667    Grabpay,
668    Ideal,
669    KakaoPay,
670    Klarna,
671    Konbini,
672    KrCard,
673    MbWay,
674    Mobilepay,
675    Multibanco,
676    NaverPay,
677    NzBankAccount,
678    Oxxo,
679    P24,
680    PayByBank,
681    Payco,
682    Paynow,
683    Paypal,
684    Payto,
685    Pix,
686    Promptpay,
687    RevolutPay,
688    SamsungPay,
689    Satispay,
690    SepaDebit,
691    Sofort,
692    Swish,
693    Twint,
694    Upi,
695    UsBankAccount,
696    WechatPay,
697    Zip,
698    /// An unrecognized value from Stripe. Should not be used as a request parameter.
699    Unknown(String),
700}
701impl SetupIntentExcludedPaymentMethodTypes {
702    pub fn as_str(&self) -> &str {
703        use SetupIntentExcludedPaymentMethodTypes::*;
704        match self {
705            AcssDebit => "acss_debit",
706            Affirm => "affirm",
707            AfterpayClearpay => "afterpay_clearpay",
708            Alipay => "alipay",
709            Alma => "alma",
710            AmazonPay => "amazon_pay",
711            AuBecsDebit => "au_becs_debit",
712            BacsDebit => "bacs_debit",
713            Bancontact => "bancontact",
714            Billie => "billie",
715            Blik => "blik",
716            Boleto => "boleto",
717            Card => "card",
718            Cashapp => "cashapp",
719            Crypto => "crypto",
720            CustomerBalance => "customer_balance",
721            Eps => "eps",
722            Fpx => "fpx",
723            Giropay => "giropay",
724            Grabpay => "grabpay",
725            Ideal => "ideal",
726            KakaoPay => "kakao_pay",
727            Klarna => "klarna",
728            Konbini => "konbini",
729            KrCard => "kr_card",
730            MbWay => "mb_way",
731            Mobilepay => "mobilepay",
732            Multibanco => "multibanco",
733            NaverPay => "naver_pay",
734            NzBankAccount => "nz_bank_account",
735            Oxxo => "oxxo",
736            P24 => "p24",
737            PayByBank => "pay_by_bank",
738            Payco => "payco",
739            Paynow => "paynow",
740            Paypal => "paypal",
741            Payto => "payto",
742            Pix => "pix",
743            Promptpay => "promptpay",
744            RevolutPay => "revolut_pay",
745            SamsungPay => "samsung_pay",
746            Satispay => "satispay",
747            SepaDebit => "sepa_debit",
748            Sofort => "sofort",
749            Swish => "swish",
750            Twint => "twint",
751            Upi => "upi",
752            UsBankAccount => "us_bank_account",
753            WechatPay => "wechat_pay",
754            Zip => "zip",
755            Unknown(v) => v,
756        }
757    }
758}
759
760impl std::str::FromStr for SetupIntentExcludedPaymentMethodTypes {
761    type Err = std::convert::Infallible;
762    fn from_str(s: &str) -> Result<Self, Self::Err> {
763        use SetupIntentExcludedPaymentMethodTypes::*;
764        match s {
765            "acss_debit" => Ok(AcssDebit),
766            "affirm" => Ok(Affirm),
767            "afterpay_clearpay" => Ok(AfterpayClearpay),
768            "alipay" => Ok(Alipay),
769            "alma" => Ok(Alma),
770            "amazon_pay" => Ok(AmazonPay),
771            "au_becs_debit" => Ok(AuBecsDebit),
772            "bacs_debit" => Ok(BacsDebit),
773            "bancontact" => Ok(Bancontact),
774            "billie" => Ok(Billie),
775            "blik" => Ok(Blik),
776            "boleto" => Ok(Boleto),
777            "card" => Ok(Card),
778            "cashapp" => Ok(Cashapp),
779            "crypto" => Ok(Crypto),
780            "customer_balance" => Ok(CustomerBalance),
781            "eps" => Ok(Eps),
782            "fpx" => Ok(Fpx),
783            "giropay" => Ok(Giropay),
784            "grabpay" => Ok(Grabpay),
785            "ideal" => Ok(Ideal),
786            "kakao_pay" => Ok(KakaoPay),
787            "klarna" => Ok(Klarna),
788            "konbini" => Ok(Konbini),
789            "kr_card" => Ok(KrCard),
790            "mb_way" => Ok(MbWay),
791            "mobilepay" => Ok(Mobilepay),
792            "multibanco" => Ok(Multibanco),
793            "naver_pay" => Ok(NaverPay),
794            "nz_bank_account" => Ok(NzBankAccount),
795            "oxxo" => Ok(Oxxo),
796            "p24" => Ok(P24),
797            "pay_by_bank" => Ok(PayByBank),
798            "payco" => Ok(Payco),
799            "paynow" => Ok(Paynow),
800            "paypal" => Ok(Paypal),
801            "payto" => Ok(Payto),
802            "pix" => Ok(Pix),
803            "promptpay" => Ok(Promptpay),
804            "revolut_pay" => Ok(RevolutPay),
805            "samsung_pay" => Ok(SamsungPay),
806            "satispay" => Ok(Satispay),
807            "sepa_debit" => Ok(SepaDebit),
808            "sofort" => Ok(Sofort),
809            "swish" => Ok(Swish),
810            "twint" => Ok(Twint),
811            "upi" => Ok(Upi),
812            "us_bank_account" => Ok(UsBankAccount),
813            "wechat_pay" => Ok(WechatPay),
814            "zip" => Ok(Zip),
815            v => {
816                tracing::warn!(
817                    "Unknown value '{}' for enum '{}'",
818                    v,
819                    "SetupIntentExcludedPaymentMethodTypes"
820                );
821                Ok(Unknown(v.to_owned()))
822            }
823        }
824    }
825}
826impl std::fmt::Display for SetupIntentExcludedPaymentMethodTypes {
827    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
828        f.write_str(self.as_str())
829    }
830}
831
832#[cfg(not(feature = "redact-generated-debug"))]
833impl std::fmt::Debug for SetupIntentExcludedPaymentMethodTypes {
834    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
835        f.write_str(self.as_str())
836    }
837}
838#[cfg(feature = "redact-generated-debug")]
839impl std::fmt::Debug for SetupIntentExcludedPaymentMethodTypes {
840    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
841        f.debug_struct(stringify!(SetupIntentExcludedPaymentMethodTypes)).finish_non_exhaustive()
842    }
843}
844impl serde::Serialize for SetupIntentExcludedPaymentMethodTypes {
845    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
846    where
847        S: serde::Serializer,
848    {
849        serializer.serialize_str(self.as_str())
850    }
851}
852impl miniserde::Deserialize for SetupIntentExcludedPaymentMethodTypes {
853    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
854        crate::Place::new(out)
855    }
856}
857
858impl miniserde::de::Visitor for crate::Place<SetupIntentExcludedPaymentMethodTypes> {
859    fn string(&mut self, s: &str) -> miniserde::Result<()> {
860        use std::str::FromStr;
861        self.out = Some(SetupIntentExcludedPaymentMethodTypes::from_str(s).expect("infallible"));
862        Ok(())
863    }
864}
865
866stripe_types::impl_from_val_with_from_str!(SetupIntentExcludedPaymentMethodTypes);
867#[cfg(feature = "deserialize")]
868impl<'de> serde::Deserialize<'de> for SetupIntentExcludedPaymentMethodTypes {
869    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
870        use std::str::FromStr;
871        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
872        Ok(Self::from_str(&s).expect("infallible"))
873    }
874}
875#[derive(Clone, Eq, PartialEq)]
876#[non_exhaustive]
877pub enum SetupIntentFlowDirections {
878    Inbound,
879    Outbound,
880    /// An unrecognized value from Stripe. Should not be used as a request parameter.
881    Unknown(String),
882}
883impl SetupIntentFlowDirections {
884    pub fn as_str(&self) -> &str {
885        use SetupIntentFlowDirections::*;
886        match self {
887            Inbound => "inbound",
888            Outbound => "outbound",
889            Unknown(v) => v,
890        }
891    }
892}
893
894impl std::str::FromStr for SetupIntentFlowDirections {
895    type Err = std::convert::Infallible;
896    fn from_str(s: &str) -> Result<Self, Self::Err> {
897        use SetupIntentFlowDirections::*;
898        match s {
899            "inbound" => Ok(Inbound),
900            "outbound" => Ok(Outbound),
901            v => {
902                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SetupIntentFlowDirections");
903                Ok(Unknown(v.to_owned()))
904            }
905        }
906    }
907}
908impl std::fmt::Display for SetupIntentFlowDirections {
909    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
910        f.write_str(self.as_str())
911    }
912}
913
914#[cfg(not(feature = "redact-generated-debug"))]
915impl std::fmt::Debug for SetupIntentFlowDirections {
916    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
917        f.write_str(self.as_str())
918    }
919}
920#[cfg(feature = "redact-generated-debug")]
921impl std::fmt::Debug for SetupIntentFlowDirections {
922    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
923        f.debug_struct(stringify!(SetupIntentFlowDirections)).finish_non_exhaustive()
924    }
925}
926impl serde::Serialize for SetupIntentFlowDirections {
927    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
928    where
929        S: serde::Serializer,
930    {
931        serializer.serialize_str(self.as_str())
932    }
933}
934impl miniserde::Deserialize for SetupIntentFlowDirections {
935    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
936        crate::Place::new(out)
937    }
938}
939
940impl miniserde::de::Visitor for crate::Place<SetupIntentFlowDirections> {
941    fn string(&mut self, s: &str) -> miniserde::Result<()> {
942        use std::str::FromStr;
943        self.out = Some(SetupIntentFlowDirections::from_str(s).expect("infallible"));
944        Ok(())
945    }
946}
947
948stripe_types::impl_from_val_with_from_str!(SetupIntentFlowDirections);
949#[cfg(feature = "deserialize")]
950impl<'de> serde::Deserialize<'de> for SetupIntentFlowDirections {
951    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
952        use std::str::FromStr;
953        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
954        Ok(Self::from_str(&s).expect("infallible"))
955    }
956}