stripe_shared/
payment_method_options_satispay.rs

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