1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CancellationDetails {
5 pub comment: Option<String>,
7 pub feedback: Option<CancellationDetailsFeedback>,
9 pub reason: Option<CancellationDetailsReason>,
11}
12#[doc(hidden)]
13pub struct CancellationDetailsBuilder {
14 comment: Option<Option<String>>,
15 feedback: Option<Option<CancellationDetailsFeedback>>,
16 reason: Option<Option<CancellationDetailsReason>>,
17}
18
19#[allow(
20 unused_variables,
21 irrefutable_let_patterns,
22 clippy::let_unit_value,
23 clippy::match_single_binding,
24 clippy::single_match
25)]
26const _: () = {
27 use miniserde::de::{Map, Visitor};
28 use miniserde::json::Value;
29 use miniserde::{Deserialize, Result, make_place};
30 use stripe_types::miniserde_helpers::FromValueOpt;
31 use stripe_types::{MapBuilder, ObjectDeser};
32
33 make_place!(Place);
34
35 impl Deserialize for CancellationDetails {
36 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
37 Place::new(out)
38 }
39 }
40
41 struct Builder<'a> {
42 out: &'a mut Option<CancellationDetails>,
43 builder: CancellationDetailsBuilder,
44 }
45
46 impl Visitor for Place<CancellationDetails> {
47 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
48 Ok(Box::new(Builder {
49 out: &mut self.out,
50 builder: CancellationDetailsBuilder::deser_default(),
51 }))
52 }
53 }
54
55 impl MapBuilder for CancellationDetailsBuilder {
56 type Out = CancellationDetails;
57 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
58 Ok(match k {
59 "comment" => Deserialize::begin(&mut self.comment),
60 "feedback" => Deserialize::begin(&mut self.feedback),
61 "reason" => Deserialize::begin(&mut self.reason),
62 _ => <dyn Visitor>::ignore(),
63 })
64 }
65
66 fn deser_default() -> Self {
67 Self {
68 comment: Deserialize::default(),
69 feedback: Deserialize::default(),
70 reason: Deserialize::default(),
71 }
72 }
73
74 fn take_out(&mut self) -> Option<Self::Out> {
75 let (Some(comment), Some(feedback), Some(reason)) =
76 (self.comment.take(), self.feedback.take(), self.reason.take())
77 else {
78 return None;
79 };
80 Some(Self::Out { comment, feedback, reason })
81 }
82 }
83
84 impl Map for Builder<'_> {
85 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86 self.builder.key(k)
87 }
88
89 fn finish(&mut self) -> Result<()> {
90 *self.out = self.builder.take_out();
91 Ok(())
92 }
93 }
94
95 impl ObjectDeser for CancellationDetails {
96 type Builder = CancellationDetailsBuilder;
97 }
98
99 impl FromValueOpt for CancellationDetails {
100 fn from_value(v: Value) -> Option<Self> {
101 let Value::Object(obj) = v else {
102 return None;
103 };
104 let mut b = CancellationDetailsBuilder::deser_default();
105 for (k, v) in obj {
106 match k.as_str() {
107 "comment" => b.comment = FromValueOpt::from_value(v),
108 "feedback" => b.feedback = FromValueOpt::from_value(v),
109 "reason" => b.reason = FromValueOpt::from_value(v),
110 _ => {}
111 }
112 }
113 b.take_out()
114 }
115 }
116};
117#[derive(Clone, Eq, PartialEq)]
119#[non_exhaustive]
120pub enum CancellationDetailsFeedback {
121 CustomerService,
122 LowQuality,
123 MissingFeatures,
124 Other,
125 SwitchedService,
126 TooComplex,
127 TooExpensive,
128 Unused,
129 Unknown(String),
131}
132impl CancellationDetailsFeedback {
133 pub fn as_str(&self) -> &str {
134 use CancellationDetailsFeedback::*;
135 match self {
136 CustomerService => "customer_service",
137 LowQuality => "low_quality",
138 MissingFeatures => "missing_features",
139 Other => "other",
140 SwitchedService => "switched_service",
141 TooComplex => "too_complex",
142 TooExpensive => "too_expensive",
143 Unused => "unused",
144 Unknown(v) => v,
145 }
146 }
147}
148
149impl std::str::FromStr for CancellationDetailsFeedback {
150 type Err = std::convert::Infallible;
151 fn from_str(s: &str) -> Result<Self, Self::Err> {
152 use CancellationDetailsFeedback::*;
153 match s {
154 "customer_service" => Ok(CustomerService),
155 "low_quality" => Ok(LowQuality),
156 "missing_features" => Ok(MissingFeatures),
157 "other" => Ok(Other),
158 "switched_service" => Ok(SwitchedService),
159 "too_complex" => Ok(TooComplex),
160 "too_expensive" => Ok(TooExpensive),
161 "unused" => Ok(Unused),
162 v => {
163 tracing::warn!(
164 "Unknown value '{}' for enum '{}'",
165 v,
166 "CancellationDetailsFeedback"
167 );
168 Ok(Unknown(v.to_owned()))
169 }
170 }
171 }
172}
173impl std::fmt::Display for CancellationDetailsFeedback {
174 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
175 f.write_str(self.as_str())
176 }
177}
178
179impl std::fmt::Debug for CancellationDetailsFeedback {
180 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
181 f.write_str(self.as_str())
182 }
183}
184#[cfg(feature = "serialize")]
185impl serde::Serialize for CancellationDetailsFeedback {
186 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
187 where
188 S: serde::Serializer,
189 {
190 serializer.serialize_str(self.as_str())
191 }
192}
193impl miniserde::Deserialize for CancellationDetailsFeedback {
194 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
195 crate::Place::new(out)
196 }
197}
198
199impl miniserde::de::Visitor for crate::Place<CancellationDetailsFeedback> {
200 fn string(&mut self, s: &str) -> miniserde::Result<()> {
201 use std::str::FromStr;
202 self.out = Some(CancellationDetailsFeedback::from_str(s).expect("infallible"));
203 Ok(())
204 }
205}
206
207stripe_types::impl_from_val_with_from_str!(CancellationDetailsFeedback);
208#[cfg(feature = "deserialize")]
209impl<'de> serde::Deserialize<'de> for CancellationDetailsFeedback {
210 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
211 use std::str::FromStr;
212 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
213 Ok(Self::from_str(&s).expect("infallible"))
214 }
215}
216#[derive(Clone, Eq, PartialEq)]
218#[non_exhaustive]
219pub enum CancellationDetailsReason {
220 CancellationRequested,
221 PaymentDisputed,
222 PaymentFailed,
223 Unknown(String),
225}
226impl CancellationDetailsReason {
227 pub fn as_str(&self) -> &str {
228 use CancellationDetailsReason::*;
229 match self {
230 CancellationRequested => "cancellation_requested",
231 PaymentDisputed => "payment_disputed",
232 PaymentFailed => "payment_failed",
233 Unknown(v) => v,
234 }
235 }
236}
237
238impl std::str::FromStr for CancellationDetailsReason {
239 type Err = std::convert::Infallible;
240 fn from_str(s: &str) -> Result<Self, Self::Err> {
241 use CancellationDetailsReason::*;
242 match s {
243 "cancellation_requested" => Ok(CancellationRequested),
244 "payment_disputed" => Ok(PaymentDisputed),
245 "payment_failed" => Ok(PaymentFailed),
246 v => {
247 tracing::warn!("Unknown value '{}' for enum '{}'", v, "CancellationDetailsReason");
248 Ok(Unknown(v.to_owned()))
249 }
250 }
251 }
252}
253impl std::fmt::Display for CancellationDetailsReason {
254 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
255 f.write_str(self.as_str())
256 }
257}
258
259impl std::fmt::Debug for CancellationDetailsReason {
260 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
261 f.write_str(self.as_str())
262 }
263}
264#[cfg(feature = "serialize")]
265impl serde::Serialize for CancellationDetailsReason {
266 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
267 where
268 S: serde::Serializer,
269 {
270 serializer.serialize_str(self.as_str())
271 }
272}
273impl miniserde::Deserialize for CancellationDetailsReason {
274 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
275 crate::Place::new(out)
276 }
277}
278
279impl miniserde::de::Visitor for crate::Place<CancellationDetailsReason> {
280 fn string(&mut self, s: &str) -> miniserde::Result<()> {
281 use std::str::FromStr;
282 self.out = Some(CancellationDetailsReason::from_str(s).expect("infallible"));
283 Ok(())
284 }
285}
286
287stripe_types::impl_from_val_with_from_str!(CancellationDetailsReason);
288#[cfg(feature = "deserialize")]
289impl<'de> serde::Deserialize<'de> for CancellationDetailsReason {
290 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
291 use std::str::FromStr;
292 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
293 Ok(Self::from_str(&s).expect("infallible"))
294 }
295}