stripe_shared/
invoice_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 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::{Deserialize, Result, make_place};
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                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self {
65                installments: Deserialize::default(),
66                request_three_d_secure: Deserialize::default(),
67            }
68        }
69
70        fn take_out(&mut self) -> Option<Self::Out> {
71            let (Some(installments), Some(request_three_d_secure)) =
72                (self.installments, self.request_three_d_secure.take())
73            else {
74                return None;
75            };
76            Some(Self::Out { installments, request_three_d_secure })
77        }
78    }
79
80    impl Map for Builder<'_> {
81        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
82            self.builder.key(k)
83        }
84
85        fn finish(&mut self) -> Result<()> {
86            *self.out = self.builder.take_out();
87            Ok(())
88        }
89    }
90
91    impl ObjectDeser for InvoicePaymentMethodOptionsCard {
92        type Builder = InvoicePaymentMethodOptionsCardBuilder;
93    }
94
95    impl FromValueOpt for InvoicePaymentMethodOptionsCard {
96        fn from_value(v: Value) -> Option<Self> {
97            let Value::Object(obj) = v else {
98                return None;
99            };
100            let mut b = InvoicePaymentMethodOptionsCardBuilder::deser_default();
101            for (k, v) in obj {
102                match k.as_str() {
103                    "installments" => b.installments = FromValueOpt::from_value(v),
104                    "request_three_d_secure" => {
105                        b.request_three_d_secure = FromValueOpt::from_value(v)
106                    }
107                    _ => {}
108                }
109            }
110            b.take_out()
111        }
112    }
113};
114/// 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).
115/// However, if you wish to request 3D Secure based on logic from your own fraud engine, provide this option.
116/// 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.
117#[derive(Clone, Eq, PartialEq)]
118#[non_exhaustive]
119pub enum InvoicePaymentMethodOptionsCardRequestThreeDSecure {
120    Any,
121    Automatic,
122    Challenge,
123    /// An unrecognized value from Stripe. Should not be used as a request parameter.
124    Unknown(String),
125}
126impl InvoicePaymentMethodOptionsCardRequestThreeDSecure {
127    pub fn as_str(&self) -> &str {
128        use InvoicePaymentMethodOptionsCardRequestThreeDSecure::*;
129        match self {
130            Any => "any",
131            Automatic => "automatic",
132            Challenge => "challenge",
133            Unknown(v) => v,
134        }
135    }
136}
137
138impl std::str::FromStr for InvoicePaymentMethodOptionsCardRequestThreeDSecure {
139    type Err = std::convert::Infallible;
140    fn from_str(s: &str) -> Result<Self, Self::Err> {
141        use InvoicePaymentMethodOptionsCardRequestThreeDSecure::*;
142        match s {
143            "any" => Ok(Any),
144            "automatic" => Ok(Automatic),
145            "challenge" => Ok(Challenge),
146            v => {
147                tracing::warn!(
148                    "Unknown value '{}' for enum '{}'",
149                    v,
150                    "InvoicePaymentMethodOptionsCardRequestThreeDSecure"
151                );
152                Ok(Unknown(v.to_owned()))
153            }
154        }
155    }
156}
157impl std::fmt::Display for InvoicePaymentMethodOptionsCardRequestThreeDSecure {
158    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
159        f.write_str(self.as_str())
160    }
161}
162
163impl std::fmt::Debug for InvoicePaymentMethodOptionsCardRequestThreeDSecure {
164    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165        f.write_str(self.as_str())
166    }
167}
168#[cfg(feature = "serialize")]
169impl serde::Serialize for InvoicePaymentMethodOptionsCardRequestThreeDSecure {
170    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
171    where
172        S: serde::Serializer,
173    {
174        serializer.serialize_str(self.as_str())
175    }
176}
177impl miniserde::Deserialize for InvoicePaymentMethodOptionsCardRequestThreeDSecure {
178    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
179        crate::Place::new(out)
180    }
181}
182
183impl miniserde::de::Visitor for crate::Place<InvoicePaymentMethodOptionsCardRequestThreeDSecure> {
184    fn string(&mut self, s: &str) -> miniserde::Result<()> {
185        use std::str::FromStr;
186        self.out = Some(
187            InvoicePaymentMethodOptionsCardRequestThreeDSecure::from_str(s).expect("infallible"),
188        );
189        Ok(())
190    }
191}
192
193stripe_types::impl_from_val_with_from_str!(InvoicePaymentMethodOptionsCardRequestThreeDSecure);
194#[cfg(feature = "deserialize")]
195impl<'de> serde::Deserialize<'de> for InvoicePaymentMethodOptionsCardRequestThreeDSecure {
196    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
197        use std::str::FromStr;
198        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
199        Ok(Self::from_str(&s).expect("infallible"))
200    }
201}