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