stripe_shared/
payment_pages_private_card_payment_method_options_resource_restrictions.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictions {
5    /// Specify the card brands to block in the Checkout Session.
6    /// If a customer enters or selects a card belonging to a blocked brand, they can't complete the Session.
7    pub brands_blocked:
8        Option<Vec<PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked>>,
9}
10#[doc(hidden)]
11pub struct PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBuilder {
12    brands_blocked: Option<
13        Option<Vec<PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked>>,
14    >,
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 PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictions {
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<PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictions>,
41        builder: PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBuilder,
42    }
43
44    impl Visitor for Place<PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictions> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47            out: &mut self.out,
48            builder: PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBuilder::deser_default(),
49        }))
50        }
51    }
52
53    impl MapBuilder for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBuilder {
54        type Out = PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictions;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "brands_blocked" => Deserialize::begin(&mut self.brands_blocked),
58
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { brands_blocked: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(brands_blocked),) = (self.brands_blocked.take(),) else {
69                return None;
70            };
71            Some(Self::Out { brands_blocked })
72        }
73    }
74
75    impl Map for Builder<'_> {
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            self.builder.key(k)
78        }
79
80        fn finish(&mut self) -> Result<()> {
81            *self.out = self.builder.take_out();
82            Ok(())
83        }
84    }
85
86    impl ObjectDeser for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictions {
87        type Builder = PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBuilder;
88    }
89
90    impl FromValueOpt for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictions {
91        fn from_value(v: Value) -> Option<Self> {
92            let Value::Object(obj) = v else {
93                return None;
94            };
95            let mut b = PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBuilder::deser_default();
96            for (k, v) in obj {
97                match k.as_str() {
98                    "brands_blocked" => b.brands_blocked = FromValueOpt::from_value(v),
99
100                    _ => {}
101                }
102            }
103            b.take_out()
104        }
105    }
106};
107/// Specify the card brands to block in the Checkout Session.
108/// If a customer enters or selects a card belonging to a blocked brand, they can't complete the Session.
109#[derive(Copy, Clone, Eq, PartialEq)]
110pub enum PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked {
111    AmericanExpress,
112    DiscoverGlobalNetwork,
113    Mastercard,
114    Visa,
115}
116impl PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked {
117    pub fn as_str(self) -> &'static str {
118        use PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked::*;
119        match self {
120            AmericanExpress => "american_express",
121            DiscoverGlobalNetwork => "discover_global_network",
122            Mastercard => "mastercard",
123            Visa => "visa",
124        }
125    }
126}
127
128impl std::str::FromStr
129    for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked
130{
131    type Err = stripe_types::StripeParseError;
132    fn from_str(s: &str) -> Result<Self, Self::Err> {
133        use PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked::*;
134        match s {
135            "american_express" => Ok(AmericanExpress),
136            "discover_global_network" => Ok(DiscoverGlobalNetwork),
137            "mastercard" => Ok(Mastercard),
138            "visa" => Ok(Visa),
139            _ => Err(stripe_types::StripeParseError),
140        }
141    }
142}
143impl std::fmt::Display
144    for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked
145{
146    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
147        f.write_str(self.as_str())
148    }
149}
150
151impl std::fmt::Debug
152    for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked
153{
154    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155        f.write_str(self.as_str())
156    }
157}
158#[cfg(feature = "serialize")]
159impl serde::Serialize
160    for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked
161{
162    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
163    where
164        S: serde::Serializer,
165    {
166        serializer.serialize_str(self.as_str())
167    }
168}
169impl miniserde::Deserialize
170    for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked
171{
172    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
173        crate::Place::new(out)
174    }
175}
176
177impl miniserde::de::Visitor
178    for crate::Place<PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked>
179{
180    fn string(&mut self, s: &str) -> miniserde::Result<()> {
181        use std::str::FromStr;
182        self.out = Some(
183            PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked::from_str(
184                s,
185            )
186            .map_err(|_| miniserde::Error)?,
187        );
188        Ok(())
189    }
190}
191
192stripe_types::impl_from_val_with_from_str!(
193    PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked
194);
195#[cfg(feature = "deserialize")]
196impl<'de> serde::Deserialize<'de>
197    for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked
198{
199    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
200        use std::str::FromStr;
201        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
202        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for PaymentPagesPrivateCardPaymentMethodOptionsResourceRestrictionsBrandsBlocked"))
203    }
204}