stripe_shared/
checkout_afterpay_clearpay_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 CheckoutAfterpayClearpayPaymentMethodOptions {
5    /// Controls when the funds will be captured from the customer's account.
6    pub capture_method: Option<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>,
7    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
8    ///
9    /// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
10    /// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
11    ///
12    /// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
13    ///
14    /// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
15    pub setup_future_usage: Option<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>,
16}
17#[doc(hidden)]
18pub struct CheckoutAfterpayClearpayPaymentMethodOptionsBuilder {
19    capture_method: Option<Option<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>>,
20    setup_future_usage:
21        Option<Option<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>>,
22}
23
24#[allow(
25    unused_variables,
26    irrefutable_let_patterns,
27    clippy::let_unit_value,
28    clippy::match_single_binding,
29    clippy::single_match
30)]
31const _: () = {
32    use miniserde::de::{Map, Visitor};
33    use miniserde::json::Value;
34    use miniserde::{Deserialize, Result, make_place};
35    use stripe_types::miniserde_helpers::FromValueOpt;
36    use stripe_types::{MapBuilder, ObjectDeser};
37
38    make_place!(Place);
39
40    impl Deserialize for CheckoutAfterpayClearpayPaymentMethodOptions {
41        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
42            Place::new(out)
43        }
44    }
45
46    struct Builder<'a> {
47        out: &'a mut Option<CheckoutAfterpayClearpayPaymentMethodOptions>,
48        builder: CheckoutAfterpayClearpayPaymentMethodOptionsBuilder,
49    }
50
51    impl Visitor for Place<CheckoutAfterpayClearpayPaymentMethodOptions> {
52        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
53            Ok(Box::new(Builder {
54                out: &mut self.out,
55                builder: CheckoutAfterpayClearpayPaymentMethodOptionsBuilder::deser_default(),
56            }))
57        }
58    }
59
60    impl MapBuilder for CheckoutAfterpayClearpayPaymentMethodOptionsBuilder {
61        type Out = CheckoutAfterpayClearpayPaymentMethodOptions;
62        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
63            Ok(match k {
64                "capture_method" => Deserialize::begin(&mut self.capture_method),
65                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
66                _ => <dyn Visitor>::ignore(),
67            })
68        }
69
70        fn deser_default() -> Self {
71            Self {
72                capture_method: Deserialize::default(),
73                setup_future_usage: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(capture_method), Some(setup_future_usage)) =
79                (self.capture_method, self.setup_future_usage)
80            else {
81                return None;
82            };
83            Some(Self::Out { capture_method, setup_future_usage })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for CheckoutAfterpayClearpayPaymentMethodOptions {
99        type Builder = CheckoutAfterpayClearpayPaymentMethodOptionsBuilder;
100    }
101
102    impl FromValueOpt for CheckoutAfterpayClearpayPaymentMethodOptions {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = CheckoutAfterpayClearpayPaymentMethodOptionsBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
111                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};
119/// Controls when the funds will be captured from the customer's account.
120#[derive(Copy, Clone, Eq, PartialEq)]
121pub enum CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
122    Manual,
123}
124impl CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
125    pub fn as_str(self) -> &'static str {
126        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
127        match self {
128            Manual => "manual",
129        }
130    }
131}
132
133impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
134    type Err = stripe_types::StripeParseError;
135    fn from_str(s: &str) -> Result<Self, Self::Err> {
136        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
137        match s {
138            "manual" => Ok(Manual),
139            _ => Err(stripe_types::StripeParseError),
140        }
141    }
142}
143impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
144    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
145        f.write_str(self.as_str())
146    }
147}
148
149impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
150    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151        f.write_str(self.as_str())
152    }
153}
154#[cfg(feature = "serialize")]
155impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
156    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
157    where
158        S: serde::Serializer,
159    {
160        serializer.serialize_str(self.as_str())
161    }
162}
163impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
164    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
165        crate::Place::new(out)
166    }
167}
168
169impl miniserde::de::Visitor
170    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>
171{
172    fn string(&mut self, s: &str) -> miniserde::Result<()> {
173        use std::str::FromStr;
174        self.out = Some(
175            CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::from_str(s)
176                .map_err(|_| miniserde::Error)?,
177        );
178        Ok(())
179    }
180}
181
182stripe_types::impl_from_val_with_from_str!(
183    CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod
184);
185#[cfg(feature = "deserialize")]
186impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
187    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
188        use std::str::FromStr;
189        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
190        Self::from_str(&s).map_err(|_| {
191            serde::de::Error::custom(
192                "Unknown value for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod",
193            )
194        })
195    }
196}
197/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
198///
199/// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
200/// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
201///
202/// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
203///
204/// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
205#[derive(Copy, Clone, Eq, PartialEq)]
206pub enum CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
207    None,
208}
209impl CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
210    pub fn as_str(self) -> &'static str {
211        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
212        match self {
213            None => "none",
214        }
215    }
216}
217
218impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
219    type Err = stripe_types::StripeParseError;
220    fn from_str(s: &str) -> Result<Self, Self::Err> {
221        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
222        match s {
223            "none" => Ok(None),
224            _ => Err(stripe_types::StripeParseError),
225        }
226    }
227}
228impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
229    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
230        f.write_str(self.as_str())
231    }
232}
233
234impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
235    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236        f.write_str(self.as_str())
237    }
238}
239#[cfg(feature = "serialize")]
240impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
241    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
242    where
243        S: serde::Serializer,
244    {
245        serializer.serialize_str(self.as_str())
246    }
247}
248impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
249    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
250        crate::Place::new(out)
251    }
252}
253
254impl miniserde::de::Visitor
255    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>
256{
257    fn string(&mut self, s: &str) -> miniserde::Result<()> {
258        use std::str::FromStr;
259        self.out = Some(
260            CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::from_str(s)
261                .map_err(|_| miniserde::Error)?,
262        );
263        Ok(())
264    }
265}
266
267stripe_types::impl_from_val_with_from_str!(
268    CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage
269);
270#[cfg(feature = "deserialize")]
271impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
272    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
273        use std::str::FromStr;
274        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
275        Self::from_str(&s).map_err(|_| {
276            serde::de::Error::custom(
277                "Unknown value for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage",
278            )
279        })
280    }
281}