stripe_shared/
payment_method_options_sofort.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsSofort {
5    /// Preferred language of the SOFORT authorization page that the customer is redirected to.
6    pub preferred_language: Option<PaymentMethodOptionsSofortPreferredLanguage>,
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<PaymentMethodOptionsSofortSetupFutureUsage>,
16}
17#[doc(hidden)]
18pub struct PaymentMethodOptionsSofortBuilder {
19    preferred_language: Option<Option<PaymentMethodOptionsSofortPreferredLanguage>>,
20    setup_future_usage: Option<Option<PaymentMethodOptionsSofortSetupFutureUsage>>,
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 PaymentMethodOptionsSofort {
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<PaymentMethodOptionsSofort>,
47        builder: PaymentMethodOptionsSofortBuilder,
48    }
49
50    impl Visitor for Place<PaymentMethodOptionsSofort> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: PaymentMethodOptionsSofortBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for PaymentMethodOptionsSofortBuilder {
60        type Out = PaymentMethodOptionsSofort;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "preferred_language" => Deserialize::begin(&mut self.preferred_language),
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                preferred_language: Deserialize::default(),
72                setup_future_usage: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(preferred_language), Some(setup_future_usage)) =
78                (self.preferred_language, self.setup_future_usage)
79            else {
80                return None;
81            };
82            Some(Self::Out { preferred_language, 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 PaymentMethodOptionsSofort {
98        type Builder = PaymentMethodOptionsSofortBuilder;
99    }
100
101    impl FromValueOpt for PaymentMethodOptionsSofort {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PaymentMethodOptionsSofortBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "preferred_language" => b.preferred_language = 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/// Preferred language of the SOFORT authorization page that the customer is redirected to.
119#[derive(Copy, Clone, Eq, PartialEq)]
120pub enum PaymentMethodOptionsSofortPreferredLanguage {
121    De,
122    En,
123    Es,
124    Fr,
125    It,
126    Nl,
127    Pl,
128}
129impl PaymentMethodOptionsSofortPreferredLanguage {
130    pub fn as_str(self) -> &'static str {
131        use PaymentMethodOptionsSofortPreferredLanguage::*;
132        match self {
133            De => "de",
134            En => "en",
135            Es => "es",
136            Fr => "fr",
137            It => "it",
138            Nl => "nl",
139            Pl => "pl",
140        }
141    }
142}
143
144impl std::str::FromStr for PaymentMethodOptionsSofortPreferredLanguage {
145    type Err = stripe_types::StripeParseError;
146    fn from_str(s: &str) -> Result<Self, Self::Err> {
147        use PaymentMethodOptionsSofortPreferredLanguage::*;
148        match s {
149            "de" => Ok(De),
150            "en" => Ok(En),
151            "es" => Ok(Es),
152            "fr" => Ok(Fr),
153            "it" => Ok(It),
154            "nl" => Ok(Nl),
155            "pl" => Ok(Pl),
156            _ => Err(stripe_types::StripeParseError),
157        }
158    }
159}
160impl std::fmt::Display for PaymentMethodOptionsSofortPreferredLanguage {
161    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162        f.write_str(self.as_str())
163    }
164}
165
166impl std::fmt::Debug for PaymentMethodOptionsSofortPreferredLanguage {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171#[cfg(feature = "serialize")]
172impl serde::Serialize for PaymentMethodOptionsSofortPreferredLanguage {
173    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
174    where
175        S: serde::Serializer,
176    {
177        serializer.serialize_str(self.as_str())
178    }
179}
180impl miniserde::Deserialize for PaymentMethodOptionsSofortPreferredLanguage {
181    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
182        crate::Place::new(out)
183    }
184}
185
186impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsSofortPreferredLanguage> {
187    fn string(&mut self, s: &str) -> miniserde::Result<()> {
188        use std::str::FromStr;
189        self.out = Some(
190            PaymentMethodOptionsSofortPreferredLanguage::from_str(s)
191                .map_err(|_| miniserde::Error)?,
192        );
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsSofortPreferredLanguage);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsSofortPreferredLanguage {
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        Self::from_str(&s).map_err(|_| {
204            serde::de::Error::custom(
205                "Unknown value for PaymentMethodOptionsSofortPreferredLanguage",
206            )
207        })
208    }
209}
210/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
211///
212/// 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.
213/// 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.
214///
215/// 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.
216///
217/// 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).
218#[derive(Copy, Clone, Eq, PartialEq)]
219pub enum PaymentMethodOptionsSofortSetupFutureUsage {
220    None,
221    OffSession,
222}
223impl PaymentMethodOptionsSofortSetupFutureUsage {
224    pub fn as_str(self) -> &'static str {
225        use PaymentMethodOptionsSofortSetupFutureUsage::*;
226        match self {
227            None => "none",
228            OffSession => "off_session",
229        }
230    }
231}
232
233impl std::str::FromStr for PaymentMethodOptionsSofortSetupFutureUsage {
234    type Err = stripe_types::StripeParseError;
235    fn from_str(s: &str) -> Result<Self, Self::Err> {
236        use PaymentMethodOptionsSofortSetupFutureUsage::*;
237        match s {
238            "none" => Ok(None),
239            "off_session" => Ok(OffSession),
240            _ => Err(stripe_types::StripeParseError),
241        }
242    }
243}
244impl std::fmt::Display for PaymentMethodOptionsSofortSetupFutureUsage {
245    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
246        f.write_str(self.as_str())
247    }
248}
249
250impl std::fmt::Debug for PaymentMethodOptionsSofortSetupFutureUsage {
251    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
252        f.write_str(self.as_str())
253    }
254}
255#[cfg(feature = "serialize")]
256impl serde::Serialize for PaymentMethodOptionsSofortSetupFutureUsage {
257    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
258    where
259        S: serde::Serializer,
260    {
261        serializer.serialize_str(self.as_str())
262    }
263}
264impl miniserde::Deserialize for PaymentMethodOptionsSofortSetupFutureUsage {
265    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
266        crate::Place::new(out)
267    }
268}
269
270impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsSofortSetupFutureUsage> {
271    fn string(&mut self, s: &str) -> miniserde::Result<()> {
272        use std::str::FromStr;
273        self.out = Some(
274            PaymentMethodOptionsSofortSetupFutureUsage::from_str(s)
275                .map_err(|_| miniserde::Error)?,
276        );
277        Ok(())
278    }
279}
280
281stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsSofortSetupFutureUsage);
282#[cfg(feature = "deserialize")]
283impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsSofortSetupFutureUsage {
284    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
285        use std::str::FromStr;
286        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
287        Self::from_str(&s).map_err(|_| {
288            serde::de::Error::custom("Unknown value for PaymentMethodOptionsSofortSetupFutureUsage")
289        })
290    }
291}