Skip to main content

stripe_shared/
issuing_card_apple_pay.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 IssuingCardApplePay {
6    /// Apple Pay Eligibility
7    pub eligible: bool,
8    /// Reason the card is ineligible for Apple Pay
9    pub ineligible_reason: Option<IssuingCardApplePayIneligibleReason>,
10}
11#[cfg(feature = "redact-generated-debug")]
12impl std::fmt::Debug for IssuingCardApplePay {
13    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14        f.debug_struct("IssuingCardApplePay").finish_non_exhaustive()
15    }
16}
17#[doc(hidden)]
18pub struct IssuingCardApplePayBuilder {
19    eligible: Option<bool>,
20    ineligible_reason: Option<Option<IssuingCardApplePayIneligibleReason>>,
21}
22
23#[allow(
24    unused_variables,
25    irrefutable_let_patterns,
26    clippy::let_unit_value,
27    clippy::match_single_binding,
28    clippy::single_match
29)]
30const _: () = {
31    use miniserde::de::{Map, Visitor};
32    use miniserde::json::Value;
33    use miniserde::{Deserialize, Result, make_place};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for IssuingCardApplePay {
40        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41            Place::new(out)
42        }
43    }
44
45    struct Builder<'a> {
46        out: &'a mut Option<IssuingCardApplePay>,
47        builder: IssuingCardApplePayBuilder,
48    }
49
50    impl Visitor for Place<IssuingCardApplePay> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: IssuingCardApplePayBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for IssuingCardApplePayBuilder {
60        type Out = IssuingCardApplePay;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "eligible" => Deserialize::begin(&mut self.eligible),
64                "ineligible_reason" => Deserialize::begin(&mut self.ineligible_reason),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self { eligible: None, ineligible_reason: Some(None) }
71        }
72
73        fn take_out(&mut self) -> Option<Self::Out> {
74            let (Some(eligible), Some(ineligible_reason)) =
75                (self.eligible, self.ineligible_reason.take())
76            else {
77                return None;
78            };
79            Some(Self::Out { eligible, ineligible_reason })
80        }
81    }
82
83    impl Map for Builder<'_> {
84        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85            self.builder.key(k)
86        }
87
88        fn finish(&mut self) -> Result<()> {
89            *self.out = self.builder.take_out();
90            Ok(())
91        }
92    }
93
94    impl ObjectDeser for IssuingCardApplePay {
95        type Builder = IssuingCardApplePayBuilder;
96    }
97
98    impl FromValueOpt for IssuingCardApplePay {
99        fn from_value(v: Value) -> Option<Self> {
100            let Value::Object(obj) = v else {
101                return None;
102            };
103            let mut b = IssuingCardApplePayBuilder::deser_default();
104            for (k, v) in obj {
105                match k.as_str() {
106                    "eligible" => b.eligible = FromValueOpt::from_value(v),
107                    "ineligible_reason" => b.ineligible_reason = FromValueOpt::from_value(v),
108                    _ => {}
109                }
110            }
111            b.take_out()
112        }
113    }
114};
115/// Reason the card is ineligible for Apple Pay
116#[derive(Clone, Eq, PartialEq)]
117#[non_exhaustive]
118pub enum IssuingCardApplePayIneligibleReason {
119    MissingAgreement,
120    MissingCardholderContact,
121    UnsupportedRegion,
122    /// An unrecognized value from Stripe. Should not be used as a request parameter.
123    Unknown(String),
124}
125impl IssuingCardApplePayIneligibleReason {
126    pub fn as_str(&self) -> &str {
127        use IssuingCardApplePayIneligibleReason::*;
128        match self {
129            MissingAgreement => "missing_agreement",
130            MissingCardholderContact => "missing_cardholder_contact",
131            UnsupportedRegion => "unsupported_region",
132            Unknown(v) => v,
133        }
134    }
135}
136
137impl std::str::FromStr for IssuingCardApplePayIneligibleReason {
138    type Err = std::convert::Infallible;
139    fn from_str(s: &str) -> Result<Self, Self::Err> {
140        use IssuingCardApplePayIneligibleReason::*;
141        match s {
142            "missing_agreement" => Ok(MissingAgreement),
143            "missing_cardholder_contact" => Ok(MissingCardholderContact),
144            "unsupported_region" => Ok(UnsupportedRegion),
145            v => {
146                tracing::warn!(
147                    "Unknown value '{}' for enum '{}'",
148                    v,
149                    "IssuingCardApplePayIneligibleReason"
150                );
151                Ok(Unknown(v.to_owned()))
152            }
153        }
154    }
155}
156impl std::fmt::Display for IssuingCardApplePayIneligibleReason {
157    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161
162#[cfg(not(feature = "redact-generated-debug"))]
163impl std::fmt::Debug for IssuingCardApplePayIneligibleReason {
164    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165        f.write_str(self.as_str())
166    }
167}
168#[cfg(feature = "redact-generated-debug")]
169impl std::fmt::Debug for IssuingCardApplePayIneligibleReason {
170    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171        f.debug_struct(stringify!(IssuingCardApplePayIneligibleReason)).finish_non_exhaustive()
172    }
173}
174#[cfg(feature = "serialize")]
175impl serde::Serialize for IssuingCardApplePayIneligibleReason {
176    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
177    where
178        S: serde::Serializer,
179    {
180        serializer.serialize_str(self.as_str())
181    }
182}
183impl miniserde::Deserialize for IssuingCardApplePayIneligibleReason {
184    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
185        crate::Place::new(out)
186    }
187}
188
189impl miniserde::de::Visitor for crate::Place<IssuingCardApplePayIneligibleReason> {
190    fn string(&mut self, s: &str) -> miniserde::Result<()> {
191        use std::str::FromStr;
192        self.out = Some(IssuingCardApplePayIneligibleReason::from_str(s).expect("infallible"));
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(IssuingCardApplePayIneligibleReason);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for IssuingCardApplePayIneligibleReason {
200    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
201        use std::str::FromStr;
202        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
203        Ok(Self::from_str(&s).expect("infallible"))
204    }
205}