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