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
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                hosted_confirmation: Deserialize::default(),
71                redirect: Deserialize::default(),
72                type_: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(hosted_confirmation), Some(redirect), Some(type_)) =
78                (self.hosted_confirmation.take(), self.redirect.take(), self.type_)
79            else {
80                return None;
81            };
82            Some(Self::Out { hosted_confirmation, redirect, type_ })
83        }
84    }
85
86    impl Map for Builder<'_> {
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            self.builder.key(k)
89        }
90
91        fn finish(&mut self) -> Result<()> {
92            *self.out = self.builder.take_out();
93            Ok(())
94        }
95    }
96
97    impl ObjectDeser for PaymentLinksResourceAfterCompletion {
98        type Builder = PaymentLinksResourceAfterCompletionBuilder;
99    }
100
101    impl FromValueOpt for PaymentLinksResourceAfterCompletion {
102        fn from_value(v: Value) -> Option<Self> {
103            let Value::Object(obj) = v else {
104                return None;
105            };
106            let mut b = PaymentLinksResourceAfterCompletionBuilder::deser_default();
107            for (k, v) in obj {
108                match k.as_str() {
109                    "hosted_confirmation" => b.hosted_confirmation = FromValueOpt::from_value(v),
110                    "redirect" => b.redirect = FromValueOpt::from_value(v),
111                    "type" => b.type_ = FromValueOpt::from_value(v),
112
113                    _ => {}
114                }
115            }
116            b.take_out()
117        }
118    }
119};
120/// The specified behavior after the purchase is complete.
121#[derive(Copy, Clone, Eq, PartialEq)]
122pub enum PaymentLinksResourceAfterCompletionType {
123    HostedConfirmation,
124    Redirect,
125}
126impl PaymentLinksResourceAfterCompletionType {
127    pub fn as_str(self) -> &'static str {
128        use PaymentLinksResourceAfterCompletionType::*;
129        match self {
130            HostedConfirmation => "hosted_confirmation",
131            Redirect => "redirect",
132        }
133    }
134}
135
136impl std::str::FromStr for PaymentLinksResourceAfterCompletionType {
137    type Err = stripe_types::StripeParseError;
138    fn from_str(s: &str) -> Result<Self, Self::Err> {
139        use PaymentLinksResourceAfterCompletionType::*;
140        match s {
141            "hosted_confirmation" => Ok(HostedConfirmation),
142            "redirect" => Ok(Redirect),
143            _ => Err(stripe_types::StripeParseError),
144        }
145    }
146}
147impl std::fmt::Display for PaymentLinksResourceAfterCompletionType {
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.write_str(self.as_str())
150    }
151}
152
153impl std::fmt::Debug for PaymentLinksResourceAfterCompletionType {
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 for PaymentLinksResourceAfterCompletionType {
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 for PaymentLinksResourceAfterCompletionType {
168    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
169        crate::Place::new(out)
170    }
171}
172
173impl miniserde::de::Visitor for crate::Place<PaymentLinksResourceAfterCompletionType> {
174    fn string(&mut self, s: &str) -> miniserde::Result<()> {
175        use std::str::FromStr;
176        self.out = Some(
177            PaymentLinksResourceAfterCompletionType::from_str(s).map_err(|_| miniserde::Error)?,
178        );
179        Ok(())
180    }
181}
182
183stripe_types::impl_from_val_with_from_str!(PaymentLinksResourceAfterCompletionType);
184#[cfg(feature = "deserialize")]
185impl<'de> serde::Deserialize<'de> for PaymentLinksResourceAfterCompletionType {
186    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
187        use std::str::FromStr;
188        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
189        Self::from_str(&s).map_err(|_| {
190            serde::de::Error::custom("Unknown value for PaymentLinksResourceAfterCompletionType")
191        })
192    }
193}