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