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