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