Skip to main content

stripe_shared/
checkout_afterpay_clearpay_payment_method_options.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct CheckoutAfterpayClearpayPaymentMethodOptions {
6    /// Controls when the funds will be captured from the customer's account.
7    pub capture_method: Option<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>,
8    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
9    ///
10    /// 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.
11    /// 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.
12    ///
13    /// 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.
14    ///
15    /// 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).
16    pub setup_future_usage: Option<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>,
17}
18#[cfg(feature = "redact-generated-debug")]
19impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptions {
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        f.debug_struct("CheckoutAfterpayClearpayPaymentMethodOptions").finish_non_exhaustive()
22    }
23}
24#[doc(hidden)]
25pub struct CheckoutAfterpayClearpayPaymentMethodOptionsBuilder {
26    capture_method: Option<Option<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>>,
27    setup_future_usage:
28        Option<Option<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{Deserialize, Result, make_place};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for CheckoutAfterpayClearpayPaymentMethodOptions {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<CheckoutAfterpayClearpayPaymentMethodOptions>,
55        builder: CheckoutAfterpayClearpayPaymentMethodOptionsBuilder,
56    }
57
58    impl Visitor for Place<CheckoutAfterpayClearpayPaymentMethodOptions> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: CheckoutAfterpayClearpayPaymentMethodOptionsBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for CheckoutAfterpayClearpayPaymentMethodOptionsBuilder {
68        type Out = CheckoutAfterpayClearpayPaymentMethodOptions;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "capture_method" => Deserialize::begin(&mut self.capture_method),
72                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
73                _ => <dyn Visitor>::ignore(),
74            })
75        }
76
77        fn deser_default() -> Self {
78            Self { capture_method: Some(None), setup_future_usage: Some(None) }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (Some(capture_method), Some(setup_future_usage)) =
83                (self.capture_method.take(), self.setup_future_usage.take())
84            else {
85                return None;
86            };
87            Some(Self::Out { capture_method, setup_future_usage })
88        }
89    }
90
91    impl Map for Builder<'_> {
92        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93            self.builder.key(k)
94        }
95
96        fn finish(&mut self) -> Result<()> {
97            *self.out = self.builder.take_out();
98            Ok(())
99        }
100    }
101
102    impl ObjectDeser for CheckoutAfterpayClearpayPaymentMethodOptions {
103        type Builder = CheckoutAfterpayClearpayPaymentMethodOptionsBuilder;
104    }
105
106    impl FromValueOpt for CheckoutAfterpayClearpayPaymentMethodOptions {
107        fn from_value(v: Value) -> Option<Self> {
108            let Value::Object(obj) = v else {
109                return None;
110            };
111            let mut b = CheckoutAfterpayClearpayPaymentMethodOptionsBuilder::deser_default();
112            for (k, v) in obj {
113                match k.as_str() {
114                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
115                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
116                    _ => {}
117                }
118            }
119            b.take_out()
120        }
121    }
122};
123/// Controls when the funds will be captured from the customer's account.
124#[derive(Clone, Eq, PartialEq)]
125#[non_exhaustive]
126pub enum CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
127    Manual,
128    /// An unrecognized value from Stripe. Should not be used as a request parameter.
129    Unknown(String),
130}
131impl CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
132    pub fn as_str(&self) -> &str {
133        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
134        match self {
135            Manual => "manual",
136            Unknown(v) => v,
137        }
138    }
139}
140
141impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
142    type Err = std::convert::Infallible;
143    fn from_str(s: &str) -> Result<Self, Self::Err> {
144        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
145        match s {
146            "manual" => Ok(Manual),
147            v => {
148                tracing::warn!(
149                    "Unknown value '{}' for enum '{}'",
150                    v,
151                    "CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod"
152                );
153                Ok(Unknown(v.to_owned()))
154            }
155        }
156    }
157}
158impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
159    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
160        f.write_str(self.as_str())
161    }
162}
163
164#[cfg(not(feature = "redact-generated-debug"))]
165impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
166    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
167        f.write_str(self.as_str())
168    }
169}
170#[cfg(feature = "redact-generated-debug")]
171impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
172    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
173        f.debug_struct(stringify!(CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod))
174            .finish_non_exhaustive()
175    }
176}
177#[cfg(feature = "serialize")]
178impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
179    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
180    where
181        S: serde::Serializer,
182    {
183        serializer.serialize_str(self.as_str())
184    }
185}
186impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
187    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
188        crate::Place::new(out)
189    }
190}
191
192impl miniserde::de::Visitor
193    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>
194{
195    fn string(&mut self, s: &str) -> miniserde::Result<()> {
196        use std::str::FromStr;
197        self.out = Some(
198            CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::from_str(s)
199                .expect("infallible"),
200        );
201        Ok(())
202    }
203}
204
205stripe_types::impl_from_val_with_from_str!(
206    CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod
207);
208#[cfg(feature = "deserialize")]
209impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
210    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
211        use std::str::FromStr;
212        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
213        Ok(Self::from_str(&s).expect("infallible"))
214    }
215}
216/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
217///
218/// 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.
219/// 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.
220///
221/// 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.
222///
223/// 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).
224#[derive(Clone, Eq, PartialEq)]
225#[non_exhaustive]
226pub enum CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
227    None,
228    /// An unrecognized value from Stripe. Should not be used as a request parameter.
229    Unknown(String),
230}
231impl CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
232    pub fn as_str(&self) -> &str {
233        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
234        match self {
235            None => "none",
236            Unknown(v) => v,
237        }
238    }
239}
240
241impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
242    type Err = std::convert::Infallible;
243    fn from_str(s: &str) -> Result<Self, Self::Err> {
244        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
245        match s {
246            "none" => Ok(None),
247            v => {
248                tracing::warn!(
249                    "Unknown value '{}' for enum '{}'",
250                    v,
251                    "CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage"
252                );
253                Ok(Unknown(v.to_owned()))
254            }
255        }
256    }
257}
258impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
259    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
260        f.write_str(self.as_str())
261    }
262}
263
264#[cfg(not(feature = "redact-generated-debug"))]
265impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
266    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
267        f.write_str(self.as_str())
268    }
269}
270#[cfg(feature = "redact-generated-debug")]
271impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
272    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
273        f.debug_struct(stringify!(CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage))
274            .finish_non_exhaustive()
275    }
276}
277#[cfg(feature = "serialize")]
278impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
279    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
280    where
281        S: serde::Serializer,
282    {
283        serializer.serialize_str(self.as_str())
284    }
285}
286impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
287    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
288        crate::Place::new(out)
289    }
290}
291
292impl miniserde::de::Visitor
293    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>
294{
295    fn string(&mut self, s: &str) -> miniserde::Result<()> {
296        use std::str::FromStr;
297        self.out = Some(
298            CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::from_str(s)
299                .expect("infallible"),
300        );
301        Ok(())
302    }
303}
304
305stripe_types::impl_from_val_with_from_str!(
306    CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage
307);
308#[cfg(feature = "deserialize")]
309impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
310    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
311        use std::str::FromStr;
312        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
313        Ok(Self::from_str(&s).expect("infallible"))
314    }
315}