stripe_shared/
checkout_mobilepay_payment_method_options.rs

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