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`, `cartes_bancaires`, `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    /// The languages that the issuing bank recommends using for localizing any customer-facing text, as read from the card.
46    /// Referenced from EMV tag 5F2D, data encoded on the card's chip.
47    pub preferred_locales: Option<Vec<String>>,
48    /// How card details were read in this transaction.
49    pub read_method: Option<PaymentMethodCardPresentReadMethod>,
50    pub wallet: Option<stripe_shared::PaymentFlowsPrivatePaymentMethodsCardPresentCommonWallet>,
51}
52#[doc(hidden)]
53pub struct PaymentMethodCardPresentBuilder {
54    brand: Option<Option<String>>,
55    brand_product: Option<Option<String>>,
56    cardholder_name: Option<Option<String>>,
57    country: Option<Option<String>>,
58    description: Option<Option<String>>,
59    exp_month: Option<i64>,
60    exp_year: Option<i64>,
61    fingerprint: Option<Option<String>>,
62    funding: Option<Option<String>>,
63    iin: Option<Option<String>>,
64    issuer: Option<Option<String>>,
65    last4: Option<Option<String>>,
66    networks: Option<Option<stripe_shared::PaymentMethodCardPresentNetworks>>,
67    offline: Option<Option<stripe_shared::PaymentMethodDetailsCardPresentOffline>>,
68    preferred_locales: Option<Option<Vec<String>>>,
69    read_method: Option<Option<PaymentMethodCardPresentReadMethod>>,
70    wallet: Option<Option<stripe_shared::PaymentFlowsPrivatePaymentMethodsCardPresentCommonWallet>>,
71}
72
73#[allow(
74    unused_variables,
75    irrefutable_let_patterns,
76    clippy::let_unit_value,
77    clippy::match_single_binding,
78    clippy::single_match
79)]
80const _: () = {
81    use miniserde::de::{Map, Visitor};
82    use miniserde::json::Value;
83    use miniserde::{make_place, Deserialize, Result};
84    use stripe_types::miniserde_helpers::FromValueOpt;
85    use stripe_types::{MapBuilder, ObjectDeser};
86
87    make_place!(Place);
88
89    impl Deserialize for PaymentMethodCardPresent {
90        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
91            Place::new(out)
92        }
93    }
94
95    struct Builder<'a> {
96        out: &'a mut Option<PaymentMethodCardPresent>,
97        builder: PaymentMethodCardPresentBuilder,
98    }
99
100    impl Visitor for Place<PaymentMethodCardPresent> {
101        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
102            Ok(Box::new(Builder {
103                out: &mut self.out,
104                builder: PaymentMethodCardPresentBuilder::deser_default(),
105            }))
106        }
107    }
108
109    impl MapBuilder for PaymentMethodCardPresentBuilder {
110        type Out = PaymentMethodCardPresent;
111        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
112            Ok(match k {
113                "brand" => Deserialize::begin(&mut self.brand),
114                "brand_product" => Deserialize::begin(&mut self.brand_product),
115                "cardholder_name" => Deserialize::begin(&mut self.cardholder_name),
116                "country" => Deserialize::begin(&mut self.country),
117                "description" => Deserialize::begin(&mut self.description),
118                "exp_month" => Deserialize::begin(&mut self.exp_month),
119                "exp_year" => Deserialize::begin(&mut self.exp_year),
120                "fingerprint" => Deserialize::begin(&mut self.fingerprint),
121                "funding" => Deserialize::begin(&mut self.funding),
122                "iin" => Deserialize::begin(&mut self.iin),
123                "issuer" => Deserialize::begin(&mut self.issuer),
124                "last4" => Deserialize::begin(&mut self.last4),
125                "networks" => Deserialize::begin(&mut self.networks),
126                "offline" => Deserialize::begin(&mut self.offline),
127                "preferred_locales" => Deserialize::begin(&mut self.preferred_locales),
128                "read_method" => Deserialize::begin(&mut self.read_method),
129                "wallet" => Deserialize::begin(&mut self.wallet),
130
131                _ => <dyn Visitor>::ignore(),
132            })
133        }
134
135        fn deser_default() -> Self {
136            Self {
137                brand: Deserialize::default(),
138                brand_product: Deserialize::default(),
139                cardholder_name: Deserialize::default(),
140                country: Deserialize::default(),
141                description: Deserialize::default(),
142                exp_month: Deserialize::default(),
143                exp_year: Deserialize::default(),
144                fingerprint: Deserialize::default(),
145                funding: Deserialize::default(),
146                iin: Deserialize::default(),
147                issuer: Deserialize::default(),
148                last4: Deserialize::default(),
149                networks: Deserialize::default(),
150                offline: Deserialize::default(),
151                preferred_locales: Deserialize::default(),
152                read_method: Deserialize::default(),
153                wallet: Deserialize::default(),
154            }
155        }
156
157        fn take_out(&mut self) -> Option<Self::Out> {
158            let (
159                Some(brand),
160                Some(brand_product),
161                Some(cardholder_name),
162                Some(country),
163                Some(description),
164                Some(exp_month),
165                Some(exp_year),
166                Some(fingerprint),
167                Some(funding),
168                Some(iin),
169                Some(issuer),
170                Some(last4),
171                Some(networks),
172                Some(offline),
173                Some(preferred_locales),
174                Some(read_method),
175                Some(wallet),
176            ) = (
177                self.brand.take(),
178                self.brand_product.take(),
179                self.cardholder_name.take(),
180                self.country.take(),
181                self.description.take(),
182                self.exp_month,
183                self.exp_year,
184                self.fingerprint.take(),
185                self.funding.take(),
186                self.iin.take(),
187                self.issuer.take(),
188                self.last4.take(),
189                self.networks.take(),
190                self.offline,
191                self.preferred_locales.take(),
192                self.read_method,
193                self.wallet,
194            )
195            else {
196                return None;
197            };
198            Some(Self::Out {
199                brand,
200                brand_product,
201                cardholder_name,
202                country,
203                description,
204                exp_month,
205                exp_year,
206                fingerprint,
207                funding,
208                iin,
209                issuer,
210                last4,
211                networks,
212                offline,
213                preferred_locales,
214                read_method,
215                wallet,
216            })
217        }
218    }
219
220    impl Map for Builder<'_> {
221        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
222            self.builder.key(k)
223        }
224
225        fn finish(&mut self) -> Result<()> {
226            *self.out = self.builder.take_out();
227            Ok(())
228        }
229    }
230
231    impl ObjectDeser for PaymentMethodCardPresent {
232        type Builder = PaymentMethodCardPresentBuilder;
233    }
234
235    impl FromValueOpt for PaymentMethodCardPresent {
236        fn from_value(v: Value) -> Option<Self> {
237            let Value::Object(obj) = v else {
238                return None;
239            };
240            let mut b = PaymentMethodCardPresentBuilder::deser_default();
241            for (k, v) in obj {
242                match k.as_str() {
243                    "brand" => b.brand = FromValueOpt::from_value(v),
244                    "brand_product" => b.brand_product = FromValueOpt::from_value(v),
245                    "cardholder_name" => b.cardholder_name = FromValueOpt::from_value(v),
246                    "country" => b.country = FromValueOpt::from_value(v),
247                    "description" => b.description = FromValueOpt::from_value(v),
248                    "exp_month" => b.exp_month = FromValueOpt::from_value(v),
249                    "exp_year" => b.exp_year = FromValueOpt::from_value(v),
250                    "fingerprint" => b.fingerprint = FromValueOpt::from_value(v),
251                    "funding" => b.funding = FromValueOpt::from_value(v),
252                    "iin" => b.iin = FromValueOpt::from_value(v),
253                    "issuer" => b.issuer = FromValueOpt::from_value(v),
254                    "last4" => b.last4 = FromValueOpt::from_value(v),
255                    "networks" => b.networks = FromValueOpt::from_value(v),
256                    "offline" => b.offline = FromValueOpt::from_value(v),
257                    "preferred_locales" => b.preferred_locales = FromValueOpt::from_value(v),
258                    "read_method" => b.read_method = FromValueOpt::from_value(v),
259                    "wallet" => b.wallet = FromValueOpt::from_value(v),
260
261                    _ => {}
262                }
263            }
264            b.take_out()
265        }
266    }
267};
268/// How card details were read in this transaction.
269#[derive(Copy, Clone, Eq, PartialEq)]
270pub enum PaymentMethodCardPresentReadMethod {
271    ContactEmv,
272    ContactlessEmv,
273    ContactlessMagstripeMode,
274    MagneticStripeFallback,
275    MagneticStripeTrack2,
276}
277impl PaymentMethodCardPresentReadMethod {
278    pub fn as_str(self) -> &'static str {
279        use PaymentMethodCardPresentReadMethod::*;
280        match self {
281            ContactEmv => "contact_emv",
282            ContactlessEmv => "contactless_emv",
283            ContactlessMagstripeMode => "contactless_magstripe_mode",
284            MagneticStripeFallback => "magnetic_stripe_fallback",
285            MagneticStripeTrack2 => "magnetic_stripe_track2",
286        }
287    }
288}
289
290impl std::str::FromStr for PaymentMethodCardPresentReadMethod {
291    type Err = stripe_types::StripeParseError;
292    fn from_str(s: &str) -> Result<Self, Self::Err> {
293        use PaymentMethodCardPresentReadMethod::*;
294        match s {
295            "contact_emv" => Ok(ContactEmv),
296            "contactless_emv" => Ok(ContactlessEmv),
297            "contactless_magstripe_mode" => Ok(ContactlessMagstripeMode),
298            "magnetic_stripe_fallback" => Ok(MagneticStripeFallback),
299            "magnetic_stripe_track2" => Ok(MagneticStripeTrack2),
300            _ => Err(stripe_types::StripeParseError),
301        }
302    }
303}
304impl std::fmt::Display for PaymentMethodCardPresentReadMethod {
305    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
306        f.write_str(self.as_str())
307    }
308}
309
310impl std::fmt::Debug for PaymentMethodCardPresentReadMethod {
311    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
312        f.write_str(self.as_str())
313    }
314}
315#[cfg(feature = "serialize")]
316impl serde::Serialize for PaymentMethodCardPresentReadMethod {
317    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
318    where
319        S: serde::Serializer,
320    {
321        serializer.serialize_str(self.as_str())
322    }
323}
324impl miniserde::Deserialize for PaymentMethodCardPresentReadMethod {
325    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
326        crate::Place::new(out)
327    }
328}
329
330impl miniserde::de::Visitor for crate::Place<PaymentMethodCardPresentReadMethod> {
331    fn string(&mut self, s: &str) -> miniserde::Result<()> {
332        use std::str::FromStr;
333        self.out =
334            Some(PaymentMethodCardPresentReadMethod::from_str(s).map_err(|_| miniserde::Error)?);
335        Ok(())
336    }
337}
338
339stripe_types::impl_from_val_with_from_str!(PaymentMethodCardPresentReadMethod);
340#[cfg(feature = "deserialize")]
341impl<'de> serde::Deserialize<'de> for PaymentMethodCardPresentReadMethod {
342    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
343        use std::str::FromStr;
344        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
345        Self::from_str(&s).map_err(|_| {
346            serde::de::Error::custom("Unknown value for PaymentMethodCardPresentReadMethod")
347        })
348    }
349}