stripe_shared/
payment_pages_checkout_session_permissions.rs

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