stripe_shared/
payment_method_card_present.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodCardPresent {
5    /// Card brand.
6    /// Can be `amex`, `diners`, `discover`, `eftpos_au`, `jcb`, `link`, `mastercard`, `unionpay`, `visa`, or `unknown`.
7    pub brand: Option<String>,
8    /// The [product code](https://stripe.com/docs/card-product-codes) that identifies the specific program or product associated with a card.
9    pub brand_product: Option<String>,
10    /// The cardholder name as read from the card, in [ISO 7813](https://en.wikipedia.org/wiki/ISO/IEC_7813) format.
11    /// May include alphanumeric characters, special characters and first/last name separator (`/`).
12    /// In some cases, the cardholder name may not be available depending on how the issuer has configured the card.
13    /// Cardholder name is typically not available on swipe or contactless payments, such as those made with Apple Pay and Google Pay.
14    pub cardholder_name: Option<String>,
15    /// Two-letter ISO code representing the country of the card.
16    /// You could use this attribute to get a sense of the international breakdown of cards you've collected.
17    pub country: Option<String>,
18    /// A high-level description of the type of cards issued in this range.
19    /// (For internal use only and not typically available in standard API requests.).
20    pub description: Option<String>,
21    /// Two-digit number representing the card's expiration month.
22    pub exp_month: i64,
23    /// Four-digit number representing the card's expiration year.
24    pub exp_year: i64,
25    /// Uniquely identifies this particular card number.
26    /// You can use this attribute to check whether two customers who’ve signed up with you are using the same card number, for example.
27    /// For payment methods that tokenize card information (Apple Pay, Google Pay), the tokenized number might be provided instead of the underlying card number.
28    ///
29    /// *As of May 1, 2021, card fingerprint in India for Connect changed to allow two fingerprints for the same card---one for India and one for the rest of the world.*.
30    pub fingerprint: Option<String>,
31    /// Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
32    pub funding: Option<String>,
33    /// Issuer identification number of the card.
34    /// (For internal use only and not typically available in standard API requests.).
35    pub iin: Option<String>,
36    /// The name of the card's issuing bank.
37    /// (For internal use only and not typically available in standard API requests.).
38    pub issuer: Option<String>,
39    /// The last four digits of the card.
40    pub last4: Option<String>,
41    /// Contains information about card networks that can be used to process the payment.
42    pub networks: Option<stripe_shared::PaymentMethodCardPresentNetworks>,
43    /// Details about payment methods collected offline.
44    pub offline: Option<stripe_shared::PaymentMethodDetailsCardPresentOffline>,
45    /// EMV tag 5F2D. Preferred languages specified by the integrated circuit chip.
46    pub preferred_locales: Option<Vec<String>>,
47    /// How card details were read in this transaction.
48    pub read_method: Option<PaymentMethodCardPresentReadMethod>,
49    pub wallet: Option<stripe_shared::PaymentFlowsPrivatePaymentMethodsCardPresentCommonWallet>,
50}
51#[doc(hidden)]
52pub struct PaymentMethodCardPresentBuilder {
53    brand: Option<Option<String>>,
54    brand_product: Option<Option<String>>,
55    cardholder_name: Option<Option<String>>,
56    country: Option<Option<String>>,
57    description: Option<Option<String>>,
58    exp_month: Option<i64>,
59    exp_year: Option<i64>,
60    fingerprint: Option<Option<String>>,
61    funding: Option<Option<String>>,
62    iin: Option<Option<String>>,
63    issuer: Option<Option<String>>,
64    last4: Option<Option<String>>,
65    networks: Option<Option<stripe_shared::PaymentMethodCardPresentNetworks>>,
66    offline: Option<Option<stripe_shared::PaymentMethodDetailsCardPresentOffline>>,
67    preferred_locales: Option<Option<Vec<String>>>,
68    read_method: Option<Option<PaymentMethodCardPresentReadMethod>>,
69    wallet: Option<Option<stripe_shared::PaymentFlowsPrivatePaymentMethodsCardPresentCommonWallet>>,
70}
71
72#[allow(
73    unused_variables,
74    irrefutable_let_patterns,
75    clippy::let_unit_value,
76    clippy::match_single_binding,
77    clippy::single_match
78)]
79const _: () = {
80    use miniserde::de::{Map, Visitor};
81    use miniserde::json::Value;
82    use miniserde::{make_place, Deserialize, Result};
83    use stripe_types::miniserde_helpers::FromValueOpt;
84    use stripe_types::{MapBuilder, ObjectDeser};
85
86    make_place!(Place);
87
88    impl Deserialize for PaymentMethodCardPresent {
89        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
90            Place::new(out)
91        }
92    }
93
94    struct Builder<'a> {
95        out: &'a mut Option<PaymentMethodCardPresent>,
96        builder: PaymentMethodCardPresentBuilder,
97    }
98
99    impl Visitor for Place<PaymentMethodCardPresent> {
100        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
101            Ok(Box::new(Builder {
102                out: &mut self.out,
103                builder: PaymentMethodCardPresentBuilder::deser_default(),
104            }))
105        }
106    }
107
108    impl MapBuilder for PaymentMethodCardPresentBuilder {
109        type Out = PaymentMethodCardPresent;
110        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
111            Ok(match k {
112                "brand" => Deserialize::begin(&mut self.brand),
113                "brand_product" => Deserialize::begin(&mut self.brand_product),
114                "cardholder_name" => Deserialize::begin(&mut self.cardholder_name),
115                "country" => Deserialize::begin(&mut self.country),
116                "description" => Deserialize::begin(&mut self.description),
117                "exp_month" => Deserialize::begin(&mut self.exp_month),
118                "exp_year" => Deserialize::begin(&mut self.exp_year),
119                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
120                "funding" => Deserialize::begin(&mut self.funding),
121                "iin" => Deserialize::begin(&mut self.iin),
122                "issuer" => Deserialize::begin(&mut self.issuer),
123                "last4" => Deserialize::begin(&mut self.last4),
124                "networks" => Deserialize::begin(&mut self.networks),
125                "offline" => Deserialize::begin(&mut self.offline),
126                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
127                "read_method" => Deserialize::begin(&mut self.read_method),
128                "wallet" => Deserialize::begin(&mut self.wallet),
129
130                _ => <dyn Visitor>::ignore(),
131            })
132        }
133
134        fn deser_default() -> Self {
135            Self {
136                brand: Deserialize::default(),
137                brand_product: Deserialize::default(),
138                cardholder_name: Deserialize::default(),
139                country: Deserialize::default(),
140                description: Deserialize::default(),
141                exp_month: Deserialize::default(),
142                exp_year: Deserialize::default(),
143                fingerprint: Deserialize::default(),
144                funding: Deserialize::default(),
145                iin: Deserialize::default(),
146                issuer: Deserialize::default(),
147                last4: Deserialize::default(),
148                networks: Deserialize::default(),
149                offline: Deserialize::default(),
150                preferred_locales: Deserialize::default(),
151                read_method: Deserialize::default(),
152                wallet: Deserialize::default(),
153            }
154        }
155
156        fn take_out(&mut self) -> Option<Self::Out> {
157            let (
158                Some(brand),
159                Some(brand_product),
160                Some(cardholder_name),
161                Some(country),
162                Some(description),
163                Some(exp_month),
164                Some(exp_year),
165                Some(fingerprint),
166                Some(funding),
167                Some(iin),
168                Some(issuer),
169                Some(last4),
170                Some(networks),
171                Some(offline),
172                Some(preferred_locales),
173                Some(read_method),
174                Some(wallet),
175            ) = (
176                self.brand.take(),
177                self.brand_product.take(),
178                self.cardholder_name.take(),
179                self.country.take(),
180                self.description.take(),
181                self.exp_month,
182                self.exp_year,
183                self.fingerprint.take(),
184                self.funding.take(),
185                self.iin.take(),
186                self.issuer.take(),
187                self.last4.take(),
188                self.networks.take(),
189                self.offline,
190                self.preferred_locales.take(),
191                self.read_method,
192                self.wallet,
193            )
194            else {
195                return None;
196            };
197            Some(Self::Out {
198                brand,
199                brand_product,
200                cardholder_name,
201                country,
202                description,
203                exp_month,
204                exp_year,
205                fingerprint,
206                funding,
207                iin,
208                issuer,
209                last4,
210                networks,
211                offline,
212                preferred_locales,
213                read_method,
214                wallet,
215            })
216        }
217    }
218
219    impl<'a> Map for Builder<'a> {
220        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
221            self.builder.key(k)
222        }
223
224        fn finish(&mut self) -> Result<()> {
225            *self.out = self.builder.take_out();
226            Ok(())
227        }
228    }
229
230    impl ObjectDeser for PaymentMethodCardPresent {
231        type Builder = PaymentMethodCardPresentBuilder;
232    }
233
234    impl FromValueOpt for PaymentMethodCardPresent {
235        fn from_value(v: Value) -> Option<Self> {
236            let Value::Object(obj) = v else {
237                return None;
238            };
239            let mut b = PaymentMethodCardPresentBuilder::deser_default();
240            for (k, v) in obj {
241                match k.as_str() {
242                    "brand" => b.brand = FromValueOpt::from_value(v),
243                    "brand_product" => b.brand_product = FromValueOpt::from_value(v),
244                    "cardholder_name" => b.cardholder_name = FromValueOpt::from_value(v),
245                    "country" => b.country = FromValueOpt::from_value(v),
246                    "description" => b.description = FromValueOpt::from_value(v),
247                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
248                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
249                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
250                    "funding" => b.funding = FromValueOpt::from_value(v),
251                    "iin" => b.iin = FromValueOpt::from_value(v),
252                    "issuer" => b.issuer = FromValueOpt::from_value(v),
253                    "last4" => b.last4 = FromValueOpt::from_value(v),
254                    "networks" => b.networks = FromValueOpt::from_value(v),
255                    "offline" => b.offline = FromValueOpt::from_value(v),
256                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
257                    "read_method" => b.read_method = FromValueOpt::from_value(v),
258                    "wallet" => b.wallet = FromValueOpt::from_value(v),
259
260                    _ => {}
261                }
262            }
263            b.take_out()
264        }
265    }
266};
267/// How card details were read in this transaction.
268#[derive(Copy, Clone, Eq, PartialEq)]
269pub enum PaymentMethodCardPresentReadMethod {
270    ContactEmv,
271    ContactlessEmv,
272    ContactlessMagstripeMode,
273    MagneticStripeFallback,
274    MagneticStripeTrack2,
275}
276impl PaymentMethodCardPresentReadMethod {
277    pub fn as_str(self) -> &'static str {
278        use PaymentMethodCardPresentReadMethod::*;
279        match self {
280            ContactEmv => "contact_emv",
281            ContactlessEmv => "contactless_emv",
282            ContactlessMagstripeMode => "contactless_magstripe_mode",
283            MagneticStripeFallback => "magnetic_stripe_fallback",
284            MagneticStripeTrack2 => "magnetic_stripe_track2",
285        }
286    }
287}
288
289impl std::str::FromStr for PaymentMethodCardPresentReadMethod {
290    type Err = stripe_types::StripeParseError;
291    fn from_str(s: &str) -> Result<Self, Self::Err> {
292        use PaymentMethodCardPresentReadMethod::*;
293        match s {
294            "contact_emv" => Ok(ContactEmv),
295            "contactless_emv" => Ok(ContactlessEmv),
296            "contactless_magstripe_mode" => Ok(ContactlessMagstripeMode),
297            "magnetic_stripe_fallback" => Ok(MagneticStripeFallback),
298            "magnetic_stripe_track2" => Ok(MagneticStripeTrack2),
299            _ => Err(stripe_types::StripeParseError),
300        }
301    }
302}
303impl std::fmt::Display for PaymentMethodCardPresentReadMethod {
304    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
305        f.write_str(self.as_str())
306    }
307}
308
309impl std::fmt::Debug for PaymentMethodCardPresentReadMethod {
310    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
311        f.write_str(self.as_str())
312    }
313}
314#[cfg(feature = "serialize")]
315impl serde::Serialize for PaymentMethodCardPresentReadMethod {
316    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
317    where
318        S: serde::Serializer,
319    {
320        serializer.serialize_str(self.as_str())
321    }
322}
323impl miniserde::Deserialize for PaymentMethodCardPresentReadMethod {
324    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
325        crate::Place::new(out)
326    }
327}
328
329impl miniserde::de::Visitor for crate::Place<PaymentMethodCardPresentReadMethod> {
330    fn string(&mut self, s: &str) -> miniserde::Result<()> {
331        use std::str::FromStr;
332        self.out =
333            Some(PaymentMethodCardPresentReadMethod::from_str(s).map_err(|_| miniserde::Error)?);
334        Ok(())
335    }
336}
337
338stripe_types::impl_from_val_with_from_str!(PaymentMethodCardPresentReadMethod);
339#[cfg(feature = "deserialize")]
340impl<'de> serde::Deserialize<'de> for PaymentMethodCardPresentReadMethod {
341    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
342        use std::str::FromStr;
343        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
344        Self::from_str(&s).map_err(|_| {
345            serde::de::Error::custom("Unknown value for PaymentMethodCardPresentReadMethod")
346        })
347    }
348}