stripe_shared/
payment_links_resource_after_completion.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentLinksResourceAfterCompletion {
5    pub hosted_confirmation:
6        Option<stripe_shared::PaymentLinksResourceCompletionBehaviorConfirmationPage>,
7    pub redirect: Option<stripe_shared::PaymentLinksResourceCompletionBehaviorRedirect>,
8    /// The specified behavior after the purchase is complete.
9    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
10    pub type_: PaymentLinksResourceAfterCompletionType,
11}
12#[doc(hidden)]
13pub struct PaymentLinksResourceAfterCompletionBuilder {
14    hosted_confirmation:
15        Option<Option<stripe_shared::PaymentLinksResourceCompletionBehaviorConfirmationPage>>,
16    redirect: Option<Option<stripe_shared::PaymentLinksResourceCompletionBehaviorRedirect>>,
17    type_: Option<PaymentLinksResourceAfterCompletionType>,
18}
19
20#[allow(
21    unused_variables,
22    irrefutable_let_patterns,
23    clippy::let_unit_value,
24    clippy::match_single_binding,
25    clippy::single_match
26)]
27const _: () = {
28    use miniserde::de::{Map, Visitor};
29    use miniserde::json::Value;
30    use miniserde::{Deserialize, Result, make_place};
31    use stripe_types::miniserde_helpers::FromValueOpt;
32    use stripe_types::{MapBuilder, ObjectDeser};
33
34    make_place!(Place);
35
36    impl Deserialize for PaymentLinksResourceAfterCompletion {
37        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
38            Place::new(out)
39        }
40    }
41
42    struct Builder<'a> {
43        out: &'a mut Option<PaymentLinksResourceAfterCompletion>,
44        builder: PaymentLinksResourceAfterCompletionBuilder,
45    }
46
47    impl Visitor for Place<PaymentLinksResourceAfterCompletion> {
48        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
49            Ok(Box::new(Builder {
50                out: &mut self.out,
51                builder: PaymentLinksResourceAfterCompletionBuilder::deser_default(),
52            }))
53        }
54    }
55
56    impl MapBuilder for PaymentLinksResourceAfterCompletionBuilder {
57        type Out = PaymentLinksResourceAfterCompletion;
58        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
59            Ok(match k {
60                "hosted_confirmation" => Deserialize::begin(&mut self.hosted_confirmation),
61                "redirect" => Deserialize::begin(&mut self.redirect),
62                "type" => Deserialize::begin(&mut self.type_),
63                _ => <dyn Visitor>::ignore(),
64            })
65        }
66
67        fn deser_default() -> Self {
68            Self {
69                hosted_confirmation: Deserialize::default(),
70                redirect: Deserialize::default(),
71                type_: Deserialize::default(),
72            }
73        }
74
75        fn take_out(&mut self) -> Option<Self::Out> {
76            let (Some(hosted_confirmation), Some(redirect), Some(type_)) =
77                (self.hosted_confirmation.take(), self.redirect.take(), self.type_.take())
78            else {
79                return None;
80            };
81            Some(Self::Out { hosted_confirmation, redirect, type_ })
82        }
83    }
84
85    impl Map for Builder<'_> {
86        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
87            self.builder.key(k)
88        }
89
90        fn finish(&mut self) -> Result<()> {
91            *self.out = self.builder.take_out();
92            Ok(())
93        }
94    }
95
96    impl ObjectDeser for PaymentLinksResourceAfterCompletion {
97        type Builder = PaymentLinksResourceAfterCompletionBuilder;
98    }
99
100    impl FromValueOpt for PaymentLinksResourceAfterCompletion {
101        fn from_value(v: Value) -> Option<Self> {
102            let Value::Object(obj) = v else {
103                return None;
104            };
105            let mut b = PaymentLinksResourceAfterCompletionBuilder::deser_default();
106            for (k, v) in obj {
107                match k.as_str() {
108                    "hosted_confirmation" => b.hosted_confirmation = FromValueOpt::from_value(v),
109                    "redirect" => b.redirect = FromValueOpt::from_value(v),
110                    "type" => b.type_ = FromValueOpt::from_value(v),
111                    _ => {}
112                }
113            }
114            b.take_out()
115        }
116    }
117};
118/// The specified behavior after the purchase is complete.
119#[derive(Clone, Eq, PartialEq)]
120#[non_exhaustive]
121pub enum PaymentLinksResourceAfterCompletionType {
122    HostedConfirmation,
123    Redirect,
124    /// An unrecognized value from Stripe. Should not be used as a request parameter.
125    Unknown(String),
126}
127impl PaymentLinksResourceAfterCompletionType {
128    pub fn as_str(&self) -> &str {
129        use PaymentLinksResourceAfterCompletionType::*;
130        match self {
131            HostedConfirmation => "hosted_confirmation",
132            Redirect => "redirect",
133            Unknown(v) => v,
134        }
135    }
136}
137
138impl std::str::FromStr for PaymentLinksResourceAfterCompletionType {
139    type Err = std::convert::Infallible;
140    fn from_str(s: &str) -> Result<Self, Self::Err> {
141        use PaymentLinksResourceAfterCompletionType::*;
142        match s {
143            "hosted_confirmation" => Ok(HostedConfirmation),
144            "redirect" => Ok(Redirect),
145            v => {
146                tracing::warn!(
147                    "Unknown value '{}' for enum '{}'",
148                    v,
149                    "PaymentLinksResourceAfterCompletionType"
150                );
151                Ok(Unknown(v.to_owned()))
152            }
153        }
154    }
155}
156impl std::fmt::Display for PaymentLinksResourceAfterCompletionType {
157    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161
162impl std::fmt::Debug for PaymentLinksResourceAfterCompletionType {
163    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164        f.write_str(self.as_str())
165    }
166}
167#[cfg(feature = "serialize")]
168impl serde::Serialize for PaymentLinksResourceAfterCompletionType {
169    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
170    where
171        S: serde::Serializer,
172    {
173        serializer.serialize_str(self.as_str())
174    }
175}
176impl miniserde::Deserialize for PaymentLinksResourceAfterCompletionType {
177    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
178        crate::Place::new(out)
179    }
180}
181
182impl miniserde::de::Visitor for crate::Place<PaymentLinksResourceAfterCompletionType> {
183    fn string(&mut self, s: &str) -> miniserde::Result<()> {
184        use std::str::FromStr;
185        self.out = Some(PaymentLinksResourceAfterCompletionType::from_str(s).expect("infallible"));
186        Ok(())
187    }
188}
189
190stripe_types::impl_from_val_with_from_str!(PaymentLinksResourceAfterCompletionType);
191#[cfg(feature = "deserialize")]
192impl<'de> serde::Deserialize<'de> for PaymentLinksResourceAfterCompletionType {
193    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
194        use std::str::FromStr;
195        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
196        Ok(Self::from_str(&s).expect("infallible"))
197    }
198}