stripe_shared/
checkout_payco_payment_method_options.rs

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