Skip to main content

stripe_shared/
payment_method_options_bancontact.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 PaymentMethodOptionsBancontact {
6    /// Preferred language of the Bancontact authorization page that the customer is redirected to.
7    pub preferred_language: PaymentMethodOptionsBancontactPreferredLanguage,
8    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
9    ///
10    /// 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.
11    /// 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.
12    ///
13    /// 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.
14    ///
15    /// 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).
16    pub setup_future_usage: Option<PaymentMethodOptionsBancontactSetupFutureUsage>,
17}
18#[cfg(feature = "redact-generated-debug")]
19impl std::fmt::Debug for PaymentMethodOptionsBancontact {
20    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
21        f.debug_struct("PaymentMethodOptionsBancontact").finish_non_exhaustive()
22    }
23}
24#[doc(hidden)]
25pub struct PaymentMethodOptionsBancontactBuilder {
26    preferred_language: Option<PaymentMethodOptionsBancontactPreferredLanguage>,
27    setup_future_usage: Option<Option<PaymentMethodOptionsBancontactSetupFutureUsage>>,
28}
29
30#[allow(
31    unused_variables,
32    irrefutable_let_patterns,
33    clippy::let_unit_value,
34    clippy::match_single_binding,
35    clippy::single_match
36)]
37const _: () = {
38    use miniserde::de::{Map, Visitor};
39    use miniserde::json::Value;
40    use miniserde::{Deserialize, Result, make_place};
41    use stripe_types::miniserde_helpers::FromValueOpt;
42    use stripe_types::{MapBuilder, ObjectDeser};
43
44    make_place!(Place);
45
46    impl Deserialize for PaymentMethodOptionsBancontact {
47        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
48            Place::new(out)
49        }
50    }
51
52    struct Builder<'a> {
53        out: &'a mut Option<PaymentMethodOptionsBancontact>,
54        builder: PaymentMethodOptionsBancontactBuilder,
55    }
56
57    impl Visitor for Place<PaymentMethodOptionsBancontact> {
58        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
59            Ok(Box::new(Builder {
60                out: &mut self.out,
61                builder: PaymentMethodOptionsBancontactBuilder::deser_default(),
62            }))
63        }
64    }
65
66    impl MapBuilder for PaymentMethodOptionsBancontactBuilder {
67        type Out = PaymentMethodOptionsBancontact;
68        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
69            Ok(match k {
70                "preferred_language" => Deserialize::begin(&mut self.preferred_language),
71                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
72                _ => <dyn Visitor>::ignore(),
73            })
74        }
75
76        fn deser_default() -> Self {
77            Self { preferred_language: None, setup_future_usage: Some(None) }
78        }
79
80        fn take_out(&mut self) -> Option<Self::Out> {
81            let (Some(preferred_language), Some(setup_future_usage)) =
82                (self.preferred_language.take(), self.setup_future_usage.take())
83            else {
84                return None;
85            };
86            Some(Self::Out { preferred_language, setup_future_usage })
87        }
88    }
89
90    impl Map for Builder<'_> {
91        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
92            self.builder.key(k)
93        }
94
95        fn finish(&mut self) -> Result<()> {
96            *self.out = self.builder.take_out();
97            Ok(())
98        }
99    }
100
101    impl ObjectDeser for PaymentMethodOptionsBancontact {
102        type Builder = PaymentMethodOptionsBancontactBuilder;
103    }
104
105    impl FromValueOpt for PaymentMethodOptionsBancontact {
106        fn from_value(v: Value) -> Option<Self> {
107            let Value::Object(obj) = v else {
108                return None;
109            };
110            let mut b = PaymentMethodOptionsBancontactBuilder::deser_default();
111            for (k, v) in obj {
112                match k.as_str() {
113                    "preferred_language" => b.preferred_language = FromValueOpt::from_value(v),
114                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
115                    _ => {}
116                }
117            }
118            b.take_out()
119        }
120    }
121};
122/// Preferred language of the Bancontact authorization page that the customer is redirected to.
123#[derive(Clone, Eq, PartialEq)]
124#[non_exhaustive]
125pub enum PaymentMethodOptionsBancontactPreferredLanguage {
126    De,
127    En,
128    Fr,
129    Nl,
130    /// An unrecognized value from Stripe. Should not be used as a request parameter.
131    Unknown(String),
132}
133impl PaymentMethodOptionsBancontactPreferredLanguage {
134    pub fn as_str(&self) -> &str {
135        use PaymentMethodOptionsBancontactPreferredLanguage::*;
136        match self {
137            De => "de",
138            En => "en",
139            Fr => "fr",
140            Nl => "nl",
141            Unknown(v) => v,
142        }
143    }
144}
145
146impl std::str::FromStr for PaymentMethodOptionsBancontactPreferredLanguage {
147    type Err = std::convert::Infallible;
148    fn from_str(s: &str) -> Result<Self, Self::Err> {
149        use PaymentMethodOptionsBancontactPreferredLanguage::*;
150        match s {
151            "de" => Ok(De),
152            "en" => Ok(En),
153            "fr" => Ok(Fr),
154            "nl" => Ok(Nl),
155            v => {
156                tracing::warn!(
157                    "Unknown value '{}' for enum '{}'",
158                    v,
159                    "PaymentMethodOptionsBancontactPreferredLanguage"
160                );
161                Ok(Unknown(v.to_owned()))
162            }
163        }
164    }
165}
166impl std::fmt::Display for PaymentMethodOptionsBancontactPreferredLanguage {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171
172#[cfg(not(feature = "redact-generated-debug"))]
173impl std::fmt::Debug for PaymentMethodOptionsBancontactPreferredLanguage {
174    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
175        f.write_str(self.as_str())
176    }
177}
178#[cfg(feature = "redact-generated-debug")]
179impl std::fmt::Debug for PaymentMethodOptionsBancontactPreferredLanguage {
180    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
181        f.debug_struct(stringify!(PaymentMethodOptionsBancontactPreferredLanguage))
182            .finish_non_exhaustive()
183    }
184}
185#[cfg(feature = "serialize")]
186impl serde::Serialize for PaymentMethodOptionsBancontactPreferredLanguage {
187    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
188    where
189        S: serde::Serializer,
190    {
191        serializer.serialize_str(self.as_str())
192    }
193}
194impl miniserde::Deserialize for PaymentMethodOptionsBancontactPreferredLanguage {
195    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
196        crate::Place::new(out)
197    }
198}
199
200impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsBancontactPreferredLanguage> {
201    fn string(&mut self, s: &str) -> miniserde::Result<()> {
202        use std::str::FromStr;
203        self.out =
204            Some(PaymentMethodOptionsBancontactPreferredLanguage::from_str(s).expect("infallible"));
205        Ok(())
206    }
207}
208
209stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsBancontactPreferredLanguage);
210#[cfg(feature = "deserialize")]
211impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsBancontactPreferredLanguage {
212    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
213        use std::str::FromStr;
214        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
215        Ok(Self::from_str(&s).expect("infallible"))
216    }
217}
218/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
219///
220/// 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.
221/// 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.
222///
223/// 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.
224///
225/// 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).
226#[derive(Clone, Eq, PartialEq)]
227#[non_exhaustive]
228pub enum PaymentMethodOptionsBancontactSetupFutureUsage {
229    None,
230    OffSession,
231    /// An unrecognized value from Stripe. Should not be used as a request parameter.
232    Unknown(String),
233}
234impl PaymentMethodOptionsBancontactSetupFutureUsage {
235    pub fn as_str(&self) -> &str {
236        use PaymentMethodOptionsBancontactSetupFutureUsage::*;
237        match self {
238            None => "none",
239            OffSession => "off_session",
240            Unknown(v) => v,
241        }
242    }
243}
244
245impl std::str::FromStr for PaymentMethodOptionsBancontactSetupFutureUsage {
246    type Err = std::convert::Infallible;
247    fn from_str(s: &str) -> Result<Self, Self::Err> {
248        use PaymentMethodOptionsBancontactSetupFutureUsage::*;
249        match s {
250            "none" => Ok(None),
251            "off_session" => Ok(OffSession),
252            v => {
253                tracing::warn!(
254                    "Unknown value '{}' for enum '{}'",
255                    v,
256                    "PaymentMethodOptionsBancontactSetupFutureUsage"
257                );
258                Ok(Unknown(v.to_owned()))
259            }
260        }
261    }
262}
263impl std::fmt::Display for PaymentMethodOptionsBancontactSetupFutureUsage {
264    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
265        f.write_str(self.as_str())
266    }
267}
268
269#[cfg(not(feature = "redact-generated-debug"))]
270impl std::fmt::Debug for PaymentMethodOptionsBancontactSetupFutureUsage {
271    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
272        f.write_str(self.as_str())
273    }
274}
275#[cfg(feature = "redact-generated-debug")]
276impl std::fmt::Debug for PaymentMethodOptionsBancontactSetupFutureUsage {
277    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
278        f.debug_struct(stringify!(PaymentMethodOptionsBancontactSetupFutureUsage))
279            .finish_non_exhaustive()
280    }
281}
282#[cfg(feature = "serialize")]
283impl serde::Serialize for PaymentMethodOptionsBancontactSetupFutureUsage {
284    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
285    where
286        S: serde::Serializer,
287    {
288        serializer.serialize_str(self.as_str())
289    }
290}
291impl miniserde::Deserialize for PaymentMethodOptionsBancontactSetupFutureUsage {
292    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
293        crate::Place::new(out)
294    }
295}
296
297impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsBancontactSetupFutureUsage> {
298    fn string(&mut self, s: &str) -> miniserde::Result<()> {
299        use std::str::FromStr;
300        self.out =
301            Some(PaymentMethodOptionsBancontactSetupFutureUsage::from_str(s).expect("infallible"));
302        Ok(())
303    }
304}
305
306stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsBancontactSetupFutureUsage);
307#[cfg(feature = "deserialize")]
308impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsBancontactSetupFutureUsage {
309    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
310        use std::str::FromStr;
311        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
312        Ok(Self::from_str(&s).expect("infallible"))
313    }
314}