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