Skip to main content

stripe_shared/
payment_method_options_mb_way.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct PaymentMethodOptionsMbWay {
6    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
7    ///
8    /// 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.
9    /// 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.
10    ///
11    /// 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.
12    ///
13    /// 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).
14    pub setup_future_usage: Option<PaymentMethodOptionsMbWaySetupFutureUsage>,
15}
16#[cfg(feature = "redact-generated-debug")]
17impl std::fmt::Debug for PaymentMethodOptionsMbWay {
18    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19        f.debug_struct("PaymentMethodOptionsMbWay").finish_non_exhaustive()
20    }
21}
22#[doc(hidden)]
23pub struct PaymentMethodOptionsMbWayBuilder {
24    setup_future_usage: Option<Option<PaymentMethodOptionsMbWaySetupFutureUsage>>,
25}
26
27#[allow(
28    unused_variables,
29    irrefutable_let_patterns,
30    clippy::let_unit_value,
31    clippy::match_single_binding,
32    clippy::single_match
33)]
34const _: () = {
35    use miniserde::de::{Map, Visitor};
36    use miniserde::json::Value;
37    use miniserde::{Deserialize, Result, make_place};
38    use stripe_types::miniserde_helpers::FromValueOpt;
39    use stripe_types::{MapBuilder, ObjectDeser};
40
41    make_place!(Place);
42
43    impl Deserialize for PaymentMethodOptionsMbWay {
44        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
45            Place::new(out)
46        }
47    }
48
49    struct Builder<'a> {
50        out: &'a mut Option<PaymentMethodOptionsMbWay>,
51        builder: PaymentMethodOptionsMbWayBuilder,
52    }
53
54    impl Visitor for Place<PaymentMethodOptionsMbWay> {
55        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
56            Ok(Box::new(Builder {
57                out: &mut self.out,
58                builder: PaymentMethodOptionsMbWayBuilder::deser_default(),
59            }))
60        }
61    }
62
63    impl MapBuilder for PaymentMethodOptionsMbWayBuilder {
64        type Out = PaymentMethodOptionsMbWay;
65        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
66            Ok(match k {
67                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self { setup_future_usage: Deserialize::default() }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(setup_future_usage),) = (self.setup_future_usage.take(),) else {
78                return None;
79            };
80            Some(Self::Out { setup_future_usage })
81        }
82    }
83
84    impl Map for Builder<'_> {
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            self.builder.key(k)
87        }
88
89        fn finish(&mut self) -> Result<()> {
90            *self.out = self.builder.take_out();
91            Ok(())
92        }
93    }
94
95    impl ObjectDeser for PaymentMethodOptionsMbWay {
96        type Builder = PaymentMethodOptionsMbWayBuilder;
97    }
98
99    impl FromValueOpt for PaymentMethodOptionsMbWay {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = PaymentMethodOptionsMbWayBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
108                    _ => {}
109                }
110            }
111            b.take_out()
112        }
113    }
114};
115/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
116///
117/// 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.
118/// 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.
119///
120/// 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.
121///
122/// 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).
123#[derive(Clone, Eq, PartialEq)]
124#[non_exhaustive]
125pub enum PaymentMethodOptionsMbWaySetupFutureUsage {
126    None,
127    /// An unrecognized value from Stripe. Should not be used as a request parameter.
128    Unknown(String),
129}
130impl PaymentMethodOptionsMbWaySetupFutureUsage {
131    pub fn as_str(&self) -> &str {
132        use PaymentMethodOptionsMbWaySetupFutureUsage::*;
133        match self {
134            None => "none",
135            Unknown(v) => v,
136        }
137    }
138}
139
140impl std::str::FromStr for PaymentMethodOptionsMbWaySetupFutureUsage {
141    type Err = std::convert::Infallible;
142    fn from_str(s: &str) -> Result<Self, Self::Err> {
143        use PaymentMethodOptionsMbWaySetupFutureUsage::*;
144        match s {
145            "none" => Ok(None),
146            v => {
147                tracing::warn!(
148                    "Unknown value '{}' for enum '{}'",
149                    v,
150                    "PaymentMethodOptionsMbWaySetupFutureUsage"
151                );
152                Ok(Unknown(v.to_owned()))
153            }
154        }
155    }
156}
157impl std::fmt::Display for PaymentMethodOptionsMbWaySetupFutureUsage {
158    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159        f.write_str(self.as_str())
160    }
161}
162
163#[cfg(not(feature = "redact-generated-debug"))]
164impl std::fmt::Debug for PaymentMethodOptionsMbWaySetupFutureUsage {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169#[cfg(feature = "redact-generated-debug")]
170impl std::fmt::Debug for PaymentMethodOptionsMbWaySetupFutureUsage {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.debug_struct(stringify!(PaymentMethodOptionsMbWaySetupFutureUsage))
173            .finish_non_exhaustive()
174    }
175}
176#[cfg(feature = "serialize")]
177impl serde::Serialize for PaymentMethodOptionsMbWaySetupFutureUsage {
178    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
179    where
180        S: serde::Serializer,
181    {
182        serializer.serialize_str(self.as_str())
183    }
184}
185impl miniserde::Deserialize for PaymentMethodOptionsMbWaySetupFutureUsage {
186    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
187        crate::Place::new(out)
188    }
189}
190
191impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsMbWaySetupFutureUsage> {
192    fn string(&mut self, s: &str) -> miniserde::Result<()> {
193        use std::str::FromStr;
194        self.out =
195            Some(PaymentMethodOptionsMbWaySetupFutureUsage::from_str(s).expect("infallible"));
196        Ok(())
197    }
198}
199
200stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsMbWaySetupFutureUsage);
201#[cfg(feature = "deserialize")]
202impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsMbWaySetupFutureUsage {
203    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
204        use std::str::FromStr;
205        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
206        Ok(Self::from_str(&s).expect("infallible"))
207    }
208}