stripe_shared/
checkout_afterpay_clearpay_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 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.take(), self.setup_future_usage.take())
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(Clone, Eq, PartialEq)]
121#[non_exhaustive]
122pub enum CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
123    Manual,
124    /// An unrecognized value from Stripe. Should not be used as a request parameter.
125    Unknown(String),
126}
127impl CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
128    pub fn as_str(&self) -> &str {
129        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
130        match self {
131            Manual => "manual",
132            Unknown(v) => v,
133        }
134    }
135}
136
137impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
138    type Err = std::convert::Infallible;
139    fn from_str(s: &str) -> Result<Self, Self::Err> {
140        use CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::*;
141        match s {
142            "manual" => Ok(Manual),
143            v => {
144                tracing::warn!(
145                    "Unknown value '{}' for enum '{}'",
146                    v,
147                    "CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod"
148                );
149                Ok(Unknown(v.to_owned()))
150            }
151        }
152    }
153}
154impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
155    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156        f.write_str(self.as_str())
157    }
158}
159
160impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
161    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162        f.write_str(self.as_str())
163    }
164}
165#[cfg(feature = "serialize")]
166impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
167    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
168    where
169        S: serde::Serializer,
170    {
171        serializer.serialize_str(self.as_str())
172    }
173}
174impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
175    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
176        crate::Place::new(out)
177    }
178}
179
180impl miniserde::de::Visitor
181    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod>
182{
183    fn string(&mut self, s: &str) -> miniserde::Result<()> {
184        use std::str::FromStr;
185        self.out = Some(
186            CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod::from_str(s)
187                .expect("infallible"),
188        );
189        Ok(())
190    }
191}
192
193stripe_types::impl_from_val_with_from_str!(
194    CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod
195);
196#[cfg(feature = "deserialize")]
197impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsCaptureMethod {
198    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199        use std::str::FromStr;
200        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201        Ok(Self::from_str(&s).expect("infallible"))
202    }
203}
204/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
205///
206/// 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.
207/// 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.
208///
209/// 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.
210///
211/// 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).
212#[derive(Clone, Eq, PartialEq)]
213#[non_exhaustive]
214pub enum CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
215    None,
216    /// An unrecognized value from Stripe. Should not be used as a request parameter.
217    Unknown(String),
218}
219impl CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
220    pub fn as_str(&self) -> &str {
221        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
222        match self {
223            None => "none",
224            Unknown(v) => v,
225        }
226    }
227}
228
229impl std::str::FromStr for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
230    type Err = std::convert::Infallible;
231    fn from_str(s: &str) -> Result<Self, Self::Err> {
232        use CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::*;
233        match s {
234            "none" => Ok(None),
235            v => {
236                tracing::warn!(
237                    "Unknown value '{}' for enum '{}'",
238                    v,
239                    "CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage"
240                );
241                Ok(Unknown(v.to_owned()))
242            }
243        }
244    }
245}
246impl std::fmt::Display for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
247    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
248        f.write_str(self.as_str())
249    }
250}
251
252impl std::fmt::Debug for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
253    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
254        f.write_str(self.as_str())
255    }
256}
257#[cfg(feature = "serialize")]
258impl serde::Serialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
259    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
260    where
261        S: serde::Serializer,
262    {
263        serializer.serialize_str(self.as_str())
264    }
265}
266impl miniserde::Deserialize for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
267    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
268        crate::Place::new(out)
269    }
270}
271
272impl miniserde::de::Visitor
273    for crate::Place<CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage>
274{
275    fn string(&mut self, s: &str) -> miniserde::Result<()> {
276        use std::str::FromStr;
277        self.out = Some(
278            CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage::from_str(s)
279                .expect("infallible"),
280        );
281        Ok(())
282    }
283}
284
285stripe_types::impl_from_val_with_from_str!(
286    CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage
287);
288#[cfg(feature = "deserialize")]
289impl<'de> serde::Deserialize<'de> for CheckoutAfterpayClearpayPaymentMethodOptionsSetupFutureUsage {
290    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
291        use std::str::FromStr;
292        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
293        Ok(Self::from_str(&s).expect("infallible"))
294    }
295}