stripe_shared/
invoice_payment_method_options_card.rs

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