stripe_shared/
payment_flows_private_payment_methods_payco_payment_method_options.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptions {
5    /// Controls when the funds will be captured from the customer's account.
6    pub capture_method:
7        Option<PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod>,
8}
9#[doc(hidden)]
10pub struct PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsBuilder {
11    capture_method:
12        Option<Option<PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod>>,
13}
14
15#[allow(
16    unused_variables,
17    irrefutable_let_patterns,
18    clippy::let_unit_value,
19    clippy::match_single_binding,
20    clippy::single_match
21)]
22const _: () = {
23    use miniserde::de::{Map, Visitor};
24    use miniserde::json::Value;
25    use miniserde::{make_place, Deserialize, Result};
26    use stripe_types::miniserde_helpers::FromValueOpt;
27    use stripe_types::{MapBuilder, ObjectDeser};
28
29    make_place!(Place);
30
31    impl Deserialize for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptions {
32        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
33            Place::new(out)
34        }
35    }
36
37    struct Builder<'a> {
38        out: &'a mut Option<PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptions>,
39        builder: PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsBuilder,
40    }
41
42    impl Visitor for Place<PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptions> {
43        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
44            Ok(Box::new(Builder {
45                out: &mut self.out,
46                builder:
47                    PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsBuilder::deser_default(
48                    ),
49            }))
50        }
51    }
52
53    impl MapBuilder for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsBuilder {
54        type Out = PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptions;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "capture_method" => Deserialize::begin(&mut self.capture_method),
58
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { capture_method: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(capture_method),) = (self.capture_method,) else {
69                return None;
70            };
71            Some(Self::Out { capture_method })
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 PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptions {
87        type Builder = PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsBuilder;
88    }
89
90    impl FromValueOpt for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptions {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b =
96                PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
100
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(Copy, Clone, Eq, PartialEq)]
110pub enum PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod {
111    Manual,
112}
113impl PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod {
114    pub fn as_str(self) -> &'static str {
115        use PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod::*;
116        match self {
117            Manual => "manual",
118        }
119    }
120}
121
122impl std::str::FromStr for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod {
123    type Err = stripe_types::StripeParseError;
124    fn from_str(s: &str) -> Result<Self, Self::Err> {
125        use PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod::*;
126        match s {
127            "manual" => Ok(Manual),
128            _ => Err(stripe_types::StripeParseError),
129        }
130    }
131}
132impl std::fmt::Display for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod {
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 PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod {
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 PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod {
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
153    for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod
154{
155    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
156        crate::Place::new(out)
157    }
158}
159
160impl miniserde::de::Visitor
161    for crate::Place<PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod>
162{
163    fn string(&mut self, s: &str) -> miniserde::Result<()> {
164        use std::str::FromStr;
165        self.out = Some(
166            PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod::from_str(s)
167                .map_err(|_| miniserde::Error)?,
168        );
169        Ok(())
170    }
171}
172
173stripe_types::impl_from_val_with_from_str!(
174    PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod
175);
176#[cfg(feature = "deserialize")]
177impl<'de> serde::Deserialize<'de>
178    for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod
179{
180    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
181        use std::str::FromStr;
182        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
183        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for PaymentFlowsPrivatePaymentMethodsPaycoPaymentMethodOptionsCaptureMethod"))
184    }
185}