stripe_shared/
payment_intent_processing.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentProcessing {
5    pub card: Option<stripe_shared::PaymentIntentCardProcessing>,
6    /// Type of the payment method for which payment is in `processing` state, one of `card`.
7    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
8    pub type_: PaymentIntentProcessingType,
9}
10#[doc(hidden)]
11pub struct PaymentIntentProcessingBuilder {
12    card: Option<Option<stripe_shared::PaymentIntentCardProcessing>>,
13    type_: Option<PaymentIntentProcessingType>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{make_place, Deserialize, Result};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for PaymentIntentProcessing {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<PaymentIntentProcessing>,
40        builder: PaymentIntentProcessingBuilder,
41    }
42
43    impl Visitor for Place<PaymentIntentProcessing> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: PaymentIntentProcessingBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for PaymentIntentProcessingBuilder {
53        type Out = PaymentIntentProcessing;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "card" => Deserialize::begin(&mut self.card),
57                "type" => Deserialize::begin(&mut self.type_),
58
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { card: Deserialize::default(), type_: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(card), Some(type_)) = (self.card, self.type_) else {
69                return None;
70            };
71            Some(Self::Out { card, type_ })
72        }
73    }
74
75    impl<'a> Map for Builder<'a> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for PaymentIntentProcessing {
87        type Builder = PaymentIntentProcessingBuilder;
88    }
89
90    impl FromValueOpt for PaymentIntentProcessing {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = PaymentIntentProcessingBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "card" => b.card = FromValueOpt::from_value(v),
99                    "type" => b.type_ = FromValueOpt::from_value(v),
100
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};
108/// Type of the payment method for which payment is in `processing` state, one of `card`.
109#[derive(Copy, Clone, Eq, PartialEq)]
110pub enum PaymentIntentProcessingType {
111    Card,
112}
113impl PaymentIntentProcessingType {
114    pub fn as_str(self) -> &'static str {
115        use PaymentIntentProcessingType::*;
116        match self {
117            Card => "card",
118        }
119    }
120}
121
122impl std::str::FromStr for PaymentIntentProcessingType {
123    type Err = stripe_types::StripeParseError;
124    fn from_str(s: &str) -> Result<Self, Self::Err> {
125        use PaymentIntentProcessingType::*;
126        match s {
127            "card" => Ok(Card),
128            _ => Err(stripe_types::StripeParseError),
129        }
130    }
131}
132impl std::fmt::Display for PaymentIntentProcessingType {
133    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
134        f.write_str(self.as_str())
135    }
136}
137
138impl std::fmt::Debug for PaymentIntentProcessingType {
139    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
140        f.write_str(self.as_str())
141    }
142}
143#[cfg(feature = "serialize")]
144impl serde::Serialize for PaymentIntentProcessingType {
145    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
146    where
147        S: serde::Serializer,
148    {
149        serializer.serialize_str(self.as_str())
150    }
151}
152impl miniserde::Deserialize for PaymentIntentProcessingType {
153    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
154        crate::Place::new(out)
155    }
156}
157
158impl miniserde::de::Visitor for crate::Place<PaymentIntentProcessingType> {
159    fn string(&mut self, s: &str) -> miniserde::Result<()> {
160        use std::str::FromStr;
161        self.out = Some(PaymentIntentProcessingType::from_str(s).map_err(|_| miniserde::Error)?);
162        Ok(())
163    }
164}
165
166stripe_types::impl_from_val_with_from_str!(PaymentIntentProcessingType);
167#[cfg(feature = "deserialize")]
168impl<'de> serde::Deserialize<'de> for PaymentIntentProcessingType {
169    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
170        use std::str::FromStr;
171        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
172        Self::from_str(&s)
173            .map_err(|_| serde::de::Error::custom("Unknown value for PaymentIntentProcessingType"))
174    }
175}