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