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