stripe_shared/
payment_method_details_passthrough_card.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodDetailsPassthroughCard {
5    /// Card brand.
6    /// Can be `amex`, `cartes_bancaires`, `diners`, `discover`, `eftpos_au`, `jcb`, `link`, `mastercard`, `unionpay`, `visa` or `unknown`.
7    pub brand: Option<String>,
8    /// Two-letter ISO code representing the country of the card.
9    /// You could use this attribute to get a sense of the international breakdown of cards you've collected.
10    pub country: Option<String>,
11    /// Two-digit number representing the card's expiration month.
12    pub exp_month: Option<i64>,
13    /// Four-digit number representing the card's expiration year.
14    pub exp_year: Option<i64>,
15    /// Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
16    pub funding: Option<String>,
17    /// The last four digits of the card.
18    pub last4: Option<String>,
19}
20#[doc(hidden)]
21pub struct PaymentMethodDetailsPassthroughCardBuilder {
22    brand: Option<Option<String>>,
23    country: Option<Option<String>>,
24    exp_month: Option<Option<i64>>,
25    exp_year: Option<Option<i64>>,
26    funding: Option<Option<String>>,
27    last4: Option<Option<String>>,
28}
29
30#[allow(
31    unused_variables,
32    irrefutable_let_patterns,
33    clippy::let_unit_value,
34    clippy::match_single_binding,
35    clippy::single_match
36)]
37const _: () = {
38    use miniserde::de::{Map, Visitor};
39    use miniserde::json::Value;
40    use miniserde::{Deserialize, Result, make_place};
41    use stripe_types::miniserde_helpers::FromValueOpt;
42    use stripe_types::{MapBuilder, ObjectDeser};
43
44    make_place!(Place);
45
46    impl Deserialize for PaymentMethodDetailsPassthroughCard {
47        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
48            Place::new(out)
49        }
50    }
51
52    struct Builder<'a> {
53        out: &'a mut Option<PaymentMethodDetailsPassthroughCard>,
54        builder: PaymentMethodDetailsPassthroughCardBuilder,
55    }
56
57    impl Visitor for Place<PaymentMethodDetailsPassthroughCard> {
58        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59            Ok(Box::new(Builder {
60                out: &mut self.out,
61                builder: PaymentMethodDetailsPassthroughCardBuilder::deser_default(),
62            }))
63        }
64    }
65
66    impl MapBuilder for PaymentMethodDetailsPassthroughCardBuilder {
67        type Out = PaymentMethodDetailsPassthroughCard;
68        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
69            Ok(match k {
70                "brand" => Deserialize::begin(&mut self.brand),
71                "country" => Deserialize::begin(&mut self.country),
72                "exp_month" => Deserialize::begin(&mut self.exp_month),
73                "exp_year" => Deserialize::begin(&mut self.exp_year),
74                "funding" => Deserialize::begin(&mut self.funding),
75                "last4" => Deserialize::begin(&mut self.last4),
76                _ => <dyn Visitor>::ignore(),
77            })
78        }
79
80        fn deser_default() -> Self {
81            Self {
82                brand: Deserialize::default(),
83                country: Deserialize::default(),
84                exp_month: Deserialize::default(),
85                exp_year: Deserialize::default(),
86                funding: Deserialize::default(),
87                last4: Deserialize::default(),
88            }
89        }
90
91        fn take_out(&mut self) -> Option<Self::Out> {
92            let (
93                Some(brand),
94                Some(country),
95                Some(exp_month),
96                Some(exp_year),
97                Some(funding),
98                Some(last4),
99            ) = (
100                self.brand.take(),
101                self.country.take(),
102                self.exp_month,
103                self.exp_year,
104                self.funding.take(),
105                self.last4.take(),
106            )
107            else {
108                return None;
109            };
110            Some(Self::Out { brand, country, exp_month, exp_year, funding, last4 })
111        }
112    }
113
114    impl Map for Builder<'_> {
115        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
116            self.builder.key(k)
117        }
118
119        fn finish(&mut self) -> Result<()> {
120            *self.out = self.builder.take_out();
121            Ok(())
122        }
123    }
124
125    impl ObjectDeser for PaymentMethodDetailsPassthroughCard {
126        type Builder = PaymentMethodDetailsPassthroughCardBuilder;
127    }
128
129    impl FromValueOpt for PaymentMethodDetailsPassthroughCard {
130        fn from_value(v: Value) -> Option<Self> {
131            let Value::Object(obj) = v else {
132                return None;
133            };
134            let mut b = PaymentMethodDetailsPassthroughCardBuilder::deser_default();
135            for (k, v) in obj {
136                match k.as_str() {
137                    "brand" => b.brand = FromValueOpt::from_value(v),
138                    "country" => b.country = FromValueOpt::from_value(v),
139                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
140                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
141                    "funding" => b.funding = FromValueOpt::from_value(v),
142                    "last4" => b.last4 = FromValueOpt::from_value(v),
143                    _ => {}
144                }
145            }
146            b.take_out()
147        }
148    }
149};