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::{make_place, Deserialize, Result};
141    use stripe_types::miniserde_helpers::FromValueOpt;
142    use stripe_types::{MapBuilder, ObjectDeser};
143
144    make_place!(Place);
145
146    impl Deserialize for 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
206                _ => <dyn Visitor>::ignore(),
207            })
208        }
209
210        fn deser_default() -> Self {
211            Self {
212                ach_credit_transfer: Deserialize::default(),
213                ach_debit: Deserialize::default(),
214                acss_debit: Deserialize::default(),
215                alipay: Deserialize::default(),
216                allow_redisplay: Deserialize::default(),
217                amount: Deserialize::default(),
218                au_becs_debit: Deserialize::default(),
219                bancontact: Deserialize::default(),
220                card: Deserialize::default(),
221                card_present: Deserialize::default(),
222                client_secret: Deserialize::default(),
223                code_verification: Deserialize::default(),
224                created: Deserialize::default(),
225                currency: Deserialize::default(),
226                customer: Deserialize::default(),
227                eps: Deserialize::default(),
228                flow: Deserialize::default(),
229                giropay: Deserialize::default(),
230                id: Deserialize::default(),
231                ideal: Deserialize::default(),
232                klarna: Deserialize::default(),
233                livemode: Deserialize::default(),
234                metadata: Deserialize::default(),
235                multibanco: Deserialize::default(),
236                owner: Deserialize::default(),
237                p24: Deserialize::default(),
238                receiver: Deserialize::default(),
239                redirect: Deserialize::default(),
240                sepa_credit_transfer: Deserialize::default(),
241                sepa_debit: Deserialize::default(),
242                sofort: Deserialize::default(),
243                source_order: Deserialize::default(),
244                statement_descriptor: Deserialize::default(),
245                status: Deserialize::default(),
246                three_d_secure: Deserialize::default(),
247                type_: Deserialize::default(),
248                usage: Deserialize::default(),
249                wechat: Deserialize::default(),
250            }
251        }
252
253        fn take_out(&mut self) -> Option<Self::Out> {
254            let (
255                Some(ach_credit_transfer),
256                Some(ach_debit),
257                Some(acss_debit),
258                Some(alipay),
259                Some(allow_redisplay),
260                Some(amount),
261                Some(au_becs_debit),
262                Some(bancontact),
263                Some(card),
264                Some(card_present),
265                Some(client_secret),
266                Some(code_verification),
267                Some(created),
268                Some(currency),
269                Some(customer),
270                Some(eps),
271                Some(flow),
272                Some(giropay),
273                Some(id),
274                Some(ideal),
275                Some(klarna),
276                Some(livemode),
277                Some(metadata),
278                Some(multibanco),
279                Some(owner),
280                Some(p24),
281                Some(receiver),
282                Some(redirect),
283                Some(sepa_credit_transfer),
284                Some(sepa_debit),
285                Some(sofort),
286                Some(source_order),
287                Some(statement_descriptor),
288                Some(status),
289                Some(three_d_secure),
290                Some(type_),
291                Some(usage),
292                Some(wechat),
293            ) = (
294                self.ach_credit_transfer.take(),
295                self.ach_debit.take(),
296                self.acss_debit.take(),
297                self.alipay.take(),
298                self.allow_redisplay,
299                self.amount,
300                self.au_becs_debit.take(),
301                self.bancontact.take(),
302                self.card.take(),
303                self.card_present.take(),
304                self.client_secret.take(),
305                self.code_verification.take(),
306                self.created,
307                self.currency,
308                self.customer.take(),
309                self.eps.take(),
310                self.flow.take(),
311                self.giropay.take(),
312                self.id.take(),
313                self.ideal.take(),
314                self.klarna.take(),
315                self.livemode,
316                self.metadata.take(),
317                self.multibanco.take(),
318                self.owner.take(),
319                self.p24.take(),
320                self.receiver.take(),
321                self.redirect.take(),
322                self.sepa_credit_transfer.take(),
323                self.sepa_debit.take(),
324                self.sofort.take(),
325                self.source_order.take(),
326                self.statement_descriptor.take(),
327                self.status.take(),
328                self.three_d_secure.take(),
329                self.type_.take(),
330                self.usage.take(),
331                self.wechat.take(),
332            )
333            else {
334                return None;
335            };
336            Some(Self::Out {
337                ach_credit_transfer,
338                ach_debit,
339                acss_debit,
340                alipay,
341                allow_redisplay,
342                amount,
343                au_becs_debit,
344                bancontact,
345                card,
346                card_present,
347                client_secret,
348                code_verification,
349                created,
350                currency,
351                customer,
352                eps,
353                flow,
354                giropay,
355                id,
356                ideal,
357                klarna,
358                livemode,
359                metadata,
360                multibanco,
361                owner,
362                p24,
363                receiver,
364                redirect,
365                sepa_credit_transfer,
366                sepa_debit,
367                sofort,
368                source_order,
369                statement_descriptor,
370                status,
371                three_d_secure,
372                type_,
373                usage,
374                wechat,
375            })
376        }
377    }
378
379    impl<'a> Map for Builder<'a> {
380        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
381            self.builder.key(k)
382        }
383
384        fn finish(&mut self) -> Result<()> {
385            *self.out = self.builder.take_out();
386            Ok(())
387        }
388    }
389
390    impl ObjectDeser for Source {
391        type Builder = SourceBuilder;
392    }
393
394    impl FromValueOpt for Source {
395        fn from_value(v: Value) -> Option<Self> {
396            let Value::Object(obj) = v else {
397                return None;
398            };
399            let mut b = SourceBuilder::deser_default();
400            for (k, v) in obj {
401                match k.as_str() {
402                    "ach_credit_transfer" => b.ach_credit_transfer = FromValueOpt::from_value(v),
403                    "ach_debit" => b.ach_debit = FromValueOpt::from_value(v),
404                    "acss_debit" => b.acss_debit = FromValueOpt::from_value(v),
405                    "alipay" => b.alipay = FromValueOpt::from_value(v),
406                    "allow_redisplay" => b.allow_redisplay = FromValueOpt::from_value(v),
407                    "amount" => b.amount = FromValueOpt::from_value(v),
408                    "au_becs_debit" => b.au_becs_debit = FromValueOpt::from_value(v),
409                    "bancontact" => b.bancontact = FromValueOpt::from_value(v),
410                    "card" => b.card = FromValueOpt::from_value(v),
411                    "card_present" => b.card_present = FromValueOpt::from_value(v),
412                    "client_secret" => b.client_secret = FromValueOpt::from_value(v),
413                    "code_verification" => b.code_verification = FromValueOpt::from_value(v),
414                    "created" => b.created = FromValueOpt::from_value(v),
415                    "currency" => b.currency = FromValueOpt::from_value(v),
416                    "customer" => b.customer = FromValueOpt::from_value(v),
417                    "eps" => b.eps = FromValueOpt::from_value(v),
418                    "flow" => b.flow = FromValueOpt::from_value(v),
419                    "giropay" => b.giropay = FromValueOpt::from_value(v),
420                    "id" => b.id = FromValueOpt::from_value(v),
421                    "ideal" => b.ideal = FromValueOpt::from_value(v),
422                    "klarna" => b.klarna = FromValueOpt::from_value(v),
423                    "livemode" => b.livemode = FromValueOpt::from_value(v),
424                    "metadata" => b.metadata = FromValueOpt::from_value(v),
425                    "multibanco" => b.multibanco = FromValueOpt::from_value(v),
426                    "owner" => b.owner = FromValueOpt::from_value(v),
427                    "p24" => b.p24 = FromValueOpt::from_value(v),
428                    "receiver" => b.receiver = FromValueOpt::from_value(v),
429                    "redirect" => b.redirect = FromValueOpt::from_value(v),
430                    "sepa_credit_transfer" => b.sepa_credit_transfer = FromValueOpt::from_value(v),
431                    "sepa_debit" => b.sepa_debit = FromValueOpt::from_value(v),
432                    "sofort" => b.sofort = FromValueOpt::from_value(v),
433                    "source_order" => b.source_order = FromValueOpt::from_value(v),
434                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
435                    "status" => b.status = FromValueOpt::from_value(v),
436                    "three_d_secure" => b.three_d_secure = FromValueOpt::from_value(v),
437                    "type" => b.type_ = FromValueOpt::from_value(v),
438                    "usage" => b.usage = FromValueOpt::from_value(v),
439                    "wechat" => b.wechat = FromValueOpt::from_value(v),
440
441                    _ => {}
442                }
443            }
444            b.take_out()
445        }
446    }
447};
448#[cfg(feature = "serialize")]
449impl serde::Serialize for Source {
450    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
451        use serde::ser::SerializeStruct;
452        let mut s = s.serialize_struct("Source", 39)?;
453        s.serialize_field("ach_credit_transfer", &self.ach_credit_transfer)?;
454        s.serialize_field("ach_debit", &self.ach_debit)?;
455        s.serialize_field("acss_debit", &self.acss_debit)?;
456        s.serialize_field("alipay", &self.alipay)?;
457        s.serialize_field("allow_redisplay", &self.allow_redisplay)?;
458        s.serialize_field("amount", &self.amount)?;
459        s.serialize_field("au_becs_debit", &self.au_becs_debit)?;
460        s.serialize_field("bancontact", &self.bancontact)?;
461        s.serialize_field("card", &self.card)?;
462        s.serialize_field("card_present", &self.card_present)?;
463        s.serialize_field("client_secret", &self.client_secret)?;
464        s.serialize_field("code_verification", &self.code_verification)?;
465        s.serialize_field("created", &self.created)?;
466        s.serialize_field("currency", &self.currency)?;
467        s.serialize_field("customer", &self.customer)?;
468        s.serialize_field("eps", &self.eps)?;
469        s.serialize_field("flow", &self.flow)?;
470        s.serialize_field("giropay", &self.giropay)?;
471        s.serialize_field("id", &self.id)?;
472        s.serialize_field("ideal", &self.ideal)?;
473        s.serialize_field("klarna", &self.klarna)?;
474        s.serialize_field("livemode", &self.livemode)?;
475        s.serialize_field("metadata", &self.metadata)?;
476        s.serialize_field("multibanco", &self.multibanco)?;
477        s.serialize_field("owner", &self.owner)?;
478        s.serialize_field("p24", &self.p24)?;
479        s.serialize_field("receiver", &self.receiver)?;
480        s.serialize_field("redirect", &self.redirect)?;
481        s.serialize_field("sepa_credit_transfer", &self.sepa_credit_transfer)?;
482        s.serialize_field("sepa_debit", &self.sepa_debit)?;
483        s.serialize_field("sofort", &self.sofort)?;
484        s.serialize_field("source_order", &self.source_order)?;
485        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
486        s.serialize_field("status", &self.status)?;
487        s.serialize_field("three_d_secure", &self.three_d_secure)?;
488        s.serialize_field("type", &self.type_)?;
489        s.serialize_field("usage", &self.usage)?;
490        s.serialize_field("wechat", &self.wechat)?;
491
492        s.serialize_field("object", "source")?;
493        s.end()
494    }
495}
496/// This field indicates whether this payment method can be shown again to its customer in a checkout flow.
497/// 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.
498/// The field defaults to “unspecified”.
499#[derive(Copy, Clone, Eq, PartialEq)]
500pub enum SourceAllowRedisplay {
501    Always,
502    Limited,
503    Unspecified,
504}
505impl SourceAllowRedisplay {
506    pub fn as_str(self) -> &'static str {
507        use SourceAllowRedisplay::*;
508        match self {
509            Always => "always",
510            Limited => "limited",
511            Unspecified => "unspecified",
512        }
513    }
514}
515
516impl std::str::FromStr for SourceAllowRedisplay {
517    type Err = stripe_types::StripeParseError;
518    fn from_str(s: &str) -> Result<Self, Self::Err> {
519        use SourceAllowRedisplay::*;
520        match s {
521            "always" => Ok(Always),
522            "limited" => Ok(Limited),
523            "unspecified" => Ok(Unspecified),
524            _ => Err(stripe_types::StripeParseError),
525        }
526    }
527}
528impl std::fmt::Display for SourceAllowRedisplay {
529    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
530        f.write_str(self.as_str())
531    }
532}
533
534impl std::fmt::Debug for SourceAllowRedisplay {
535    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
536        f.write_str(self.as_str())
537    }
538}
539#[cfg(feature = "serialize")]
540impl serde::Serialize for SourceAllowRedisplay {
541    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
542    where
543        S: serde::Serializer,
544    {
545        serializer.serialize_str(self.as_str())
546    }
547}
548impl miniserde::Deserialize for SourceAllowRedisplay {
549    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
550        crate::Place::new(out)
551    }
552}
553
554impl miniserde::de::Visitor for crate::Place<SourceAllowRedisplay> {
555    fn string(&mut self, s: &str) -> miniserde::Result<()> {
556        use std::str::FromStr;
557        self.out = Some(SourceAllowRedisplay::from_str(s).map_err(|_| miniserde::Error)?);
558        Ok(())
559    }
560}
561
562stripe_types::impl_from_val_with_from_str!(SourceAllowRedisplay);
563#[cfg(feature = "deserialize")]
564impl<'de> serde::Deserialize<'de> for SourceAllowRedisplay {
565    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
566        use std::str::FromStr;
567        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
568        Self::from_str(&s)
569            .map_err(|_| serde::de::Error::custom("Unknown value for SourceAllowRedisplay"))
570    }
571}
572/// The `type` of the source.
573/// 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`.
574/// An additional hash is included on the source with a name matching this value.
575/// It contains additional information specific to the [payment method](https://stripe.com/docs/sources) used.
576#[derive(Clone, Eq, PartialEq)]
577#[non_exhaustive]
578pub enum SourceType {
579    AchCreditTransfer,
580    AchDebit,
581    AcssDebit,
582    Alipay,
583    AuBecsDebit,
584    Bancontact,
585    Card,
586    CardPresent,
587    Eps,
588    Giropay,
589    Ideal,
590    Klarna,
591    Multibanco,
592    P24,
593    SepaCreditTransfer,
594    SepaDebit,
595    Sofort,
596    ThreeDSecure,
597    Wechat,
598    /// An unrecognized value from Stripe. Should not be used as a request parameter.
599    Unknown(String),
600}
601impl SourceType {
602    pub fn as_str(&self) -> &str {
603        use SourceType::*;
604        match self {
605            AchCreditTransfer => "ach_credit_transfer",
606            AchDebit => "ach_debit",
607            AcssDebit => "acss_debit",
608            Alipay => "alipay",
609            AuBecsDebit => "au_becs_debit",
610            Bancontact => "bancontact",
611            Card => "card",
612            CardPresent => "card_present",
613            Eps => "eps",
614            Giropay => "giropay",
615            Ideal => "ideal",
616            Klarna => "klarna",
617            Multibanco => "multibanco",
618            P24 => "p24",
619            SepaCreditTransfer => "sepa_credit_transfer",
620            SepaDebit => "sepa_debit",
621            Sofort => "sofort",
622            ThreeDSecure => "three_d_secure",
623            Wechat => "wechat",
624            Unknown(v) => v,
625        }
626    }
627}
628
629impl std::str::FromStr for SourceType {
630    type Err = std::convert::Infallible;
631    fn from_str(s: &str) -> Result<Self, Self::Err> {
632        use SourceType::*;
633        match s {
634            "ach_credit_transfer" => Ok(AchCreditTransfer),
635            "ach_debit" => Ok(AchDebit),
636            "acss_debit" => Ok(AcssDebit),
637            "alipay" => Ok(Alipay),
638            "au_becs_debit" => Ok(AuBecsDebit),
639            "bancontact" => Ok(Bancontact),
640            "card" => Ok(Card),
641            "card_present" => Ok(CardPresent),
642            "eps" => Ok(Eps),
643            "giropay" => Ok(Giropay),
644            "ideal" => Ok(Ideal),
645            "klarna" => Ok(Klarna),
646            "multibanco" => Ok(Multibanco),
647            "p24" => Ok(P24),
648            "sepa_credit_transfer" => Ok(SepaCreditTransfer),
649            "sepa_debit" => Ok(SepaDebit),
650            "sofort" => Ok(Sofort),
651            "three_d_secure" => Ok(ThreeDSecure),
652            "wechat" => Ok(Wechat),
653            v => Ok(Unknown(v.to_owned())),
654        }
655    }
656}
657impl std::fmt::Display for SourceType {
658    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
659        f.write_str(self.as_str())
660    }
661}
662
663impl std::fmt::Debug for SourceType {
664    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
665        f.write_str(self.as_str())
666    }
667}
668#[cfg(feature = "serialize")]
669impl serde::Serialize for SourceType {
670    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
671    where
672        S: serde::Serializer,
673    {
674        serializer.serialize_str(self.as_str())
675    }
676}
677impl miniserde::Deserialize for SourceType {
678    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
679        crate::Place::new(out)
680    }
681}
682
683impl miniserde::de::Visitor for crate::Place<SourceType> {
684    fn string(&mut self, s: &str) -> miniserde::Result<()> {
685        use std::str::FromStr;
686        self.out = Some(SourceType::from_str(s).unwrap());
687        Ok(())
688    }
689}
690
691stripe_types::impl_from_val_with_from_str!(SourceType);
692#[cfg(feature = "deserialize")]
693impl<'de> serde::Deserialize<'de> for SourceType {
694    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
695        use std::str::FromStr;
696        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
697        Ok(Self::from_str(&s).unwrap())
698    }
699}
700impl stripe_types::Object for Source {
701    type Id = stripe_shared::SourceId;
702    fn id(&self) -> &Self::Id {
703        &self.id
704    }
705
706    fn into_id(self) -> Self::Id {
707        self.id
708    }
709}
710stripe_types::def_id!(SourceId);