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
67                _ => <dyn Visitor>::ignore(),
68            })
69        }
70
71        fn deser_default() -> Self {
72            Self {
73                capture_method: Deserialize::default(),
74                setup_future_usage: Deserialize::default(),
75            }
76        }
77
78        fn take_out(&mut self) -> Option<Self::Out> {
79            let (Some(capture_method), Some(setup_future_usage)) =
80                (self.capture_method, self.setup_future_usage)
81            else {
82                return None;
83            };
84            Some(Self::Out { capture_method, setup_future_usage })
85        }
86    }
87
88    impl Map for Builder<'_> {
89        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
90            self.builder.key(k)
91        }
92
93        fn finish(&mut self) -> Result<()> {
94            *self.out = self.builder.take_out();
95            Ok(())
96        }
97    }
98
99    impl ObjectDeser for CheckoutAfterpayClearpayPaymentMethodOptions {
100        type Builder = CheckoutAfterpayClearpayPaymentMethodOptionsBuilder;
101    }
102
103    impl FromValueOpt for CheckoutAfterpayClearpayPaymentMethodOptions {
104        fn from_value(v: Value) -> Option<Self> {
105            let Value::Object(obj) = v else {
106                return None;
107            };
108            let mut b = CheckoutAfterpayClearpayPaymentMethodOptionsBuilder::deser_default();
109            for (k, v) in obj {
110                match k.as_str() {
111                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
112                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
113
114                    _ => {}
115                }
116            }
117            b.take_out()
118        }
119    }
120};
121/// Controls when the funds will be captured from the customer's account.
122#[derive(Copy, Clone, Eq, PartialEq)]
123pub enum CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
124    Manual,
125}
126impl CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
127    pub fn as_str(self) -> &'static str {
128        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
129        match self {
130            Manual => "manual",
131        }
132    }
133}
134
135impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
136    type Err = stripe_types::StripeParseError;
137    fn from_str(s: &str) -> Result<Self, Self::Err> {
138        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
139        match s {
140            "manual" => Ok(Manual),
141            _ => Err(stripe_types::StripeParseError),
142        }
143    }
144}
145impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150
151impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
152    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156#[cfg(feature = "serialize")]
157impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
158    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
159    where
160        S: serde::Serializer,
161    {
162        serializer.serialize_str(self.as_str())
163    }
164}
165impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
166    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
167        crate::Place::new(out)
168    }
169}
170
171impl miniserde::de::Visitor
172    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>
173{
174    fn string(&mut self, s: &str) -> miniserde::Result<()> {
175        use std::str::FromStr;
176        self.out = Some(
177            CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::from_str(s)
178                .map_err(|_| miniserde::Error)?,
179        );
180        Ok(())
181    }
182}
183
184stripe_types::impl_from_val_with_from_str!(
185    CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod
186);
187#[cfg(feature = "deserialize")]
188impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
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        Self::from_str(&s).map_err(|_| {
193            serde::de::Error::custom(
194                "Unknown value for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod",
195            )
196        })
197    }
198}
199/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
200///
201/// 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.
202/// 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.
203///
204/// 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.
205///
206/// 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).
207#[derive(Copy, Clone, Eq, PartialEq)]
208pub enum CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
209    None,
210}
211impl CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
212    pub fn as_str(self) -> &'static str {
213        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
214        match self {
215            None => "none",
216        }
217    }
218}
219
220impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
221    type Err = stripe_types::StripeParseError;
222    fn from_str(s: &str) -> Result<Self, Self::Err> {
223        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
224        match s {
225            "none" => Ok(None),
226            _ => Err(stripe_types::StripeParseError),
227        }
228    }
229}
230impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
231    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232        f.write_str(self.as_str())
233    }
234}
235
236impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
237    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
238        f.write_str(self.as_str())
239    }
240}
241#[cfg(feature = "serialize")]
242impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
243    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
244    where
245        S: serde::Serializer,
246    {
247        serializer.serialize_str(self.as_str())
248    }
249}
250impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
251    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
252        crate::Place::new(out)
253    }
254}
255
256impl miniserde::de::Visitor
257    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>
258{
259    fn string(&mut self, s: &str) -> miniserde::Result<()> {
260        use std::str::FromStr;
261        self.out = Some(
262            CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::from_str(s)
263                .map_err(|_| miniserde::Error)?,
264        );
265        Ok(())
266    }
267}
268
269stripe_types::impl_from_val_with_from_str!(
270    CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage
271);
272#[cfg(feature = "deserialize")]
273impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
274    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
275        use std::str::FromStr;
276        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
277        Self::from_str(&s).map_err(|_| {
278            serde::de::Error::custom(
279                "Unknown value for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage",
280            )
281        })
282    }
283}