stripe_shared/
payment_intent_payment_method_options_mobilepay.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentPaymentMethodOptionsMobilepay {
5    /// Controls when the funds will be captured from the customer's account.
6    pub capture_method: Option<PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod>,
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<PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage>,
16}
17#[doc(hidden)]
18pub struct PaymentIntentPaymentMethodOptionsMobilepayBuilder {
19    capture_method: Option<Option<PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod>>,
20    setup_future_usage: Option<Option<PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage>>,
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 PaymentIntentPaymentMethodOptionsMobilepay {
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<PaymentIntentPaymentMethodOptionsMobilepay>,
47        builder: PaymentIntentPaymentMethodOptionsMobilepayBuilder,
48    }
49
50    impl Visitor for Place<PaymentIntentPaymentMethodOptionsMobilepay> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: PaymentIntentPaymentMethodOptionsMobilepayBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for PaymentIntentPaymentMethodOptionsMobilepayBuilder {
60        type Out = PaymentIntentPaymentMethodOptionsMobilepay;
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.take(), self.setup_future_usage.take())
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 PaymentIntentPaymentMethodOptionsMobilepay {
98        type Builder = PaymentIntentPaymentMethodOptionsMobilepayBuilder;
99    }
100
101    impl FromValueOpt for PaymentIntentPaymentMethodOptionsMobilepay {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PaymentIntentPaymentMethodOptionsMobilepayBuilder::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(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
122    Manual,
123    /// An unrecognized value from Stripe. Should not be used as a request parameter.
124    Unknown(String),
125}
126impl PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
127    pub fn as_str(&self) -> &str {
128        use PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod::*;
129        match self {
130            Manual => "manual",
131            Unknown(v) => v,
132        }
133    }
134}
135
136impl std::str::FromStr for PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
137    type Err = std::convert::Infallible;
138    fn from_str(s: &str) -> Result<Self, Self::Err> {
139        use PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod::*;
140        match s {
141            "manual" => Ok(Manual),
142            v => {
143                tracing::warn!(
144                    "Unknown value '{}' for enum '{}'",
145                    v,
146                    "PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod"
147                );
148                Ok(Unknown(v.to_owned()))
149            }
150        }
151    }
152}
153impl std::fmt::Display for PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
154    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155        f.write_str(self.as_str())
156    }
157}
158
159impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
160    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
161        f.write_str(self.as_str())
162    }
163}
164#[cfg(feature = "serialize")]
165impl serde::Serialize for PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
166    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
167    where
168        S: serde::Serializer,
169    {
170        serializer.serialize_str(self.as_str())
171    }
172}
173impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
174    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
175        crate::Place::new(out)
176    }
177}
178
179impl miniserde::de::Visitor
180    for crate::Place<PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod>
181{
182    fn string(&mut self, s: &str) -> miniserde::Result<()> {
183        use std::str::FromStr;
184        self.out = Some(
185            PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod::from_str(s)
186                .expect("infallible"),
187        );
188        Ok(())
189    }
190}
191
192stripe_types::impl_from_val_with_from_str!(PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod);
193#[cfg(feature = "deserialize")]
194impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsMobilepayCaptureMethod {
195    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
196        use std::str::FromStr;
197        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
198        Ok(Self::from_str(&s).expect("infallible"))
199    }
200}
201/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
202///
203/// 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.
204/// 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.
205///
206/// 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.
207///
208/// 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).
209#[derive(Clone, Eq, PartialEq)]
210#[non_exhaustive]
211pub enum PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
212    None,
213    /// An unrecognized value from Stripe. Should not be used as a request parameter.
214    Unknown(String),
215}
216impl PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
217    pub fn as_str(&self) -> &str {
218        use PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage::*;
219        match self {
220            None => "none",
221            Unknown(v) => v,
222        }
223    }
224}
225
226impl std::str::FromStr for PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
227    type Err = std::convert::Infallible;
228    fn from_str(s: &str) -> Result<Self, Self::Err> {
229        use PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage::*;
230        match s {
231            "none" => Ok(None),
232            v => {
233                tracing::warn!(
234                    "Unknown value '{}' for enum '{}'",
235                    v,
236                    "PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage"
237                );
238                Ok(Unknown(v.to_owned()))
239            }
240        }
241    }
242}
243impl std::fmt::Display for PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
244    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
245        f.write_str(self.as_str())
246    }
247}
248
249impl std::fmt::Debug for PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
250    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
251        f.write_str(self.as_str())
252    }
253}
254#[cfg(feature = "serialize")]
255impl serde::Serialize for PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
256    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
257    where
258        S: serde::Serializer,
259    {
260        serializer.serialize_str(self.as_str())
261    }
262}
263impl miniserde::Deserialize for PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
264    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
265        crate::Place::new(out)
266    }
267}
268
269impl miniserde::de::Visitor
270    for crate::Place<PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage>
271{
272    fn string(&mut self, s: &str) -> miniserde::Result<()> {
273        use std::str::FromStr;
274        self.out = Some(
275            PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage::from_str(s)
276                .expect("infallible"),
277        );
278        Ok(())
279    }
280}
281
282stripe_types::impl_from_val_with_from_str!(
283    PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage
284);
285#[cfg(feature = "deserialize")]
286impl<'de> serde::Deserialize<'de> for PaymentIntentPaymentMethodOptionsMobilepaySetupFutureUsage {
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}