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