Skip to main content

stripe_shared/
payment_method_details_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 PaymentMethodDetailsCardPresent {
6    /// The authorized amount
7    pub amount_authorized: Option<i64>,
8    /// Card brand.
9    /// Can be `amex`, `cartes_bancaires`, `diners`, `discover`, `eftpos_au`, `jcb`, `link`, `mastercard`, `unionpay`, `visa` or `unknown`.
10    pub brand: Option<String>,
11    /// The [product code](https://stripe.com/docs/card-product-codes) that identifies the specific program or product associated with a card.
12    pub brand_product: Option<String>,
13    /// When using manual capture, a future timestamp after which the charge will be automatically refunded if uncaptured.
14    pub capture_before: Option<stripe_types::Timestamp>,
15    /// The cardholder name as read from the card, in [ISO 7813](https://en.wikipedia.org/wiki/ISO/IEC_7813) format.
16    /// May include alphanumeric characters, special characters and first/last name separator (`/`).
17    /// In some cases, the cardholder name may not be available depending on how the issuer has configured the card.
18    /// Cardholder name is typically not available on swipe or contactless payments, such as those made with Apple Pay and Google Pay.
19    pub cardholder_name: Option<String>,
20    /// Two-letter ISO code representing the country of the card.
21    /// You could use this attribute to get a sense of the international breakdown of cards you've collected.
22    pub country: Option<String>,
23    /// A high-level description of the type of cards issued in this range.
24    /// (For internal use only and not typically available in standard API requests.).
25    pub description: Option<String>,
26    /// Authorization response cryptogram.
27    pub emv_auth_data: Option<String>,
28    /// Two-digit number representing the card's expiration month.
29    pub exp_month: i64,
30    /// Four-digit number representing the card's expiration year.
31    pub exp_year: i64,
32    /// Uniquely identifies this particular card number.
33    /// You can use this attribute to check whether two customers who’ve signed up with you are using the same card number, for example.
34    /// For payment methods that tokenize card information (Apple Pay, Google Pay), the tokenized number might be provided instead of the underlying card number.
35    ///
36    /// *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.*.
37    pub fingerprint: Option<String>,
38    /// Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
39    pub funding: Option<String>,
40    /// ID of a card PaymentMethod generated from the card_present PaymentMethod that may be attached to a Customer for future transactions.
41    /// Only present if it was possible to generate a card PaymentMethod.
42    pub generated_card: Option<String>,
43    /// Issuer identification number of the card.
44    /// (For internal use only and not typically available in standard API requests.).
45    pub iin: Option<String>,
46    /// Whether this [PaymentIntent](https://docs.stripe.com/api/payment_intents) is eligible for incremental authorizations.
47    /// Request support using [request_incremental_authorization_support](https://docs.stripe.com/api/payment_intents/create#create_payment_intent-payment_method_options-card_present-request_incremental_authorization_support).
48    pub incremental_authorization_supported: bool,
49    /// The name of the card's issuing bank.
50    /// (For internal use only and not typically available in standard API requests.).
51    pub issuer: Option<String>,
52    /// The last four digits of the card.
53    pub last4: Option<String>,
54    /// ID of the [location](https://docs.stripe.com/api/terminal/locations) that this transaction's reader is assigned to.
55    pub location: Option<String>,
56    /// Identifies which network this charge was processed on.
57    /// Can be `amex`, `cartes_bancaires`, `diners`, `discover`, `eftpos_au`, `interac`, `jcb`, `link`, `mastercard`, `unionpay`, `visa`, or `unknown`.
58    pub network: Option<String>,
59    /// This is used by the financial networks to identify a transaction.
60    /// Visa calls this the Transaction ID, Mastercard calls this the Trace ID, and American Express calls this the Acquirer Reference Data.
61    /// This value will be present if it is returned by the financial network in the authorization response, and null otherwise.
62    pub network_transaction_id: Option<String>,
63    /// Details about payments collected offline.
64    pub offline: Option<stripe_shared::PaymentMethodDetailsCardPresentOffline>,
65    /// Defines whether the authorized amount can be over-captured or not
66    pub overcapture_supported: bool,
67    /// The languages that the issuing bank recommends using for localizing any customer-facing text, as read from the card.
68    /// Referenced from EMV tag 5F2D, data encoded on the card's chip.
69    pub preferred_locales: Option<Vec<String>>,
70    /// How card details were read in this transaction.
71    pub read_method: Option<PaymentMethodDetailsCardPresentReadMethod>,
72    /// ID of the [reader](https://docs.stripe.com/api/terminal/readers) this transaction was made on.
73    pub reader: Option<String>,
74    /// A collection of fields required to be displayed on receipts. Only required for EMV transactions.
75    pub receipt: Option<stripe_shared::PaymentMethodDetailsCardPresentReceipt>,
76    pub wallet: Option<stripe_shared::PaymentFlowsPrivatePaymentMethodsCardPresentCommonWallet>,
77}
78#[cfg(feature = "redact-generated-debug")]
79impl std::fmt::Debug for PaymentMethodDetailsCardPresent {
80    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
81        f.debug_struct("PaymentMethodDetailsCardPresent").finish_non_exhaustive()
82    }
83}
84#[doc(hidden)]
85pub struct PaymentMethodDetailsCardPresentBuilder {
86    amount_authorized: Option<Option<i64>>,
87    brand: Option<Option<String>>,
88    brand_product: Option<Option<String>>,
89    capture_before: Option<Option<stripe_types::Timestamp>>,
90    cardholder_name: Option<Option<String>>,
91    country: Option<Option<String>>,
92    description: Option<Option<String>>,
93    emv_auth_data: Option<Option<String>>,
94    exp_month: Option<i64>,
95    exp_year: Option<i64>,
96    fingerprint: Option<Option<String>>,
97    funding: Option<Option<String>>,
98    generated_card: Option<Option<String>>,
99    iin: Option<Option<String>>,
100    incremental_authorization_supported: Option<bool>,
101    issuer: Option<Option<String>>,
102    last4: Option<Option<String>>,
103    location: Option<Option<String>>,
104    network: Option<Option<String>>,
105    network_transaction_id: Option<Option<String>>,
106    offline: Option<Option<stripe_shared::PaymentMethodDetailsCardPresentOffline>>,
107    overcapture_supported: Option<bool>,
108    preferred_locales: Option<Option<Vec<String>>>,
109    read_method: Option<Option<PaymentMethodDetailsCardPresentReadMethod>>,
110    reader: Option<Option<String>>,
111    receipt: Option<Option<stripe_shared::PaymentMethodDetailsCardPresentReceipt>>,
112    wallet: Option<Option<stripe_shared::PaymentFlowsPrivatePaymentMethodsCardPresentCommonWallet>>,
113}
114
115#[allow(
116    unused_variables,
117    irrefutable_let_patterns,
118    clippy::let_unit_value,
119    clippy::match_single_binding,
120    clippy::single_match
121)]
122const _: () = {
123    use miniserde::de::{Map, Visitor};
124    use miniserde::json::Value;
125    use miniserde::{Deserialize, Result, make_place};
126    use stripe_types::miniserde_helpers::FromValueOpt;
127    use stripe_types::{MapBuilder, ObjectDeser};
128
129    make_place!(Place);
130
131    impl Deserialize for PaymentMethodDetailsCardPresent {
132        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
133            Place::new(out)
134        }
135    }
136
137    struct Builder<'a> {
138        out: &'a mut Option<PaymentMethodDetailsCardPresent>,
139        builder: PaymentMethodDetailsCardPresentBuilder,
140    }
141
142    impl Visitor for Place<PaymentMethodDetailsCardPresent> {
143        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
144            Ok(Box::new(Builder {
145                out: &mut self.out,
146                builder: PaymentMethodDetailsCardPresentBuilder::deser_default(),
147            }))
148        }
149    }
150
151    impl MapBuilder for PaymentMethodDetailsCardPresentBuilder {
152        type Out = PaymentMethodDetailsCardPresent;
153        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
154            Ok(match k {
155                "amount_authorized" => Deserialize::begin(&mut self.amount_authorized),
156                "brand" => Deserialize::begin(&mut self.brand),
157                "brand_product" => Deserialize::begin(&mut self.brand_product),
158                "capture_before" => Deserialize::begin(&mut self.capture_before),
159                "cardholder_name" => Deserialize::begin(&mut self.cardholder_name),
160                "country" => Deserialize::begin(&mut self.country),
161                "description" => Deserialize::begin(&mut self.description),
162                "emv_auth_data" => Deserialize::begin(&mut self.emv_auth_data),
163                "exp_month" => Deserialize::begin(&mut self.exp_month),
164                "exp_year" => Deserialize::begin(&mut self.exp_year),
165                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
166                "funding" => Deserialize::begin(&mut self.funding),
167                "generated_card" => Deserialize::begin(&mut self.generated_card),
168                "iin" => Deserialize::begin(&mut self.iin),
169                "incremental_authorization_supported" => {
170                    Deserialize::begin(&mut self.incremental_authorization_supported)
171                }
172                "issuer" => Deserialize::begin(&mut self.issuer),
173                "last4" => Deserialize::begin(&mut self.last4),
174                "location" => Deserialize::begin(&mut self.location),
175                "network" => Deserialize::begin(&mut self.network),
176                "network_transaction_id" => Deserialize::begin(&mut self.network_transaction_id),
177                "offline" => Deserialize::begin(&mut self.offline),
178                "overcapture_supported" => Deserialize::begin(&mut self.overcapture_supported),
179                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
180                "read_method" => Deserialize::begin(&mut self.read_method),
181                "reader" => Deserialize::begin(&mut self.reader),
182                "receipt" => Deserialize::begin(&mut self.receipt),
183                "wallet" => Deserialize::begin(&mut self.wallet),
184                _ => <dyn Visitor>::ignore(),
185            })
186        }
187
188        fn deser_default() -> Self {
189            Self {
190                amount_authorized: Some(None),
191                brand: Some(None),
192                brand_product: Some(None),
193                capture_before: Some(None),
194                cardholder_name: Some(None),
195                country: Some(None),
196                description: Some(None),
197                emv_auth_data: Some(None),
198                exp_month: None,
199                exp_year: None,
200                fingerprint: Some(None),
201                funding: Some(None),
202                generated_card: Some(None),
203                iin: Some(None),
204                incremental_authorization_supported: None,
205                issuer: Some(None),
206                last4: Some(None),
207                location: Some(None),
208                network: Some(None),
209                network_transaction_id: Some(None),
210                offline: Some(None),
211                overcapture_supported: None,
212                preferred_locales: Some(None),
213                read_method: Some(None),
214                reader: Some(None),
215                receipt: Some(None),
216                wallet: Some(None),
217            }
218        }
219
220        fn take_out(&mut self) -> Option<Self::Out> {
221            let (
222                Some(amount_authorized),
223                Some(brand),
224                Some(brand_product),
225                Some(capture_before),
226                Some(cardholder_name),
227                Some(country),
228                Some(description),
229                Some(emv_auth_data),
230                Some(exp_month),
231                Some(exp_year),
232                Some(fingerprint),
233                Some(funding),
234                Some(generated_card),
235                Some(iin),
236                Some(incremental_authorization_supported),
237                Some(issuer),
238                Some(last4),
239                Some(location),
240                Some(network),
241                Some(network_transaction_id),
242                Some(offline),
243                Some(overcapture_supported),
244                Some(preferred_locales),
245                Some(read_method),
246                Some(reader),
247                Some(receipt),
248                Some(wallet),
249            ) = (
250                self.amount_authorized,
251                self.brand.take(),
252                self.brand_product.take(),
253                self.capture_before,
254                self.cardholder_name.take(),
255                self.country.take(),
256                self.description.take(),
257                self.emv_auth_data.take(),
258                self.exp_month,
259                self.exp_year,
260                self.fingerprint.take(),
261                self.funding.take(),
262                self.generated_card.take(),
263                self.iin.take(),
264                self.incremental_authorization_supported,
265                self.issuer.take(),
266                self.last4.take(),
267                self.location.take(),
268                self.network.take(),
269                self.network_transaction_id.take(),
270                self.offline.take(),
271                self.overcapture_supported,
272                self.preferred_locales.take(),
273                self.read_method.take(),
274                self.reader.take(),
275                self.receipt.take(),
276                self.wallet.take(),
277            )
278            else {
279                return None;
280            };
281            Some(Self::Out {
282                amount_authorized,
283                brand,
284                brand_product,
285                capture_before,
286                cardholder_name,
287                country,
288                description,
289                emv_auth_data,
290                exp_month,
291                exp_year,
292                fingerprint,
293                funding,
294                generated_card,
295                iin,
296                incremental_authorization_supported,
297                issuer,
298                last4,
299                location,
300                network,
301                network_transaction_id,
302                offline,
303                overcapture_supported,
304                preferred_locales,
305                read_method,
306                reader,
307                receipt,
308                wallet,
309            })
310        }
311    }
312
313    impl Map for Builder<'_> {
314        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
315            self.builder.key(k)
316        }
317
318        fn finish(&mut self) -> Result<()> {
319            *self.out = self.builder.take_out();
320            Ok(())
321        }
322    }
323
324    impl ObjectDeser for PaymentMethodDetailsCardPresent {
325        type Builder = PaymentMethodDetailsCardPresentBuilder;
326    }
327
328    impl FromValueOpt for PaymentMethodDetailsCardPresent {
329        fn from_value(v: Value) -> Option<Self> {
330            let Value::Object(obj) = v else {
331                return None;
332            };
333            let mut b = PaymentMethodDetailsCardPresentBuilder::deser_default();
334            for (k, v) in obj {
335                match k.as_str() {
336                    "amount_authorized" => b.amount_authorized = FromValueOpt::from_value(v),
337                    "brand" => b.brand = FromValueOpt::from_value(v),
338                    "brand_product" => b.brand_product = FromValueOpt::from_value(v),
339                    "capture_before" => b.capture_before = FromValueOpt::from_value(v),
340                    "cardholder_name" => b.cardholder_name = FromValueOpt::from_value(v),
341                    "country" => b.country = FromValueOpt::from_value(v),
342                    "description" => b.description = FromValueOpt::from_value(v),
343                    "emv_auth_data" => b.emv_auth_data = FromValueOpt::from_value(v),
344                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
345                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
346                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
347                    "funding" => b.funding = FromValueOpt::from_value(v),
348                    "generated_card" => b.generated_card = FromValueOpt::from_value(v),
349                    "iin" => b.iin = FromValueOpt::from_value(v),
350                    "incremental_authorization_supported" => {
351                        b.incremental_authorization_supported = FromValueOpt::from_value(v)
352                    }
353                    "issuer" => b.issuer = FromValueOpt::from_value(v),
354                    "last4" => b.last4 = FromValueOpt::from_value(v),
355                    "location" => b.location = FromValueOpt::from_value(v),
356                    "network" => b.network = FromValueOpt::from_value(v),
357                    "network_transaction_id" => {
358                        b.network_transaction_id = FromValueOpt::from_value(v)
359                    }
360                    "offline" => b.offline = FromValueOpt::from_value(v),
361                    "overcapture_supported" => {
362                        b.overcapture_supported = FromValueOpt::from_value(v)
363                    }
364                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
365                    "read_method" => b.read_method = FromValueOpt::from_value(v),
366                    "reader" => b.reader = FromValueOpt::from_value(v),
367                    "receipt" => b.receipt = FromValueOpt::from_value(v),
368                    "wallet" => b.wallet = FromValueOpt::from_value(v),
369                    _ => {}
370                }
371            }
372            b.take_out()
373        }
374    }
375};
376/// How card details were read in this transaction.
377#[derive(Clone, Eq, PartialEq)]
378#[non_exhaustive]
379pub enum PaymentMethodDetailsCardPresentReadMethod {
380    ContactEmv,
381    ContactlessEmv,
382    ContactlessMagstripeMode,
383    MagneticStripeFallback,
384    MagneticStripeTrack2,
385    /// An unrecognized value from Stripe. Should not be used as a request parameter.
386    Unknown(String),
387}
388impl PaymentMethodDetailsCardPresentReadMethod {
389    pub fn as_str(&self) -> &str {
390        use PaymentMethodDetailsCardPresentReadMethod::*;
391        match self {
392            ContactEmv => "contact_emv",
393            ContactlessEmv => "contactless_emv",
394            ContactlessMagstripeMode => "contactless_magstripe_mode",
395            MagneticStripeFallback => "magnetic_stripe_fallback",
396            MagneticStripeTrack2 => "magnetic_stripe_track2",
397            Unknown(v) => v,
398        }
399    }
400}
401
402impl std::str::FromStr for PaymentMethodDetailsCardPresentReadMethod {
403    type Err = std::convert::Infallible;
404    fn from_str(s: &str) -> Result<Self, Self::Err> {
405        use PaymentMethodDetailsCardPresentReadMethod::*;
406        match s {
407            "contact_emv" => Ok(ContactEmv),
408            "contactless_emv" => Ok(ContactlessEmv),
409            "contactless_magstripe_mode" => Ok(ContactlessMagstripeMode),
410            "magnetic_stripe_fallback" => Ok(MagneticStripeFallback),
411            "magnetic_stripe_track2" => Ok(MagneticStripeTrack2),
412            v => {
413                tracing::warn!(
414                    "Unknown value '{}' for enum '{}'",
415                    v,
416                    "PaymentMethodDetailsCardPresentReadMethod"
417                );
418                Ok(Unknown(v.to_owned()))
419            }
420        }
421    }
422}
423impl std::fmt::Display for PaymentMethodDetailsCardPresentReadMethod {
424    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
425        f.write_str(self.as_str())
426    }
427}
428
429#[cfg(not(feature = "redact-generated-debug"))]
430impl std::fmt::Debug for PaymentMethodDetailsCardPresentReadMethod {
431    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
432        f.write_str(self.as_str())
433    }
434}
435#[cfg(feature = "redact-generated-debug")]
436impl std::fmt::Debug for PaymentMethodDetailsCardPresentReadMethod {
437    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
438        f.debug_struct(stringify!(PaymentMethodDetailsCardPresentReadMethod))
439            .finish_non_exhaustive()
440    }
441}
442#[cfg(feature = "serialize")]
443impl serde::Serialize for PaymentMethodDetailsCardPresentReadMethod {
444    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
445    where
446        S: serde::Serializer,
447    {
448        serializer.serialize_str(self.as_str())
449    }
450}
451impl miniserde::Deserialize for PaymentMethodDetailsCardPresentReadMethod {
452    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
453        crate::Place::new(out)
454    }
455}
456
457impl miniserde::de::Visitor for crate::Place<PaymentMethodDetailsCardPresentReadMethod> {
458    fn string(&mut self, s: &str) -> miniserde::Result<()> {
459        use std::str::FromStr;
460        self.out =
461            Some(PaymentMethodDetailsCardPresentReadMethod::from_str(s).expect("infallible"));
462        Ok(())
463    }
464}
465
466stripe_types::impl_from_val_with_from_str!(PaymentMethodDetailsCardPresentReadMethod);
467#[cfg(feature = "deserialize")]
468impl<'de> serde::Deserialize<'de> for PaymentMethodDetailsCardPresentReadMethod {
469    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
470        use std::str::FromStr;
471        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
472        Ok(Self::from_str(&s).expect("infallible"))
473    }
474}