stripe_shared/
checkout_alma_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 CheckoutAlmaPaymentMethodOptions {
5    /// Controls when the funds will be captured from the customer's account.
6    pub capture_method: Option<CheckoutAlmaPaymentMethodOptionsCaptureMethod>,
7}
8#[doc(hidden)]
9pub struct CheckoutAlmaPaymentMethodOptionsBuilder {
10    capture_method: Option<Option<CheckoutAlmaPaymentMethodOptionsCaptureMethod>>,
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 CheckoutAlmaPaymentMethodOptions {
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<CheckoutAlmaPaymentMethodOptions>,
37        builder: CheckoutAlmaPaymentMethodOptionsBuilder,
38    }
39
40    impl Visitor for Place<CheckoutAlmaPaymentMethodOptions> {
41        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
42            Ok(Box::new(Builder {
43                out: &mut self.out,
44                builder: CheckoutAlmaPaymentMethodOptionsBuilder::deser_default(),
45            }))
46        }
47    }
48
49    impl MapBuilder for CheckoutAlmaPaymentMethodOptionsBuilder {
50        type Out = CheckoutAlmaPaymentMethodOptions;
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,) 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 CheckoutAlmaPaymentMethodOptions {
82        type Builder = CheckoutAlmaPaymentMethodOptionsBuilder;
83    }
84
85    impl FromValueOpt for CheckoutAlmaPaymentMethodOptions {
86        fn from_value(v: Value) -> Option<Self> {
87            let Value::Object(obj) = v else {
88                return None;
89            };
90            let mut b = CheckoutAlmaPaymentMethodOptionsBuilder::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(Copy, Clone, Eq, PartialEq)]
103pub enum CheckoutAlmaPaymentMethodOptionsCaptureMethod {
104    Manual,
105}
106impl CheckoutAlmaPaymentMethodOptionsCaptureMethod {
107    pub fn as_str(self) -> &'static str {
108        use CheckoutAlmaPaymentMethodOptionsCaptureMethod::*;
109        match self {
110            Manual => "manual",
111        }
112    }
113}
114
115impl std::str::FromStr for CheckoutAlmaPaymentMethodOptionsCaptureMethod {
116    type Err = stripe_types::StripeParseError;
117    fn from_str(s: &str) -> Result<Self, Self::Err> {
118        use CheckoutAlmaPaymentMethodOptionsCaptureMethod::*;
119        match s {
120            "manual" => Ok(Manual),
121            _ => Err(stripe_types::StripeParseError),
122        }
123    }
124}
125impl std::fmt::Display for CheckoutAlmaPaymentMethodOptionsCaptureMethod {
126    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
127        f.write_str(self.as_str())
128    }
129}
130
131impl std::fmt::Debug for CheckoutAlmaPaymentMethodOptionsCaptureMethod {
132    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
133        f.write_str(self.as_str())
134    }
135}
136#[cfg(feature = "serialize")]
137impl serde::Serialize for CheckoutAlmaPaymentMethodOptionsCaptureMethod {
138    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
139    where
140        S: serde::Serializer,
141    {
142        serializer.serialize_str(self.as_str())
143    }
144}
145impl miniserde::Deserialize for CheckoutAlmaPaymentMethodOptionsCaptureMethod {
146    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
147        crate::Place::new(out)
148    }
149}
150
151impl miniserde::de::Visitor for crate::Place<CheckoutAlmaPaymentMethodOptionsCaptureMethod> {
152    fn string(&mut self, s: &str) -> miniserde::Result<()> {
153        use std::str::FromStr;
154        self.out = Some(
155            CheckoutAlmaPaymentMethodOptionsCaptureMethod::from_str(s)
156                .map_err(|_| miniserde::Error)?,
157        );
158        Ok(())
159    }
160}
161
162stripe_types::impl_from_val_with_from_str!(CheckoutAlmaPaymentMethodOptionsCaptureMethod);
163#[cfg(feature = "deserialize")]
164impl<'de> serde::Deserialize<'de> for CheckoutAlmaPaymentMethodOptionsCaptureMethod {
165    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
166        use std::str::FromStr;
167        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
168        Self::from_str(&s).map_err(|_| {
169            serde::de::Error::custom(
170                "Unknown value for CheckoutAlmaPaymentMethodOptionsCaptureMethod",
171            )
172        })
173    }
174}