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