stripe_shared/
payment_flows_private_payment_methods_card_present_common_wallet.rs

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