Skip to main content

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