Skip to main content

stripe_shared/
payment_method_card_present.rs

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