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    /// Indicates the directions of money movement for which this payment method is intended to be used.
55    ///
56    /// Include `inbound` if you intend to use the payment method as the origin to pull funds from.
57    /// Include `outbound` if you intend to use the payment method as the destination to send funds to.
58    /// You can include both if you intend to use the payment method for both purposes.
59    pub flow_directions: Option<Vec<stripe_shared::SetupIntentFlowDirections>>,
60    /// Unique identifier for the object.
61    pub id: stripe_shared::SetupIntentId,
62    /// The error encountered in the previous SetupIntent confirmation.
63    pub last_setup_error: Option<Box<stripe_shared::ApiErrors>>,
64    /// The most recent SetupAttempt for this SetupIntent.
65    pub latest_attempt: Option<stripe_types::Expandable<stripe_shared::SetupAttempt>>,
66    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
67    pub livemode: bool,
68    /// ID of the multi use Mandate generated by the SetupIntent.
69    pub mandate: Option<stripe_types::Expandable<stripe_shared::Mandate>>,
70    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
71    /// This can be useful for storing additional information about the object in a structured format.
72    pub metadata: Option<std::collections::HashMap<String, String>>,
73    /// If present, this property tells you what actions you need to take in order for your customer to continue payment setup.
74    pub next_action: Option<stripe_shared::SetupIntentNextAction>,
75    /// The account (if any) for which the setup is intended.
76    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
77    /// ID of the payment method used with this SetupIntent.
78    /// 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.
79    pub payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
80    /// Information about the [payment method configuration](https://stripe.com/docs/api/payment_method_configurations) used for this Setup Intent.
81    pub payment_method_configuration_details:
82        Option<stripe_shared::PaymentMethodConfigBizPaymentMethodConfigurationDetails>,
83    /// Payment method-specific configuration for this SetupIntent.
84    pub payment_method_options: Option<stripe_shared::SetupIntentPaymentMethodOptions>,
85    /// The list of payment method types (e.g.
86    /// card) that this SetupIntent is allowed to set up.
87    /// A list of valid payment method types can be found [here](https://docs.stripe.com/api/payment_methods/object#payment_method_object-type).
88    pub payment_method_types: Vec<String>,
89    /// ID of the single_use Mandate generated by the SetupIntent.
90    pub single_use_mandate: Option<stripe_types::Expandable<stripe_shared::Mandate>>,
91    /// [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`.
92    pub status: SetupIntentStatus,
93    /// Indicates how the payment method is intended to be used in the future.
94    ///
95    /// Use `on_session` if you intend to only reuse the payment method when the customer is in your checkout flow.
96    /// Use `off_session` if your customer may or may not be in your checkout flow.
97    /// If not provided, this value defaults to `off_session`.
98    pub usage: String,
99}
100#[doc(hidden)]
101pub struct SetupIntentBuilder {
102    application: Option<Option<stripe_types::Expandable<stripe_shared::Application>>>,
103    attach_to_self: Option<Option<bool>>,
104    automatic_payment_methods:
105        Option<Option<stripe_shared::PaymentFlowsAutomaticPaymentMethodsSetupIntent>>,
106    cancellation_reason: Option<Option<stripe_shared::SetupIntentCancellationReason>>,
107    client_secret: Option<Option<String>>,
108    created: Option<stripe_types::Timestamp>,
109    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
110    description: Option<Option<String>>,
111    flow_directions: Option<Option<Vec<stripe_shared::SetupIntentFlowDirections>>>,
112    id: Option<stripe_shared::SetupIntentId>,
113    last_setup_error: Option<Option<Box<stripe_shared::ApiErrors>>>,
114    latest_attempt: Option<Option<stripe_types::Expandable<stripe_shared::SetupAttempt>>>,
115    livemode: Option<bool>,
116    mandate: Option<Option<stripe_types::Expandable<stripe_shared::Mandate>>>,
117    metadata: Option<Option<std::collections::HashMap<String, String>>>,
118    next_action: Option<Option<stripe_shared::SetupIntentNextAction>>,
119    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
120    payment_method: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
121    payment_method_configuration_details:
122        Option<Option<stripe_shared::PaymentMethodConfigBizPaymentMethodConfigurationDetails>>,
123    payment_method_options: Option<Option<stripe_shared::SetupIntentPaymentMethodOptions>>,
124    payment_method_types: Option<Vec<String>>,
125    single_use_mandate: Option<Option<stripe_types::Expandable<stripe_shared::Mandate>>>,
126    status: Option<SetupIntentStatus>,
127    usage: Option<String>,
128}
129
130#[allow(
131    unused_variables,
132    irrefutable_let_patterns,
133    clippy::let_unit_value,
134    clippy::match_single_binding,
135    clippy::single_match
136)]
137const _: () = {
138    use miniserde::de::{Map, Visitor};
139    use miniserde::json::Value;
140    use miniserde::{make_place, Deserialize, Result};
141    use stripe_types::miniserde_helpers::FromValueOpt;
142    use stripe_types::{MapBuilder, ObjectDeser};
143
144    make_place!(Place);
145
146    impl Deserialize for SetupIntent {
147        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
148            Place::new(out)
149        }
150    }
151
152    struct Builder<'a> {
153        out: &'a mut Option<SetupIntent>,
154        builder: SetupIntentBuilder,
155    }
156
157    impl Visitor for Place<SetupIntent> {
158        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
159            Ok(Box::new(Builder {
160                out: &mut self.out,
161                builder: SetupIntentBuilder::deser_default(),
162            }))
163        }
164    }
165
166    impl MapBuilder for SetupIntentBuilder {
167        type Out = SetupIntent;
168        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
169            Ok(match k {
170                "application" => Deserialize::begin(&mut self.application),
171                "attach_to_self" => Deserialize::begin(&mut self.attach_to_self),
172                "automatic_payment_methods" => {
173                    Deserialize::begin(&mut self.automatic_payment_methods)
174                }
175                "cancellation_reason" => Deserialize::begin(&mut self.cancellation_reason),
176                "client_secret" => Deserialize::begin(&mut self.client_secret),
177                "created" => Deserialize::begin(&mut self.created),
178                "customer" => Deserialize::begin(&mut self.customer),
179                "description" => Deserialize::begin(&mut self.description),
180                "flow_directions" => Deserialize::begin(&mut self.flow_directions),
181                "id" => Deserialize::begin(&mut self.id),
182                "last_setup_error" => Deserialize::begin(&mut self.last_setup_error),
183                "latest_attempt" => Deserialize::begin(&mut self.latest_attempt),
184                "livemode" => Deserialize::begin(&mut self.livemode),
185                "mandate" => Deserialize::begin(&mut self.mandate),
186                "metadata" => Deserialize::begin(&mut self.metadata),
187                "next_action" => Deserialize::begin(&mut self.next_action),
188                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
189                "payment_method" => Deserialize::begin(&mut self.payment_method),
190                "payment_method_configuration_details" => {
191                    Deserialize::begin(&mut self.payment_method_configuration_details)
192                }
193                "payment_method_options" => Deserialize::begin(&mut self.payment_method_options),
194                "payment_method_types" => Deserialize::begin(&mut self.payment_method_types),
195                "single_use_mandate" => Deserialize::begin(&mut self.single_use_mandate),
196                "status" => Deserialize::begin(&mut self.status),
197                "usage" => Deserialize::begin(&mut self.usage),
198
199                _ => <dyn Visitor>::ignore(),
200            })
201        }
202
203        fn deser_default() -> Self {
204            Self {
205                application: Deserialize::default(),
206                attach_to_self: Deserialize::default(),
207                automatic_payment_methods: Deserialize::default(),
208                cancellation_reason: Deserialize::default(),
209                client_secret: Deserialize::default(),
210                created: Deserialize::default(),
211                customer: Deserialize::default(),
212                description: Deserialize::default(),
213                flow_directions: Deserialize::default(),
214                id: Deserialize::default(),
215                last_setup_error: Deserialize::default(),
216                latest_attempt: Deserialize::default(),
217                livemode: Deserialize::default(),
218                mandate: Deserialize::default(),
219                metadata: Deserialize::default(),
220                next_action: Deserialize::default(),
221                on_behalf_of: Deserialize::default(),
222                payment_method: Deserialize::default(),
223                payment_method_configuration_details: Deserialize::default(),
224                payment_method_options: Deserialize::default(),
225                payment_method_types: Deserialize::default(),
226                single_use_mandate: Deserialize::default(),
227                status: Deserialize::default(),
228                usage: Deserialize::default(),
229            }
230        }
231
232        fn take_out(&mut self) -> Option<Self::Out> {
233            let (
234                Some(application),
235                Some(attach_to_self),
236                Some(automatic_payment_methods),
237                Some(cancellation_reason),
238                Some(client_secret),
239                Some(created),
240                Some(customer),
241                Some(description),
242                Some(flow_directions),
243                Some(id),
244                Some(last_setup_error),
245                Some(latest_attempt),
246                Some(livemode),
247                Some(mandate),
248                Some(metadata),
249                Some(next_action),
250                Some(on_behalf_of),
251                Some(payment_method),
252                Some(payment_method_configuration_details),
253                Some(payment_method_options),
254                Some(payment_method_types),
255                Some(single_use_mandate),
256                Some(status),
257                Some(usage),
258            ) = (
259                self.application.take(),
260                self.attach_to_self,
261                self.automatic_payment_methods,
262                self.cancellation_reason,
263                self.client_secret.take(),
264                self.created,
265                self.customer.take(),
266                self.description.take(),
267                self.flow_directions.take(),
268                self.id.take(),
269                self.last_setup_error.take(),
270                self.latest_attempt.take(),
271                self.livemode,
272                self.mandate.take(),
273                self.metadata.take(),
274                self.next_action.take(),
275                self.on_behalf_of.take(),
276                self.payment_method.take(),
277                self.payment_method_configuration_details.take(),
278                self.payment_method_options.take(),
279                self.payment_method_types.take(),
280                self.single_use_mandate.take(),
281                self.status,
282                self.usage.take(),
283            )
284            else {
285                return None;
286            };
287            Some(Self::Out {
288                application,
289                attach_to_self,
290                automatic_payment_methods,
291                cancellation_reason,
292                client_secret,
293                created,
294                customer,
295                description,
296                flow_directions,
297                id,
298                last_setup_error,
299                latest_attempt,
300                livemode,
301                mandate,
302                metadata,
303                next_action,
304                on_behalf_of,
305                payment_method,
306                payment_method_configuration_details,
307                payment_method_options,
308                payment_method_types,
309                single_use_mandate,
310                status,
311                usage,
312            })
313        }
314    }
315
316    impl Map for Builder<'_> {
317        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
318            self.builder.key(k)
319        }
320
321        fn finish(&mut self) -> Result<()> {
322            *self.out = self.builder.take_out();
323            Ok(())
324        }
325    }
326
327    impl ObjectDeser for SetupIntent {
328        type Builder = SetupIntentBuilder;
329    }
330
331    impl FromValueOpt for SetupIntent {
332        fn from_value(v: Value) -> Option<Self> {
333            let Value::Object(obj) = v else {
334                return None;
335            };
336            let mut b = SetupIntentBuilder::deser_default();
337            for (k, v) in obj {
338                match k.as_str() {
339                    "application" => b.application = FromValueOpt::from_value(v),
340                    "attach_to_self" => b.attach_to_self = FromValueOpt::from_value(v),
341                    "automatic_payment_methods" => {
342                        b.automatic_payment_methods = FromValueOpt::from_value(v)
343                    }
344                    "cancellation_reason" => b.cancellation_reason = FromValueOpt::from_value(v),
345                    "client_secret" => b.client_secret = FromValueOpt::from_value(v),
346                    "created" => b.created = FromValueOpt::from_value(v),
347                    "customer" => b.customer = FromValueOpt::from_value(v),
348                    "description" => b.description = FromValueOpt::from_value(v),
349                    "flow_directions" => b.flow_directions = FromValueOpt::from_value(v),
350                    "id" => b.id = FromValueOpt::from_value(v),
351                    "last_setup_error" => b.last_setup_error = FromValueOpt::from_value(v),
352                    "latest_attempt" => b.latest_attempt = FromValueOpt::from_value(v),
353                    "livemode" => b.livemode = FromValueOpt::from_value(v),
354                    "mandate" => b.mandate = FromValueOpt::from_value(v),
355                    "metadata" => b.metadata = FromValueOpt::from_value(v),
356                    "next_action" => b.next_action = FromValueOpt::from_value(v),
357                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
358                    "payment_method" => b.payment_method = FromValueOpt::from_value(v),
359                    "payment_method_configuration_details" => {
360                        b.payment_method_configuration_details = FromValueOpt::from_value(v)
361                    }
362                    "payment_method_options" => {
363                        b.payment_method_options = FromValueOpt::from_value(v)
364                    }
365                    "payment_method_types" => b.payment_method_types = FromValueOpt::from_value(v),
366                    "single_use_mandate" => b.single_use_mandate = FromValueOpt::from_value(v),
367                    "status" => b.status = FromValueOpt::from_value(v),
368                    "usage" => b.usage = FromValueOpt::from_value(v),
369
370                    _ => {}
371                }
372            }
373            b.take_out()
374        }
375    }
376};
377#[cfg(feature = "serialize")]
378impl serde::Serialize for SetupIntent {
379    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
380        use serde::ser::SerializeStruct;
381        let mut s = s.serialize_struct("SetupIntent", 25)?;
382        s.serialize_field("application", &self.application)?;
383        s.serialize_field("attach_to_self", &self.attach_to_self)?;
384        s.serialize_field("automatic_payment_methods", &self.automatic_payment_methods)?;
385        s.serialize_field("cancellation_reason", &self.cancellation_reason)?;
386        s.serialize_field("client_secret", &self.client_secret)?;
387        s.serialize_field("created", &self.created)?;
388        s.serialize_field("customer", &self.customer)?;
389        s.serialize_field("description", &self.description)?;
390        s.serialize_field("flow_directions", &self.flow_directions)?;
391        s.serialize_field("id", &self.id)?;
392        s.serialize_field("last_setup_error", &self.last_setup_error)?;
393        s.serialize_field("latest_attempt", &self.latest_attempt)?;
394        s.serialize_field("livemode", &self.livemode)?;
395        s.serialize_field("mandate", &self.mandate)?;
396        s.serialize_field("metadata", &self.metadata)?;
397        s.serialize_field("next_action", &self.next_action)?;
398        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
399        s.serialize_field("payment_method", &self.payment_method)?;
400        s.serialize_field(
401            "payment_method_configuration_details",
402            &self.payment_method_configuration_details,
403        )?;
404        s.serialize_field("payment_method_options", &self.payment_method_options)?;
405        s.serialize_field("payment_method_types", &self.payment_method_types)?;
406        s.serialize_field("single_use_mandate", &self.single_use_mandate)?;
407        s.serialize_field("status", &self.status)?;
408        s.serialize_field("usage", &self.usage)?;
409
410        s.serialize_field("object", "setup_intent")?;
411        s.end()
412    }
413}
414/// [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`.
415#[derive(Copy, Clone, Eq, PartialEq)]
416pub enum SetupIntentStatus {
417    Canceled,
418    Processing,
419    RequiresAction,
420    RequiresConfirmation,
421    RequiresPaymentMethod,
422    Succeeded,
423}
424impl SetupIntentStatus {
425    pub fn as_str(self) -> &'static str {
426        use SetupIntentStatus::*;
427        match self {
428            Canceled => "canceled",
429            Processing => "processing",
430            RequiresAction => "requires_action",
431            RequiresConfirmation => "requires_confirmation",
432            RequiresPaymentMethod => "requires_payment_method",
433            Succeeded => "succeeded",
434        }
435    }
436}
437
438impl std::str::FromStr for SetupIntentStatus {
439    type Err = stripe_types::StripeParseError;
440    fn from_str(s: &str) -> Result<Self, Self::Err> {
441        use SetupIntentStatus::*;
442        match s {
443            "canceled" => Ok(Canceled),
444            "processing" => Ok(Processing),
445            "requires_action" => Ok(RequiresAction),
446            "requires_confirmation" => Ok(RequiresConfirmation),
447            "requires_payment_method" => Ok(RequiresPaymentMethod),
448            "succeeded" => Ok(Succeeded),
449            _ => Err(stripe_types::StripeParseError),
450        }
451    }
452}
453impl std::fmt::Display for SetupIntentStatus {
454    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
455        f.write_str(self.as_str())
456    }
457}
458
459impl std::fmt::Debug for SetupIntentStatus {
460    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
461        f.write_str(self.as_str())
462    }
463}
464#[cfg(feature = "serialize")]
465impl serde::Serialize for SetupIntentStatus {
466    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
467    where
468        S: serde::Serializer,
469    {
470        serializer.serialize_str(self.as_str())
471    }
472}
473impl miniserde::Deserialize for SetupIntentStatus {
474    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
475        crate::Place::new(out)
476    }
477}
478
479impl miniserde::de::Visitor for crate::Place<SetupIntentStatus> {
480    fn string(&mut self, s: &str) -> miniserde::Result<()> {
481        use std::str::FromStr;
482        self.out = Some(SetupIntentStatus::from_str(s).map_err(|_| miniserde::Error)?);
483        Ok(())
484    }
485}
486
487stripe_types::impl_from_val_with_from_str!(SetupIntentStatus);
488#[cfg(feature = "deserialize")]
489impl<'de> serde::Deserialize<'de> for SetupIntentStatus {
490    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
491        use std::str::FromStr;
492        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
493        Self::from_str(&s)
494            .map_err(|_| serde::de::Error::custom("Unknown value for SetupIntentStatus"))
495    }
496}
497impl stripe_types::Object for SetupIntent {
498    type Id = stripe_shared::SetupIntentId;
499    fn id(&self) -> &Self::Id {
500        &self.id
501    }
502
503    fn into_id(self) -> Self::Id {
504        self.id
505    }
506}
507stripe_types::def_id!(SetupIntentId);
508#[derive(Copy, Clone, Eq, PartialEq)]
509pub enum SetupIntentCancellationReason {
510    Abandoned,
511    Duplicate,
512    RequestedByCustomer,
513}
514impl SetupIntentCancellationReason {
515    pub fn as_str(self) -> &'static str {
516        use SetupIntentCancellationReason::*;
517        match self {
518            Abandoned => "abandoned",
519            Duplicate => "duplicate",
520            RequestedByCustomer => "requested_by_customer",
521        }
522    }
523}
524
525impl std::str::FromStr for SetupIntentCancellationReason {
526    type Err = stripe_types::StripeParseError;
527    fn from_str(s: &str) -> Result<Self, Self::Err> {
528        use SetupIntentCancellationReason::*;
529        match s {
530            "abandoned" => Ok(Abandoned),
531            "duplicate" => Ok(Duplicate),
532            "requested_by_customer" => Ok(RequestedByCustomer),
533            _ => Err(stripe_types::StripeParseError),
534        }
535    }
536}
537impl std::fmt::Display for SetupIntentCancellationReason {
538    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
539        f.write_str(self.as_str())
540    }
541}
542
543impl std::fmt::Debug for SetupIntentCancellationReason {
544    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
545        f.write_str(self.as_str())
546    }
547}
548impl serde::Serialize for SetupIntentCancellationReason {
549    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
550    where
551        S: serde::Serializer,
552    {
553        serializer.serialize_str(self.as_str())
554    }
555}
556impl miniserde::Deserialize for SetupIntentCancellationReason {
557    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
558        crate::Place::new(out)
559    }
560}
561
562impl miniserde::de::Visitor for crate::Place<SetupIntentCancellationReason> {
563    fn string(&mut self, s: &str) -> miniserde::Result<()> {
564        use std::str::FromStr;
565        self.out = Some(SetupIntentCancellationReason::from_str(s).map_err(|_| miniserde::Error)?);
566        Ok(())
567    }
568}
569
570stripe_types::impl_from_val_with_from_str!(SetupIntentCancellationReason);
571#[cfg(feature = "deserialize")]
572impl<'de> serde::Deserialize<'de> for SetupIntentCancellationReason {
573    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
574        use std::str::FromStr;
575        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
576        Self::from_str(&s).map_err(|_| {
577            serde::de::Error::custom("Unknown value for SetupIntentCancellationReason")
578        })
579    }
580}
581#[derive(Copy, Clone, Eq, PartialEq)]
582pub enum SetupIntentFlowDirections {
583    Inbound,
584    Outbound,
585}
586impl SetupIntentFlowDirections {
587    pub fn as_str(self) -> &'static str {
588        use SetupIntentFlowDirections::*;
589        match self {
590            Inbound => "inbound",
591            Outbound => "outbound",
592        }
593    }
594}
595
596impl std::str::FromStr for SetupIntentFlowDirections {
597    type Err = stripe_types::StripeParseError;
598    fn from_str(s: &str) -> Result<Self, Self::Err> {
599        use SetupIntentFlowDirections::*;
600        match s {
601            "inbound" => Ok(Inbound),
602            "outbound" => Ok(Outbound),
603            _ => Err(stripe_types::StripeParseError),
604        }
605    }
606}
607impl std::fmt::Display for SetupIntentFlowDirections {
608    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
609        f.write_str(self.as_str())
610    }
611}
612
613impl std::fmt::Debug for SetupIntentFlowDirections {
614    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
615        f.write_str(self.as_str())
616    }
617}
618impl serde::Serialize for SetupIntentFlowDirections {
619    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
620    where
621        S: serde::Serializer,
622    {
623        serializer.serialize_str(self.as_str())
624    }
625}
626impl miniserde::Deserialize for SetupIntentFlowDirections {
627    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
628        crate::Place::new(out)
629    }
630}
631
632impl miniserde::de::Visitor for crate::Place<SetupIntentFlowDirections> {
633    fn string(&mut self, s: &str) -> miniserde::Result<()> {
634        use std::str::FromStr;
635        self.out = Some(SetupIntentFlowDirections::from_str(s).map_err(|_| miniserde::Error)?);
636        Ok(())
637    }
638}
639
640stripe_types::impl_from_val_with_from_str!(SetupIntentFlowDirections);
641#[cfg(feature = "deserialize")]
642impl<'de> serde::Deserialize<'de> for SetupIntentFlowDirections {
643    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
644        use std::str::FromStr;
645        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
646        Self::from_str(&s)
647            .map_err(|_| serde::de::Error::custom("Unknown value for SetupIntentFlowDirections"))
648    }
649}