Skip to main content

stripe_shared/
source.rs

1/// `Source` objects allow you to accept a variety of payment methods. They
2/// represent a customer's payment instrument, and can be used with the Stripe API
3/// just like a `Card` object: once chargeable, they can be charged, or can be
4/// attached to customers.
5///
6/// Stripe doesn't recommend using the deprecated [Sources API](https://docs.stripe.com/api/sources).
7/// We recommend that you adopt the [PaymentMethods API](https://docs.stripe.com/api/payment_methods).
8/// This newer API provides access to our latest features and payment method types.
9///
10/// Related guides: [Sources API](https://docs.stripe.com/sources) and [Sources & Customers](https://docs.stripe.com/sources/customers).
11///
12/// For more details see <<https://stripe.com/docs/api/sources/object>>.
13#[derive(Clone)]
14#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
15#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
16pub struct Source {
17    pub ach_credit_transfer: Option<stripe_shared::SourceTypeAchCreditTransfer>,
18    pub ach_debit: Option<stripe_shared::SourceTypeAchDebit>,
19    pub acss_debit: Option<stripe_shared::SourceTypeAcssDebit>,
20    pub alipay: Option<stripe_shared::SourceTypeAlipay>,
21    /// This field indicates whether this payment method can be shown again to its customer in a checkout flow.
22    /// Stripe products such as Checkout and Elements use this field to determine whether a payment method can be shown as a saved payment method in a checkout flow.
23    /// The field defaults to “unspecified”.
24    pub allow_redisplay: Option<SourceAllowRedisplay>,
25    /// A positive integer in the smallest currency unit (that is, 100 cents for $1.00, or 1 for ¥1, Japanese Yen being a zero-decimal currency) representing the total amount associated with the source.
26    /// This is the amount for which the source will be chargeable once ready.
27    /// Required for `single_use` sources.
28    pub amount: Option<i64>,
29    pub au_becs_debit: Option<stripe_shared::SourceTypeAuBecsDebit>,
30    pub bancontact: Option<stripe_shared::SourceTypeBancontact>,
31    pub card: Option<stripe_shared::SourceTypeCard>,
32    pub card_present: Option<stripe_shared::SourceTypeCardPresent>,
33    /// The client secret of the source. Used for client-side retrieval using a publishable key.
34    pub client_secret: String,
35    pub code_verification: Option<stripe_shared::SourceCodeVerificationFlow>,
36    /// Time at which the object was created. Measured in seconds since the Unix epoch.
37    pub created: stripe_types::Timestamp,
38    /// Three-letter [ISO code for the currency](https://stripe.com/docs/currencies) associated with the source.
39    /// This is the currency for which the source will be chargeable once ready.
40    /// Required for `single_use` sources.
41    pub currency: Option<stripe_types::Currency>,
42    /// The ID of the customer to which this source is attached.
43    /// This will not be present when the source has not been attached to a customer.
44    pub customer: Option<String>,
45    pub eps: Option<stripe_shared::SourceTypeEps>,
46    /// The authentication `flow` of the source.
47    /// `flow` is one of `redirect`, `receiver`, `code_verification`, `none`.
48    pub flow: String,
49    pub giropay: Option<stripe_shared::SourceTypeGiropay>,
50    /// Unique identifier for the object.
51    pub id: stripe_shared::SourceId,
52    pub ideal: Option<stripe_shared::SourceTypeIdeal>,
53    pub klarna: Option<stripe_shared::SourceTypeKlarna>,
54    /// If the object exists in live mode, the value is `true`.
55    /// If the object exists in test mode, the value is `false`.
56    pub livemode: bool,
57    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
58    /// This can be useful for storing additional information about the object in a structured format.
59    pub metadata: Option<std::collections::HashMap<String, String>>,
60    pub multibanco: Option<stripe_shared::SourceTypeMultibanco>,
61    /// Information about the owner of the payment instrument that may be used or required by particular source types.
62    pub owner: Option<stripe_shared::SourceOwner>,
63    pub p24: Option<stripe_shared::SourceTypeP24>,
64    pub receiver: Option<stripe_shared::SourceReceiverFlow>,
65    pub redirect: Option<stripe_shared::SourceRedirectFlow>,
66    pub sepa_credit_transfer: Option<stripe_shared::SourceTypeSepaCreditTransfer>,
67    pub sepa_debit: Option<stripe_shared::SourceTypeSepaDebit>,
68    pub sofort: Option<stripe_shared::SourceTypeSofort>,
69    pub source_order: Option<stripe_shared::SourceOrder>,
70    /// Extra information about a source.
71    /// This will appear on your customer's statement every time you charge the source.
72    pub statement_descriptor: Option<String>,
73    /// The status of the source, one of `canceled`, `chargeable`, `consumed`, `failed`, or `pending`.
74    /// Only `chargeable` sources can be used to create a charge.
75    pub status: String,
76    pub three_d_secure: Option<stripe_shared::SourceTypeThreeDSecure>,
77    /// The `type` of the source.
78    /// The `type` is a payment method, one of `ach_credit_transfer`, `ach_debit`, `alipay`, `bancontact`, `card`, `card_present`, `eps`, `giropay`, `ideal`, `multibanco`, `klarna`, `p24`, `sepa_debit`, `sofort`, `three_d_secure`, or `wechat`.
79    /// An additional hash is included on the source with a name matching this value.
80    /// It contains additional information specific to the [payment method](https://docs.stripe.com/sources) used.
81    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
82    pub type_: SourceType,
83    /// Either `reusable` or `single_use`.
84    /// Whether this source should be reusable or not.
85    /// Some source types may or may not be reusable by construction, while others may leave the option at creation.
86    /// If an incompatible value is passed, an error will be returned.
87    pub usage: Option<String>,
88    pub wechat: Option<stripe_shared::SourceTypeWechat>,
89}
90#[cfg(feature = "redact-generated-debug")]
91impl std::fmt::Debug for Source {
92    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
93        f.debug_struct("Source").finish_non_exhaustive()
94    }
95}
96#[doc(hidden)]
97pub struct SourceBuilder {
98    ach_credit_transfer: Option<Option<stripe_shared::SourceTypeAchCreditTransfer>>,
99    ach_debit: Option<Option<stripe_shared::SourceTypeAchDebit>>,
100    acss_debit: Option<Option<stripe_shared::SourceTypeAcssDebit>>,
101    alipay: Option<Option<stripe_shared::SourceTypeAlipay>>,
102    allow_redisplay: Option<Option<SourceAllowRedisplay>>,
103    amount: Option<Option<i64>>,
104    au_becs_debit: Option<Option<stripe_shared::SourceTypeAuBecsDebit>>,
105    bancontact: Option<Option<stripe_shared::SourceTypeBancontact>>,
106    card: Option<Option<stripe_shared::SourceTypeCard>>,
107    card_present: Option<Option<stripe_shared::SourceTypeCardPresent>>,
108    client_secret: Option<String>,
109    code_verification: Option<Option<stripe_shared::SourceCodeVerificationFlow>>,
110    created: Option<stripe_types::Timestamp>,
111    currency: Option<Option<stripe_types::Currency>>,
112    customer: Option<Option<String>>,
113    eps: Option<Option<stripe_shared::SourceTypeEps>>,
114    flow: Option<String>,
115    giropay: Option<Option<stripe_shared::SourceTypeGiropay>>,
116    id: Option<stripe_shared::SourceId>,
117    ideal: Option<Option<stripe_shared::SourceTypeIdeal>>,
118    klarna: Option<Option<stripe_shared::SourceTypeKlarna>>,
119    livemode: Option<bool>,
120    metadata: Option<Option<std::collections::HashMap<String, String>>>,
121    multibanco: Option<Option<stripe_shared::SourceTypeMultibanco>>,
122    owner: Option<Option<stripe_shared::SourceOwner>>,
123    p24: Option<Option<stripe_shared::SourceTypeP24>>,
124    receiver: Option<Option<stripe_shared::SourceReceiverFlow>>,
125    redirect: Option<Option<stripe_shared::SourceRedirectFlow>>,
126    sepa_credit_transfer: Option<Option<stripe_shared::SourceTypeSepaCreditTransfer>>,
127    sepa_debit: Option<Option<stripe_shared::SourceTypeSepaDebit>>,
128    sofort: Option<Option<stripe_shared::SourceTypeSofort>>,
129    source_order: Option<Option<stripe_shared::SourceOrder>>,
130    statement_descriptor: Option<Option<String>>,
131    status: Option<String>,
132    three_d_secure: Option<Option<stripe_shared::SourceTypeThreeDSecure>>,
133    type_: Option<SourceType>,
134    usage: Option<Option<String>>,
135    wechat: Option<Option<stripe_shared::SourceTypeWechat>>,
136}
137
138#[allow(
139    unused_variables,
140    irrefutable_let_patterns,
141    clippy::let_unit_value,
142    clippy::match_single_binding,
143    clippy::single_match
144)]
145const _: () = {
146    use miniserde::de::{Map, Visitor};
147    use miniserde::json::Value;
148    use miniserde::{Deserialize, Result, make_place};
149    use stripe_types::miniserde_helpers::FromValueOpt;
150    use stripe_types::{MapBuilder, ObjectDeser};
151
152    make_place!(Place);
153
154    impl Deserialize for Source {
155        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
156            Place::new(out)
157        }
158    }
159
160    struct Builder<'a> {
161        out: &'a mut Option<Source>,
162        builder: SourceBuilder,
163    }
164
165    impl Visitor for Place<Source> {
166        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
167            Ok(Box::new(Builder { out: &mut self.out, builder: SourceBuilder::deser_default() }))
168        }
169    }
170
171    impl MapBuilder for SourceBuilder {
172        type Out = Source;
173        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
174            Ok(match k {
175                "ach_credit_transfer" => Deserialize::begin(&mut self.ach_credit_transfer),
176                "ach_debit" => Deserialize::begin(&mut self.ach_debit),
177                "acss_debit" => Deserialize::begin(&mut self.acss_debit),
178                "alipay" => Deserialize::begin(&mut self.alipay),
179                "allow_redisplay" => Deserialize::begin(&mut self.allow_redisplay),
180                "amount" => Deserialize::begin(&mut self.amount),
181                "au_becs_debit" => Deserialize::begin(&mut self.au_becs_debit),
182                "bancontact" => Deserialize::begin(&mut self.bancontact),
183                "card" => Deserialize::begin(&mut self.card),
184                "card_present" => Deserialize::begin(&mut self.card_present),
185                "client_secret" => Deserialize::begin(&mut self.client_secret),
186                "code_verification" => Deserialize::begin(&mut self.code_verification),
187                "created" => Deserialize::begin(&mut self.created),
188                "currency" => Deserialize::begin(&mut self.currency),
189                "customer" => Deserialize::begin(&mut self.customer),
190                "eps" => Deserialize::begin(&mut self.eps),
191                "flow" => Deserialize::begin(&mut self.flow),
192                "giropay" => Deserialize::begin(&mut self.giropay),
193                "id" => Deserialize::begin(&mut self.id),
194                "ideal" => Deserialize::begin(&mut self.ideal),
195                "klarna" => Deserialize::begin(&mut self.klarna),
196                "livemode" => Deserialize::begin(&mut self.livemode),
197                "metadata" => Deserialize::begin(&mut self.metadata),
198                "multibanco" => Deserialize::begin(&mut self.multibanco),
199                "owner" => Deserialize::begin(&mut self.owner),
200                "p24" => Deserialize::begin(&mut self.p24),
201                "receiver" => Deserialize::begin(&mut self.receiver),
202                "redirect" => Deserialize::begin(&mut self.redirect),
203                "sepa_credit_transfer" => Deserialize::begin(&mut self.sepa_credit_transfer),
204                "sepa_debit" => Deserialize::begin(&mut self.sepa_debit),
205                "sofort" => Deserialize::begin(&mut self.sofort),
206                "source_order" => Deserialize::begin(&mut self.source_order),
207                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
208                "status" => Deserialize::begin(&mut self.status),
209                "three_d_secure" => Deserialize::begin(&mut self.three_d_secure),
210                "type" => Deserialize::begin(&mut self.type_),
211                "usage" => Deserialize::begin(&mut self.usage),
212                "wechat" => Deserialize::begin(&mut self.wechat),
213                _ => <dyn Visitor>::ignore(),
214            })
215        }
216
217        fn deser_default() -> Self {
218            Self {
219                ach_credit_transfer: Deserialize::default(),
220                ach_debit: Deserialize::default(),
221                acss_debit: Deserialize::default(),
222                alipay: Deserialize::default(),
223                allow_redisplay: Deserialize::default(),
224                amount: Deserialize::default(),
225                au_becs_debit: Deserialize::default(),
226                bancontact: Deserialize::default(),
227                card: Deserialize::default(),
228                card_present: Deserialize::default(),
229                client_secret: Deserialize::default(),
230                code_verification: Deserialize::default(),
231                created: Deserialize::default(),
232                currency: Deserialize::default(),
233                customer: Deserialize::default(),
234                eps: Deserialize::default(),
235                flow: Deserialize::default(),
236                giropay: Deserialize::default(),
237                id: Deserialize::default(),
238                ideal: Deserialize::default(),
239                klarna: Deserialize::default(),
240                livemode: Deserialize::default(),
241                metadata: Deserialize::default(),
242                multibanco: Deserialize::default(),
243                owner: Deserialize::default(),
244                p24: Deserialize::default(),
245                receiver: Deserialize::default(),
246                redirect: Deserialize::default(),
247                sepa_credit_transfer: Deserialize::default(),
248                sepa_debit: Deserialize::default(),
249                sofort: Deserialize::default(),
250                source_order: Deserialize::default(),
251                statement_descriptor: Deserialize::default(),
252                status: Deserialize::default(),
253                three_d_secure: Deserialize::default(),
254                type_: Deserialize::default(),
255                usage: Deserialize::default(),
256                wechat: Deserialize::default(),
257            }
258        }
259
260        fn take_out(&mut self) -> Option<Self::Out> {
261            let (
262                Some(ach_credit_transfer),
263                Some(ach_debit),
264                Some(acss_debit),
265                Some(alipay),
266                Some(allow_redisplay),
267                Some(amount),
268                Some(au_becs_debit),
269                Some(bancontact),
270                Some(card),
271                Some(card_present),
272                Some(client_secret),
273                Some(code_verification),
274                Some(created),
275                Some(currency),
276                Some(customer),
277                Some(eps),
278                Some(flow),
279                Some(giropay),
280                Some(id),
281                Some(ideal),
282                Some(klarna),
283                Some(livemode),
284                Some(metadata),
285                Some(multibanco),
286                Some(owner),
287                Some(p24),
288                Some(receiver),
289                Some(redirect),
290                Some(sepa_credit_transfer),
291                Some(sepa_debit),
292                Some(sofort),
293                Some(source_order),
294                Some(statement_descriptor),
295                Some(status),
296                Some(three_d_secure),
297                Some(type_),
298                Some(usage),
299                Some(wechat),
300            ) = (
301                self.ach_credit_transfer.take(),
302                self.ach_debit.take(),
303                self.acss_debit.take(),
304                self.alipay.take(),
305                self.allow_redisplay.take(),
306                self.amount,
307                self.au_becs_debit.take(),
308                self.bancontact.take(),
309                self.card.take(),
310                self.card_present.take(),
311                self.client_secret.take(),
312                self.code_verification.take(),
313                self.created,
314                self.currency.take(),
315                self.customer.take(),
316                self.eps.take(),
317                self.flow.take(),
318                self.giropay.take(),
319                self.id.take(),
320                self.ideal.take(),
321                self.klarna.take(),
322                self.livemode,
323                self.metadata.take(),
324                self.multibanco.take(),
325                self.owner.take(),
326                self.p24.take(),
327                self.receiver.take(),
328                self.redirect.take(),
329                self.sepa_credit_transfer.take(),
330                self.sepa_debit.take(),
331                self.sofort.take(),
332                self.source_order.take(),
333                self.statement_descriptor.take(),
334                self.status.take(),
335                self.three_d_secure.take(),
336                self.type_.take(),
337                self.usage.take(),
338                self.wechat.take(),
339            )
340            else {
341                return None;
342            };
343            Some(Self::Out {
344                ach_credit_transfer,
345                ach_debit,
346                acss_debit,
347                alipay,
348                allow_redisplay,
349                amount,
350                au_becs_debit,
351                bancontact,
352                card,
353                card_present,
354                client_secret,
355                code_verification,
356                created,
357                currency,
358                customer,
359                eps,
360                flow,
361                giropay,
362                id,
363                ideal,
364                klarna,
365                livemode,
366                metadata,
367                multibanco,
368                owner,
369                p24,
370                receiver,
371                redirect,
372                sepa_credit_transfer,
373                sepa_debit,
374                sofort,
375                source_order,
376                statement_descriptor,
377                status,
378                three_d_secure,
379                type_,
380                usage,
381                wechat,
382            })
383        }
384    }
385
386    impl Map for Builder<'_> {
387        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
388            self.builder.key(k)
389        }
390
391        fn finish(&mut self) -> Result<()> {
392            *self.out = self.builder.take_out();
393            Ok(())
394        }
395    }
396
397    impl ObjectDeser for Source {
398        type Builder = SourceBuilder;
399    }
400
401    impl FromValueOpt for Source {
402        fn from_value(v: Value) -> Option<Self> {
403            let Value::Object(obj) = v else {
404                return None;
405            };
406            let mut b = SourceBuilder::deser_default();
407            for (k, v) in obj {
408                match k.as_str() {
409                    "ach_credit_transfer" => b.ach_credit_transfer = FromValueOpt::from_value(v),
410                    "ach_debit" => b.ach_debit = FromValueOpt::from_value(v),
411                    "acss_debit" => b.acss_debit = FromValueOpt::from_value(v),
412                    "alipay" => b.alipay = FromValueOpt::from_value(v),
413                    "allow_redisplay" => b.allow_redisplay = FromValueOpt::from_value(v),
414                    "amount" => b.amount = FromValueOpt::from_value(v),
415                    "au_becs_debit" => b.au_becs_debit = FromValueOpt::from_value(v),
416                    "bancontact" => b.bancontact = FromValueOpt::from_value(v),
417                    "card" => b.card = FromValueOpt::from_value(v),
418                    "card_present" => b.card_present = FromValueOpt::from_value(v),
419                    "client_secret" => b.client_secret = FromValueOpt::from_value(v),
420                    "code_verification" => b.code_verification = FromValueOpt::from_value(v),
421                    "created" => b.created = FromValueOpt::from_value(v),
422                    "currency" => b.currency = FromValueOpt::from_value(v),
423                    "customer" => b.customer = FromValueOpt::from_value(v),
424                    "eps" => b.eps = FromValueOpt::from_value(v),
425                    "flow" => b.flow = FromValueOpt::from_value(v),
426                    "giropay" => b.giropay = FromValueOpt::from_value(v),
427                    "id" => b.id = FromValueOpt::from_value(v),
428                    "ideal" => b.ideal = FromValueOpt::from_value(v),
429                    "klarna" => b.klarna = FromValueOpt::from_value(v),
430                    "livemode" => b.livemode = FromValueOpt::from_value(v),
431                    "metadata" => b.metadata = FromValueOpt::from_value(v),
432                    "multibanco" => b.multibanco = FromValueOpt::from_value(v),
433                    "owner" => b.owner = FromValueOpt::from_value(v),
434                    "p24" => b.p24 = FromValueOpt::from_value(v),
435                    "receiver" => b.receiver = FromValueOpt::from_value(v),
436                    "redirect" => b.redirect = FromValueOpt::from_value(v),
437                    "sepa_credit_transfer" => b.sepa_credit_transfer = FromValueOpt::from_value(v),
438                    "sepa_debit" => b.sepa_debit = FromValueOpt::from_value(v),
439                    "sofort" => b.sofort = FromValueOpt::from_value(v),
440                    "source_order" => b.source_order = FromValueOpt::from_value(v),
441                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
442                    "status" => b.status = FromValueOpt::from_value(v),
443                    "three_d_secure" => b.three_d_secure = FromValueOpt::from_value(v),
444                    "type" => b.type_ = FromValueOpt::from_value(v),
445                    "usage" => b.usage = FromValueOpt::from_value(v),
446                    "wechat" => b.wechat = FromValueOpt::from_value(v),
447                    _ => {}
448                }
449            }
450            b.take_out()
451        }
452    }
453};
454#[cfg(feature = "serialize")]
455impl serde::Serialize for Source {
456    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
457        use serde::ser::SerializeStruct;
458        let mut s = s.serialize_struct("Source", 39)?;
459        s.serialize_field("ach_credit_transfer", &self.ach_credit_transfer)?;
460        s.serialize_field("ach_debit", &self.ach_debit)?;
461        s.serialize_field("acss_debit", &self.acss_debit)?;
462        s.serialize_field("alipay", &self.alipay)?;
463        s.serialize_field("allow_redisplay", &self.allow_redisplay)?;
464        s.serialize_field("amount", &self.amount)?;
465        s.serialize_field("au_becs_debit", &self.au_becs_debit)?;
466        s.serialize_field("bancontact", &self.bancontact)?;
467        s.serialize_field("card", &self.card)?;
468        s.serialize_field("card_present", &self.card_present)?;
469        s.serialize_field("client_secret", &self.client_secret)?;
470        s.serialize_field("code_verification", &self.code_verification)?;
471        s.serialize_field("created", &self.created)?;
472        s.serialize_field("currency", &self.currency)?;
473        s.serialize_field("customer", &self.customer)?;
474        s.serialize_field("eps", &self.eps)?;
475        s.serialize_field("flow", &self.flow)?;
476        s.serialize_field("giropay", &self.giropay)?;
477        s.serialize_field("id", &self.id)?;
478        s.serialize_field("ideal", &self.ideal)?;
479        s.serialize_field("klarna", &self.klarna)?;
480        s.serialize_field("livemode", &self.livemode)?;
481        s.serialize_field("metadata", &self.metadata)?;
482        s.serialize_field("multibanco", &self.multibanco)?;
483        s.serialize_field("owner", &self.owner)?;
484        s.serialize_field("p24", &self.p24)?;
485        s.serialize_field("receiver", &self.receiver)?;
486        s.serialize_field("redirect", &self.redirect)?;
487        s.serialize_field("sepa_credit_transfer", &self.sepa_credit_transfer)?;
488        s.serialize_field("sepa_debit", &self.sepa_debit)?;
489        s.serialize_field("sofort", &self.sofort)?;
490        s.serialize_field("source_order", &self.source_order)?;
491        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
492        s.serialize_field("status", &self.status)?;
493        s.serialize_field("three_d_secure", &self.three_d_secure)?;
494        s.serialize_field("type", &self.type_)?;
495        s.serialize_field("usage", &self.usage)?;
496        s.serialize_field("wechat", &self.wechat)?;
497
498        s.serialize_field("object", "source")?;
499        s.end()
500    }
501}
502/// This field indicates whether this payment method can be shown again to its customer in a checkout flow.
503/// Stripe products such as Checkout and Elements use this field to determine whether a payment method can be shown as a saved payment method in a checkout flow.
504/// The field defaults to “unspecified”.
505#[derive(Clone, Eq, PartialEq)]
506#[non_exhaustive]
507pub enum SourceAllowRedisplay {
508    Always,
509    Limited,
510    Unspecified,
511    /// An unrecognized value from Stripe. Should not be used as a request parameter.
512    Unknown(String),
513}
514impl SourceAllowRedisplay {
515    pub fn as_str(&self) -> &str {
516        use SourceAllowRedisplay::*;
517        match self {
518            Always => "always",
519            Limited => "limited",
520            Unspecified => "unspecified",
521            Unknown(v) => v,
522        }
523    }
524}
525
526impl std::str::FromStr for SourceAllowRedisplay {
527    type Err = std::convert::Infallible;
528    fn from_str(s: &str) -> Result<Self, Self::Err> {
529        use SourceAllowRedisplay::*;
530        match s {
531            "always" => Ok(Always),
532            "limited" => Ok(Limited),
533            "unspecified" => Ok(Unspecified),
534            v => {
535                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SourceAllowRedisplay");
536                Ok(Unknown(v.to_owned()))
537            }
538        }
539    }
540}
541impl std::fmt::Display for SourceAllowRedisplay {
542    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
543        f.write_str(self.as_str())
544    }
545}
546
547#[cfg(not(feature = "redact-generated-debug"))]
548impl std::fmt::Debug for SourceAllowRedisplay {
549    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
550        f.write_str(self.as_str())
551    }
552}
553#[cfg(feature = "redact-generated-debug")]
554impl std::fmt::Debug for SourceAllowRedisplay {
555    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
556        f.debug_struct(stringify!(SourceAllowRedisplay)).finish_non_exhaustive()
557    }
558}
559#[cfg(feature = "serialize")]
560impl serde::Serialize for SourceAllowRedisplay {
561    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
562    where
563        S: serde::Serializer,
564    {
565        serializer.serialize_str(self.as_str())
566    }
567}
568impl miniserde::Deserialize for SourceAllowRedisplay {
569    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
570        crate::Place::new(out)
571    }
572}
573
574impl miniserde::de::Visitor for crate::Place<SourceAllowRedisplay> {
575    fn string(&mut self, s: &str) -> miniserde::Result<()> {
576        use std::str::FromStr;
577        self.out = Some(SourceAllowRedisplay::from_str(s).expect("infallible"));
578        Ok(())
579    }
580}
581
582stripe_types::impl_from_val_with_from_str!(SourceAllowRedisplay);
583#[cfg(feature = "deserialize")]
584impl<'de> serde::Deserialize<'de> for SourceAllowRedisplay {
585    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
586        use std::str::FromStr;
587        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
588        Ok(Self::from_str(&s).expect("infallible"))
589    }
590}
591/// The `type` of the source.
592/// The `type` is a payment method, one of `ach_credit_transfer`, `ach_debit`, `alipay`, `bancontact`, `card`, `card_present`, `eps`, `giropay`, `ideal`, `multibanco`, `klarna`, `p24`, `sepa_debit`, `sofort`, `three_d_secure`, or `wechat`.
593/// An additional hash is included on the source with a name matching this value.
594/// It contains additional information specific to the [payment method](https://docs.stripe.com/sources) used.
595#[derive(Clone, Eq, PartialEq)]
596#[non_exhaustive]
597pub enum SourceType {
598    AchCreditTransfer,
599    AchDebit,
600    AcssDebit,
601    Alipay,
602    AuBecsDebit,
603    Bancontact,
604    Card,
605    CardPresent,
606    Eps,
607    Giropay,
608    Ideal,
609    Klarna,
610    Multibanco,
611    P24,
612    SepaCreditTransfer,
613    SepaDebit,
614    Sofort,
615    ThreeDSecure,
616    Wechat,
617    /// An unrecognized value from Stripe. Should not be used as a request parameter.
618    Unknown(String),
619}
620impl SourceType {
621    pub fn as_str(&self) -> &str {
622        use SourceType::*;
623        match self {
624            AchCreditTransfer => "ach_credit_transfer",
625            AchDebit => "ach_debit",
626            AcssDebit => "acss_debit",
627            Alipay => "alipay",
628            AuBecsDebit => "au_becs_debit",
629            Bancontact => "bancontact",
630            Card => "card",
631            CardPresent => "card_present",
632            Eps => "eps",
633            Giropay => "giropay",
634            Ideal => "ideal",
635            Klarna => "klarna",
636            Multibanco => "multibanco",
637            P24 => "p24",
638            SepaCreditTransfer => "sepa_credit_transfer",
639            SepaDebit => "sepa_debit",
640            Sofort => "sofort",
641            ThreeDSecure => "three_d_secure",
642            Wechat => "wechat",
643            Unknown(v) => v,
644        }
645    }
646}
647
648impl std::str::FromStr for SourceType {
649    type Err = std::convert::Infallible;
650    fn from_str(s: &str) -> Result<Self, Self::Err> {
651        use SourceType::*;
652        match s {
653            "ach_credit_transfer" => Ok(AchCreditTransfer),
654            "ach_debit" => Ok(AchDebit),
655            "acss_debit" => Ok(AcssDebit),
656            "alipay" => Ok(Alipay),
657            "au_becs_debit" => Ok(AuBecsDebit),
658            "bancontact" => Ok(Bancontact),
659            "card" => Ok(Card),
660            "card_present" => Ok(CardPresent),
661            "eps" => Ok(Eps),
662            "giropay" => Ok(Giropay),
663            "ideal" => Ok(Ideal),
664            "klarna" => Ok(Klarna),
665            "multibanco" => Ok(Multibanco),
666            "p24" => Ok(P24),
667            "sepa_credit_transfer" => Ok(SepaCreditTransfer),
668            "sepa_debit" => Ok(SepaDebit),
669            "sofort" => Ok(Sofort),
670            "three_d_secure" => Ok(ThreeDSecure),
671            "wechat" => Ok(Wechat),
672            v => {
673                tracing::warn!("Unknown value '{}' for enum '{}'", v, "SourceType");
674                Ok(Unknown(v.to_owned()))
675            }
676        }
677    }
678}
679impl std::fmt::Display for SourceType {
680    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
681        f.write_str(self.as_str())
682    }
683}
684
685#[cfg(not(feature = "redact-generated-debug"))]
686impl std::fmt::Debug for SourceType {
687    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
688        f.write_str(self.as_str())
689    }
690}
691#[cfg(feature = "redact-generated-debug")]
692impl std::fmt::Debug for SourceType {
693    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
694        f.debug_struct(stringify!(SourceType)).finish_non_exhaustive()
695    }
696}
697#[cfg(feature = "serialize")]
698impl serde::Serialize for SourceType {
699    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
700    where
701        S: serde::Serializer,
702    {
703        serializer.serialize_str(self.as_str())
704    }
705}
706impl miniserde::Deserialize for SourceType {
707    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
708        crate::Place::new(out)
709    }
710}
711
712impl miniserde::de::Visitor for crate::Place<SourceType> {
713    fn string(&mut self, s: &str) -> miniserde::Result<()> {
714        use std::str::FromStr;
715        self.out = Some(SourceType::from_str(s).expect("infallible"));
716        Ok(())
717    }
718}
719
720stripe_types::impl_from_val_with_from_str!(SourceType);
721#[cfg(feature = "deserialize")]
722impl<'de> serde::Deserialize<'de> for SourceType {
723    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
724        use std::str::FromStr;
725        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
726        Ok(Self::from_str(&s).expect("infallible"))
727    }
728}
729impl stripe_types::Object for Source {
730    type Id = stripe_shared::SourceId;
731    fn id(&self) -> &Self::Id {
732        &self.id
733    }
734
735    fn into_id(self) -> Self::Id {
736        self.id
737    }
738}
739stripe_types::def_id!(SourceId);