stripe_shared/
payment_method_options_afterpay_clearpay.rs

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