stripe_shared/
subscription_payment_method_options_card.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionPaymentMethodOptionsCard {
5    pub mandate_options: Option<stripe_shared::InvoiceMandateOptionsCard>,
6    /// Selected network to process this Subscription on.
7    /// Depends on the available networks of the card attached to the Subscription.
8    /// Can be only set confirm-time.
9    pub network: Option<SubscriptionPaymentMethodOptionsCardNetwork>,
10    /// We strongly recommend that you rely on our SCA Engine to automatically prompt your customers for authentication based on risk level and [other requirements](https://stripe.com/docs/strong-customer-authentication).
11    /// However, if you wish to request 3D Secure based on logic from your own fraud engine, provide this option.
12    /// Read our guide on [manually requesting 3D Secure](https://stripe.com/docs/payments/3d-secure/authentication-flow#manual-three-ds) for more information on how this configuration interacts with Radar and our SCA Engine.
13    pub request_three_d_secure: Option<SubscriptionPaymentMethodOptionsCardRequestThreeDSecure>,
14}
15#[doc(hidden)]
16pub struct SubscriptionPaymentMethodOptionsCardBuilder {
17    mandate_options: Option<Option<stripe_shared::InvoiceMandateOptionsCard>>,
18    network: Option<Option<SubscriptionPaymentMethodOptionsCardNetwork>>,
19    request_three_d_secure: Option<Option<SubscriptionPaymentMethodOptionsCardRequestThreeDSecure>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for SubscriptionPaymentMethodOptionsCard {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<SubscriptionPaymentMethodOptionsCard>,
46        builder: SubscriptionPaymentMethodOptionsCardBuilder,
47    }
48
49    impl Visitor for Place<SubscriptionPaymentMethodOptionsCard> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: SubscriptionPaymentMethodOptionsCardBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for SubscriptionPaymentMethodOptionsCardBuilder {
59        type Out = SubscriptionPaymentMethodOptionsCard;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "mandate_options" => Deserialize::begin(&mut self.mandate_options),
63                "network" => Deserialize::begin(&mut self.network),
64                "request_three_d_secure" => Deserialize::begin(&mut self.request_three_d_secure),
65                _ => <dyn Visitor>::ignore(),
66            })
67        }
68
69        fn deser_default() -> Self {
70            Self {
71                mandate_options: Deserialize::default(),
72                network: Deserialize::default(),
73                request_three_d_secure: Deserialize::default(),
74            }
75        }
76
77        fn take_out(&mut self) -> Option<Self::Out> {
78            let (Some(mandate_options), Some(network), Some(request_three_d_secure)) =
79                (self.mandate_options.take(), self.network, self.request_three_d_secure)
80            else {
81                return None;
82            };
83            Some(Self::Out { mandate_options, network, request_three_d_secure })
84        }
85    }
86
87    impl Map for Builder<'_> {
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            self.builder.key(k)
90        }
91
92        fn finish(&mut self) -> Result<()> {
93            *self.out = self.builder.take_out();
94            Ok(())
95        }
96    }
97
98    impl ObjectDeser for SubscriptionPaymentMethodOptionsCard {
99        type Builder = SubscriptionPaymentMethodOptionsCardBuilder;
100    }
101
102    impl FromValueOpt for SubscriptionPaymentMethodOptionsCard {
103        fn from_value(v: Value) -> Option<Self> {
104            let Value::Object(obj) = v else {
105                return None;
106            };
107            let mut b = SubscriptionPaymentMethodOptionsCardBuilder::deser_default();
108            for (k, v) in obj {
109                match k.as_str() {
110                    "mandate_options" => b.mandate_options = FromValueOpt::from_value(v),
111                    "network" => b.network = FromValueOpt::from_value(v),
112                    "request_three_d_secure" => {
113                        b.request_three_d_secure = FromValueOpt::from_value(v)
114                    }
115                    _ => {}
116                }
117            }
118            b.take_out()
119        }
120    }
121};
122/// Selected network to process this Subscription on.
123/// Depends on the available networks of the card attached to the Subscription.
124/// Can be only set confirm-time.
125#[derive(Copy, Clone, Eq, PartialEq)]
126pub enum SubscriptionPaymentMethodOptionsCardNetwork {
127    Amex,
128    CartesBancaires,
129    Diners,
130    Discover,
131    EftposAu,
132    Girocard,
133    Interac,
134    Jcb,
135    Link,
136    Mastercard,
137    Unionpay,
138    Unknown,
139    Visa,
140}
141impl SubscriptionPaymentMethodOptionsCardNetwork {
142    pub fn as_str(self) -> &'static str {
143        use SubscriptionPaymentMethodOptionsCardNetwork::*;
144        match self {
145            Amex => "amex",
146            CartesBancaires => "cartes_bancaires",
147            Diners => "diners",
148            Discover => "discover",
149            EftposAu => "eftpos_au",
150            Girocard => "girocard",
151            Interac => "interac",
152            Jcb => "jcb",
153            Link => "link",
154            Mastercard => "mastercard",
155            Unionpay => "unionpay",
156            Unknown => "unknown",
157            Visa => "visa",
158        }
159    }
160}
161
162impl std::str::FromStr for SubscriptionPaymentMethodOptionsCardNetwork {
163    type Err = stripe_types::StripeParseError;
164    fn from_str(s: &str) -> Result<Self, Self::Err> {
165        use SubscriptionPaymentMethodOptionsCardNetwork::*;
166        match s {
167            "amex" => Ok(Amex),
168            "cartes_bancaires" => Ok(CartesBancaires),
169            "diners" => Ok(Diners),
170            "discover" => Ok(Discover),
171            "eftpos_au" => Ok(EftposAu),
172            "girocard" => Ok(Girocard),
173            "interac" => Ok(Interac),
174            "jcb" => Ok(Jcb),
175            "link" => Ok(Link),
176            "mastercard" => Ok(Mastercard),
177            "unionpay" => Ok(Unionpay),
178            "unknown" => Ok(Unknown),
179            "visa" => Ok(Visa),
180            _ => Err(stripe_types::StripeParseError),
181        }
182    }
183}
184impl std::fmt::Display for SubscriptionPaymentMethodOptionsCardNetwork {
185    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
186        f.write_str(self.as_str())
187    }
188}
189
190impl std::fmt::Debug for SubscriptionPaymentMethodOptionsCardNetwork {
191    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
192        f.write_str(self.as_str())
193    }
194}
195#[cfg(feature = "serialize")]
196impl serde::Serialize for SubscriptionPaymentMethodOptionsCardNetwork {
197    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
198    where
199        S: serde::Serializer,
200    {
201        serializer.serialize_str(self.as_str())
202    }
203}
204impl miniserde::Deserialize for SubscriptionPaymentMethodOptionsCardNetwork {
205    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
206        crate::Place::new(out)
207    }
208}
209
210impl miniserde::de::Visitor for crate::Place<SubscriptionPaymentMethodOptionsCardNetwork> {
211    fn string(&mut self, s: &str) -> miniserde::Result<()> {
212        use std::str::FromStr;
213        self.out = Some(
214            SubscriptionPaymentMethodOptionsCardNetwork::from_str(s)
215                .map_err(|_| miniserde::Error)?,
216        );
217        Ok(())
218    }
219}
220
221stripe_types::impl_from_val_with_from_str!(SubscriptionPaymentMethodOptionsCardNetwork);
222#[cfg(feature = "deserialize")]
223impl<'de> serde::Deserialize<'de> for SubscriptionPaymentMethodOptionsCardNetwork {
224    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
225        use std::str::FromStr;
226        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
227        Self::from_str(&s).map_err(|_| {
228            serde::de::Error::custom(
229                "Unknown value for SubscriptionPaymentMethodOptionsCardNetwork",
230            )
231        })
232    }
233}
234/// We strongly recommend that you rely on our SCA Engine to automatically prompt your customers for authentication based on risk level and [other requirements](https://stripe.com/docs/strong-customer-authentication).
235/// However, if you wish to request 3D Secure based on logic from your own fraud engine, provide this option.
236/// Read our guide on [manually requesting 3D Secure](https://stripe.com/docs/payments/3d-secure/authentication-flow#manual-three-ds) for more information on how this configuration interacts with Radar and our SCA Engine.
237#[derive(Copy, Clone, Eq, PartialEq)]
238pub enum SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
239    Any,
240    Automatic,
241    Challenge,
242}
243impl SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
244    pub fn as_str(self) -> &'static str {
245        use SubscriptionPaymentMethodOptionsCardRequestThreeDSecure::*;
246        match self {
247            Any => "any",
248            Automatic => "automatic",
249            Challenge => "challenge",
250        }
251    }
252}
253
254impl std::str::FromStr for SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
255    type Err = stripe_types::StripeParseError;
256    fn from_str(s: &str) -> Result<Self, Self::Err> {
257        use SubscriptionPaymentMethodOptionsCardRequestThreeDSecure::*;
258        match s {
259            "any" => Ok(Any),
260            "automatic" => Ok(Automatic),
261            "challenge" => Ok(Challenge),
262            _ => Err(stripe_types::StripeParseError),
263        }
264    }
265}
266impl std::fmt::Display for SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
267    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
268        f.write_str(self.as_str())
269    }
270}
271
272impl std::fmt::Debug for SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
273    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274        f.write_str(self.as_str())
275    }
276}
277#[cfg(feature = "serialize")]
278impl serde::Serialize for SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
279    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
280    where
281        S: serde::Serializer,
282    {
283        serializer.serialize_str(self.as_str())
284    }
285}
286impl miniserde::Deserialize for SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
287    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
288        crate::Place::new(out)
289    }
290}
291
292impl miniserde::de::Visitor
293    for crate::Place<SubscriptionPaymentMethodOptionsCardRequestThreeDSecure>
294{
295    fn string(&mut self, s: &str) -> miniserde::Result<()> {
296        use std::str::FromStr;
297        self.out = Some(
298            SubscriptionPaymentMethodOptionsCardRequestThreeDSecure::from_str(s)
299                .map_err(|_| miniserde::Error)?,
300        );
301        Ok(())
302    }
303}
304
305stripe_types::impl_from_val_with_from_str!(SubscriptionPaymentMethodOptionsCardRequestThreeDSecure);
306#[cfg(feature = "deserialize")]
307impl<'de> serde::Deserialize<'de> for SubscriptionPaymentMethodOptionsCardRequestThreeDSecure {
308    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
309        use std::str::FromStr;
310        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
311        Self::from_str(&s).map_err(|_| {
312            serde::de::Error::custom(
313                "Unknown value for SubscriptionPaymentMethodOptionsCardRequestThreeDSecure",
314            )
315        })
316    }
317}