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.take(),
271                self.cancellation_reason.take(),
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.take(),
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(Clone, Eq, PartialEq)]
430#[non_exhaustive]
431pub enum SetupIntentStatus {
432    Canceled,
433    Processing,
434    RequiresAction,
435    RequiresConfirmation,
436    RequiresPaymentMethod,
437    Succeeded,
438    /// An unrecognized value from Stripe. Should not be used as a request parameter.
439    Unknown(String),
440}
441impl SetupIntentStatus {
442    pub fn as_str(&self) -> &str {
443        use SetupIntentStatus::*;
444        match self {
445            Canceled => "canceled",
446            Processing => "processing",
447            RequiresAction => "requires_action",
448            RequiresConfirmation => "requires_confirmation",
449            RequiresPaymentMethod => "requires_payment_method",
450            Succeeded => "succeeded",
451            Unknown(v) => v,
452        }
453    }
454}
455
456impl std::str::FromStr for SetupIntentStatus {
457    type Err = std::convert::Infallible;
458    fn from_str(s: &str) -> Result<Self, Self::Err> {
459        use SetupIntentStatus::*;
460        match s {
461            "canceled" => Ok(Canceled),
462            "processing" => Ok(Processing),
463            "requires_action" => Ok(RequiresAction),
464            "requires_confirmation" => Ok(RequiresConfirmation),
465            "requires_payment_method" => Ok(RequiresPaymentMethod),
466            "succeeded" => Ok(Succeeded),
467            v => {
468                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SetupIntentStatus");
469                Ok(Unknown(v.to_owned()))
470            }
471        }
472    }
473}
474impl std::fmt::Display for SetupIntentStatus {
475    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
476        f.write_str(self.as_str())
477    }
478}
479
480impl std::fmt::Debug for SetupIntentStatus {
481    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
482        f.write_str(self.as_str())
483    }
484}
485#[cfg(feature = "serialize")]
486impl serde::Serialize for SetupIntentStatus {
487    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
488    where
489        S: serde::Serializer,
490    {
491        serializer.serialize_str(self.as_str())
492    }
493}
494impl miniserde::Deserialize for SetupIntentStatus {
495    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
496        crate::Place::new(out)
497    }
498}
499
500impl miniserde::de::Visitor for crate::Place<SetupIntentStatus> {
501    fn string(&mut self, s: &str) -> miniserde::Result<()> {
502        use std::str::FromStr;
503        self.out = Some(SetupIntentStatus::from_str(s).expect("infallible"));
504        Ok(())
505    }
506}
507
508stripe_types::impl_from_val_with_from_str!(SetupIntentStatus);
509#[cfg(feature = "deserialize")]
510impl<'de> serde::Deserialize<'de> for SetupIntentStatus {
511    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
512        use std::str::FromStr;
513        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
514        Ok(Self::from_str(&s).expect("infallible"))
515    }
516}
517impl stripe_types::Object for SetupIntent {
518    type Id = stripe_shared::SetupIntentId;
519    fn id(&self) -> &Self::Id {
520        &self.id
521    }
522
523    fn into_id(self) -> Self::Id {
524        self.id
525    }
526}
527stripe_types::def_id!(SetupIntentId);
528#[derive(Clone, Eq, PartialEq)]
529#[non_exhaustive]
530pub enum SetupIntentCancellationReason {
531    Abandoned,
532    Duplicate,
533    RequestedByCustomer,
534    /// An unrecognized value from Stripe. Should not be used as a request parameter.
535    Unknown(String),
536}
537impl SetupIntentCancellationReason {
538    pub fn as_str(&self) -> &str {
539        use SetupIntentCancellationReason::*;
540        match self {
541            Abandoned => "abandoned",
542            Duplicate => "duplicate",
543            RequestedByCustomer => "requested_by_customer",
544            Unknown(v) => v,
545        }
546    }
547}
548
549impl std::str::FromStr for SetupIntentCancellationReason {
550    type Err = std::convert::Infallible;
551    fn from_str(s: &str) -> Result<Self, Self::Err> {
552        use SetupIntentCancellationReason::*;
553        match s {
554            "abandoned" => Ok(Abandoned),
555            "duplicate" => Ok(Duplicate),
556            "requested_by_customer" => Ok(RequestedByCustomer),
557            v => {
558                tracing::warn!(
559                    "Unknown value '{}' for enum '{}'",
560                    v,
561                    "SetupIntentCancellationReason"
562                );
563                Ok(Unknown(v.to_owned()))
564            }
565        }
566    }
567}
568impl std::fmt::Display for SetupIntentCancellationReason {
569    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
570        f.write_str(self.as_str())
571    }
572}
573
574impl std::fmt::Debug for SetupIntentCancellationReason {
575    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
576        f.write_str(self.as_str())
577    }
578}
579impl serde::Serialize for SetupIntentCancellationReason {
580    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
581    where
582        S: serde::Serializer,
583    {
584        serializer.serialize_str(self.as_str())
585    }
586}
587impl miniserde::Deserialize for SetupIntentCancellationReason {
588    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
589        crate::Place::new(out)
590    }
591}
592
593impl miniserde::de::Visitor for crate::Place<SetupIntentCancellationReason> {
594    fn string(&mut self, s: &str) -> miniserde::Result<()> {
595        use std::str::FromStr;
596        self.out = Some(SetupIntentCancellationReason::from_str(s).expect("infallible"));
597        Ok(())
598    }
599}
600
601stripe_types::impl_from_val_with_from_str!(SetupIntentCancellationReason);
602#[cfg(feature = "deserialize")]
603impl<'de> serde::Deserialize<'de> for SetupIntentCancellationReason {
604    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
605        use std::str::FromStr;
606        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
607        Ok(Self::from_str(&s).expect("infallible"))
608    }
609}
610#[derive(Clone, Eq, PartialEq)]
611#[non_exhaustive]
612pub enum SetupIntentExcludedPaymentMethodTypes {
613    AcssDebit,
614    Affirm,
615    AfterpayClearpay,
616    Alipay,
617    Alma,
618    AmazonPay,
619    AuBecsDebit,
620    BacsDebit,
621    Bancontact,
622    Billie,
623    Blik,
624    Boleto,
625    Card,
626    Cashapp,
627    Crypto,
628    CustomerBalance,
629    Eps,
630    Fpx,
631    Giropay,
632    Grabpay,
633    Ideal,
634    KakaoPay,
635    Klarna,
636    Konbini,
637    KrCard,
638    MbWay,
639    Mobilepay,
640    Multibanco,
641    NaverPay,
642    NzBankAccount,
643    Oxxo,
644    P24,
645    PayByBank,
646    Payco,
647    Paynow,
648    Paypal,
649    Pix,
650    Promptpay,
651    RevolutPay,
652    SamsungPay,
653    Satispay,
654    SepaDebit,
655    Sofort,
656    Swish,
657    Twint,
658    UsBankAccount,
659    WechatPay,
660    Zip,
661    /// An unrecognized value from Stripe. Should not be used as a request parameter.
662    Unknown(String),
663}
664impl SetupIntentExcludedPaymentMethodTypes {
665    pub fn as_str(&self) -> &str {
666        use SetupIntentExcludedPaymentMethodTypes::*;
667        match self {
668            AcssDebit => "acss_debit",
669            Affirm => "affirm",
670            AfterpayClearpay => "afterpay_clearpay",
671            Alipay => "alipay",
672            Alma => "alma",
673            AmazonPay => "amazon_pay",
674            AuBecsDebit => "au_becs_debit",
675            BacsDebit => "bacs_debit",
676            Bancontact => "bancontact",
677            Billie => "billie",
678            Blik => "blik",
679            Boleto => "boleto",
680            Card => "card",
681            Cashapp => "cashapp",
682            Crypto => "crypto",
683            CustomerBalance => "customer_balance",
684            Eps => "eps",
685            Fpx => "fpx",
686            Giropay => "giropay",
687            Grabpay => "grabpay",
688            Ideal => "ideal",
689            KakaoPay => "kakao_pay",
690            Klarna => "klarna",
691            Konbini => "konbini",
692            KrCard => "kr_card",
693            MbWay => "mb_way",
694            Mobilepay => "mobilepay",
695            Multibanco => "multibanco",
696            NaverPay => "naver_pay",
697            NzBankAccount => "nz_bank_account",
698            Oxxo => "oxxo",
699            P24 => "p24",
700            PayByBank => "pay_by_bank",
701            Payco => "payco",
702            Paynow => "paynow",
703            Paypal => "paypal",
704            Pix => "pix",
705            Promptpay => "promptpay",
706            RevolutPay => "revolut_pay",
707            SamsungPay => "samsung_pay",
708            Satispay => "satispay",
709            SepaDebit => "sepa_debit",
710            Sofort => "sofort",
711            Swish => "swish",
712            Twint => "twint",
713            UsBankAccount => "us_bank_account",
714            WechatPay => "wechat_pay",
715            Zip => "zip",
716            Unknown(v) => v,
717        }
718    }
719}
720
721impl std::str::FromStr for SetupIntentExcludedPaymentMethodTypes {
722    type Err = std::convert::Infallible;
723    fn from_str(s: &str) -> Result<Self, Self::Err> {
724        use SetupIntentExcludedPaymentMethodTypes::*;
725        match s {
726            "acss_debit" => Ok(AcssDebit),
727            "affirm" => Ok(Affirm),
728            "afterpay_clearpay" => Ok(AfterpayClearpay),
729            "alipay" => Ok(Alipay),
730            "alma" => Ok(Alma),
731            "amazon_pay" => Ok(AmazonPay),
732            "au_becs_debit" => Ok(AuBecsDebit),
733            "bacs_debit" => Ok(BacsDebit),
734            "bancontact" => Ok(Bancontact),
735            "billie" => Ok(Billie),
736            "blik" => Ok(Blik),
737            "boleto" => Ok(Boleto),
738            "card" => Ok(Card),
739            "cashapp" => Ok(Cashapp),
740            "crypto" => Ok(Crypto),
741            "customer_balance" => Ok(CustomerBalance),
742            "eps" => Ok(Eps),
743            "fpx" => Ok(Fpx),
744            "giropay" => Ok(Giropay),
745            "grabpay" => Ok(Grabpay),
746            "ideal" => Ok(Ideal),
747            "kakao_pay" => Ok(KakaoPay),
748            "klarna" => Ok(Klarna),
749            "konbini" => Ok(Konbini),
750            "kr_card" => Ok(KrCard),
751            "mb_way" => Ok(MbWay),
752            "mobilepay" => Ok(Mobilepay),
753            "multibanco" => Ok(Multibanco),
754            "naver_pay" => Ok(NaverPay),
755            "nz_bank_account" => Ok(NzBankAccount),
756            "oxxo" => Ok(Oxxo),
757            "p24" => Ok(P24),
758            "pay_by_bank" => Ok(PayByBank),
759            "payco" => Ok(Payco),
760            "paynow" => Ok(Paynow),
761            "paypal" => Ok(Paypal),
762            "pix" => Ok(Pix),
763            "promptpay" => Ok(Promptpay),
764            "revolut_pay" => Ok(RevolutPay),
765            "samsung_pay" => Ok(SamsungPay),
766            "satispay" => Ok(Satispay),
767            "sepa_debit" => Ok(SepaDebit),
768            "sofort" => Ok(Sofort),
769            "swish" => Ok(Swish),
770            "twint" => Ok(Twint),
771            "us_bank_account" => Ok(UsBankAccount),
772            "wechat_pay" => Ok(WechatPay),
773            "zip" => Ok(Zip),
774            v => {
775                tracing::warn!(
776                    "Unknown value '{}' for enum '{}'",
777                    v,
778                    "SetupIntentExcludedPaymentMethodTypes"
779                );
780                Ok(Unknown(v.to_owned()))
781            }
782        }
783    }
784}
785impl std::fmt::Display for SetupIntentExcludedPaymentMethodTypes {
786    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
787        f.write_str(self.as_str())
788    }
789}
790
791impl std::fmt::Debug for SetupIntentExcludedPaymentMethodTypes {
792    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
793        f.write_str(self.as_str())
794    }
795}
796impl serde::Serialize for SetupIntentExcludedPaymentMethodTypes {
797    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
798    where
799        S: serde::Serializer,
800    {
801        serializer.serialize_str(self.as_str())
802    }
803}
804impl miniserde::Deserialize for SetupIntentExcludedPaymentMethodTypes {
805    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
806        crate::Place::new(out)
807    }
808}
809
810impl miniserde::de::Visitor for crate::Place<SetupIntentExcludedPaymentMethodTypes> {
811    fn string(&mut self, s: &str) -> miniserde::Result<()> {
812        use std::str::FromStr;
813        self.out = Some(SetupIntentExcludedPaymentMethodTypes::from_str(s).expect("infallible"));
814        Ok(())
815    }
816}
817
818stripe_types::impl_from_val_with_from_str!(SetupIntentExcludedPaymentMethodTypes);
819#[cfg(feature = "deserialize")]
820impl<'de> serde::Deserialize<'de> for SetupIntentExcludedPaymentMethodTypes {
821    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
822        use std::str::FromStr;
823        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
824        Ok(Self::from_str(&s).expect("infallible"))
825    }
826}
827#[derive(Clone, Eq, PartialEq)]
828#[non_exhaustive]
829pub enum SetupIntentFlowDirections {
830    Inbound,
831    Outbound,
832    /// An unrecognized value from Stripe. Should not be used as a request parameter.
833    Unknown(String),
834}
835impl SetupIntentFlowDirections {
836    pub fn as_str(&self) -> &str {
837        use SetupIntentFlowDirections::*;
838        match self {
839            Inbound => "inbound",
840            Outbound => "outbound",
841            Unknown(v) => v,
842        }
843    }
844}
845
846impl std::str::FromStr for SetupIntentFlowDirections {
847    type Err = std::convert::Infallible;
848    fn from_str(s: &str) -> Result<Self, Self::Err> {
849        use SetupIntentFlowDirections::*;
850        match s {
851            "inbound" => Ok(Inbound),
852            "outbound" => Ok(Outbound),
853            v => {
854                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SetupIntentFlowDirections");
855                Ok(Unknown(v.to_owned()))
856            }
857        }
858    }
859}
860impl std::fmt::Display for SetupIntentFlowDirections {
861    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
862        f.write_str(self.as_str())
863    }
864}
865
866impl std::fmt::Debug for SetupIntentFlowDirections {
867    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
868        f.write_str(self.as_str())
869    }
870}
871impl serde::Serialize for SetupIntentFlowDirections {
872    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
873    where
874        S: serde::Serializer,
875    {
876        serializer.serialize_str(self.as_str())
877    }
878}
879impl miniserde::Deserialize for SetupIntentFlowDirections {
880    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
881        crate::Place::new(out)
882    }
883}
884
885impl miniserde::de::Visitor for crate::Place<SetupIntentFlowDirections> {
886    fn string(&mut self, s: &str) -> miniserde::Result<()> {
887        use std::str::FromStr;
888        self.out = Some(SetupIntentFlowDirections::from_str(s).expect("infallible"));
889        Ok(())
890    }
891}
892
893stripe_types::impl_from_val_with_from_str!(SetupIntentFlowDirections);
894#[cfg(feature = "deserialize")]
895impl<'de> serde::Deserialize<'de> for SetupIntentFlowDirections {
896    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
897        use std::str::FromStr;
898        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
899        Ok(Self::from_str(&s).expect("infallible"))
900    }
901}