1#[derive(Clone, Debug)]
8#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
9pub struct Review {
10 pub billing_zip: Option<String>,
12 pub charge: Option<stripe_types::Expandable<stripe_shared::Charge>>,
14 pub closed_reason: Option<ReviewClosedReason>,
17 pub created: stripe_types::Timestamp,
19 pub id: stripe_shared::ReviewId,
21 pub ip_address: Option<String>,
23 pub ip_address_location: Option<stripe_shared::RadarReviewResourceLocation>,
26 pub livemode: bool,
28 pub open: bool,
30 pub opened_reason: ReviewOpenedReason,
32 pub payment_intent: Option<stripe_types::Expandable<stripe_shared::PaymentIntent>>,
34 pub reason: String,
37 pub session: Option<stripe_shared::RadarReviewResourceSession>,
39}
40#[doc(hidden)]
41pub struct ReviewBuilder {
42 billing_zip: Option<Option<String>>,
43 charge: Option<Option<stripe_types::Expandable<stripe_shared::Charge>>>,
44 closed_reason: Option<Option<ReviewClosedReason>>,
45 created: Option<stripe_types::Timestamp>,
46 id: Option<stripe_shared::ReviewId>,
47 ip_address: Option<Option<String>>,
48 ip_address_location: Option<Option<stripe_shared::RadarReviewResourceLocation>>,
49 livemode: Option<bool>,
50 open: Option<bool>,
51 opened_reason: Option<ReviewOpenedReason>,
52 payment_intent: Option<Option<stripe_types::Expandable<stripe_shared::PaymentIntent>>>,
53 reason: Option<String>,
54 session: Option<Option<stripe_shared::RadarReviewResourceSession>>,
55}
56
57#[allow(
58 unused_variables,
59 irrefutable_let_patterns,
60 clippy::let_unit_value,
61 clippy::match_single_binding,
62 clippy::single_match
63)]
64const _: () = {
65 use miniserde::de::{Map, Visitor};
66 use miniserde::json::Value;
67 use miniserde::{Deserialize, Result, make_place};
68 use stripe_types::miniserde_helpers::FromValueOpt;
69 use stripe_types::{MapBuilder, ObjectDeser};
70
71 make_place!(Place);
72
73 impl Deserialize for Review {
74 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
75 Place::new(out)
76 }
77 }
78
79 struct Builder<'a> {
80 out: &'a mut Option<Review>,
81 builder: ReviewBuilder,
82 }
83
84 impl Visitor for Place<Review> {
85 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
86 Ok(Box::new(Builder { out: &mut self.out, builder: ReviewBuilder::deser_default() }))
87 }
88 }
89
90 impl MapBuilder for ReviewBuilder {
91 type Out = Review;
92 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
93 Ok(match k {
94 "billing_zip" => Deserialize::begin(&mut self.billing_zip),
95 "charge" => Deserialize::begin(&mut self.charge),
96 "closed_reason" => Deserialize::begin(&mut self.closed_reason),
97 "created" => Deserialize::begin(&mut self.created),
98 "id" => Deserialize::begin(&mut self.id),
99 "ip_address" => Deserialize::begin(&mut self.ip_address),
100 "ip_address_location" => Deserialize::begin(&mut self.ip_address_location),
101 "livemode" => Deserialize::begin(&mut self.livemode),
102 "open" => Deserialize::begin(&mut self.open),
103 "opened_reason" => Deserialize::begin(&mut self.opened_reason),
104 "payment_intent" => Deserialize::begin(&mut self.payment_intent),
105 "reason" => Deserialize::begin(&mut self.reason),
106 "session" => Deserialize::begin(&mut self.session),
107 _ => <dyn Visitor>::ignore(),
108 })
109 }
110
111 fn deser_default() -> Self {
112 Self {
113 billing_zip: Deserialize::default(),
114 charge: Deserialize::default(),
115 closed_reason: Deserialize::default(),
116 created: Deserialize::default(),
117 id: Deserialize::default(),
118 ip_address: Deserialize::default(),
119 ip_address_location: Deserialize::default(),
120 livemode: Deserialize::default(),
121 open: Deserialize::default(),
122 opened_reason: Deserialize::default(),
123 payment_intent: Deserialize::default(),
124 reason: Deserialize::default(),
125 session: Deserialize::default(),
126 }
127 }
128
129 fn take_out(&mut self) -> Option<Self::Out> {
130 let (
131 Some(billing_zip),
132 Some(charge),
133 Some(closed_reason),
134 Some(created),
135 Some(id),
136 Some(ip_address),
137 Some(ip_address_location),
138 Some(livemode),
139 Some(open),
140 Some(opened_reason),
141 Some(payment_intent),
142 Some(reason),
143 Some(session),
144 ) = (
145 self.billing_zip.take(),
146 self.charge.take(),
147 self.closed_reason.take(),
148 self.created,
149 self.id.take(),
150 self.ip_address.take(),
151 self.ip_address_location.take(),
152 self.livemode,
153 self.open,
154 self.opened_reason.take(),
155 self.payment_intent.take(),
156 self.reason.take(),
157 self.session.take(),
158 )
159 else {
160 return None;
161 };
162 Some(Self::Out {
163 billing_zip,
164 charge,
165 closed_reason,
166 created,
167 id,
168 ip_address,
169 ip_address_location,
170 livemode,
171 open,
172 opened_reason,
173 payment_intent,
174 reason,
175 session,
176 })
177 }
178 }
179
180 impl Map for Builder<'_> {
181 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
182 self.builder.key(k)
183 }
184
185 fn finish(&mut self) -> Result<()> {
186 *self.out = self.builder.take_out();
187 Ok(())
188 }
189 }
190
191 impl ObjectDeser for Review {
192 type Builder = ReviewBuilder;
193 }
194
195 impl FromValueOpt for Review {
196 fn from_value(v: Value) -> Option<Self> {
197 let Value::Object(obj) = v else {
198 return None;
199 };
200 let mut b = ReviewBuilder::deser_default();
201 for (k, v) in obj {
202 match k.as_str() {
203 "billing_zip" => b.billing_zip = FromValueOpt::from_value(v),
204 "charge" => b.charge = FromValueOpt::from_value(v),
205 "closed_reason" => b.closed_reason = FromValueOpt::from_value(v),
206 "created" => b.created = FromValueOpt::from_value(v),
207 "id" => b.id = FromValueOpt::from_value(v),
208 "ip_address" => b.ip_address = FromValueOpt::from_value(v),
209 "ip_address_location" => b.ip_address_location = FromValueOpt::from_value(v),
210 "livemode" => b.livemode = FromValueOpt::from_value(v),
211 "open" => b.open = FromValueOpt::from_value(v),
212 "opened_reason" => b.opened_reason = FromValueOpt::from_value(v),
213 "payment_intent" => b.payment_intent = FromValueOpt::from_value(v),
214 "reason" => b.reason = FromValueOpt::from_value(v),
215 "session" => b.session = FromValueOpt::from_value(v),
216 _ => {}
217 }
218 }
219 b.take_out()
220 }
221 }
222};
223#[cfg(feature = "serialize")]
224impl serde::Serialize for Review {
225 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
226 use serde::ser::SerializeStruct;
227 let mut s = s.serialize_struct("Review", 14)?;
228 s.serialize_field("billing_zip", &self.billing_zip)?;
229 s.serialize_field("charge", &self.charge)?;
230 s.serialize_field("closed_reason", &self.closed_reason)?;
231 s.serialize_field("created", &self.created)?;
232 s.serialize_field("id", &self.id)?;
233 s.serialize_field("ip_address", &self.ip_address)?;
234 s.serialize_field("ip_address_location", &self.ip_address_location)?;
235 s.serialize_field("livemode", &self.livemode)?;
236 s.serialize_field("open", &self.open)?;
237 s.serialize_field("opened_reason", &self.opened_reason)?;
238 s.serialize_field("payment_intent", &self.payment_intent)?;
239 s.serialize_field("reason", &self.reason)?;
240 s.serialize_field("session", &self.session)?;
241
242 s.serialize_field("object", "review")?;
243 s.end()
244 }
245}
246#[derive(Clone, Eq, PartialEq)]
249#[non_exhaustive]
250pub enum ReviewClosedReason {
251 Acknowledged,
252 Approved,
253 Canceled,
254 Disputed,
255 PaymentNeverSettled,
256 Redacted,
257 Refunded,
258 RefundedAsFraud,
259 Unknown(String),
261}
262impl ReviewClosedReason {
263 pub fn as_str(&self) -> &str {
264 use ReviewClosedReason::*;
265 match self {
266 Acknowledged => "acknowledged",
267 Approved => "approved",
268 Canceled => "canceled",
269 Disputed => "disputed",
270 PaymentNeverSettled => "payment_never_settled",
271 Redacted => "redacted",
272 Refunded => "refunded",
273 RefundedAsFraud => "refunded_as_fraud",
274 Unknown(v) => v,
275 }
276 }
277}
278
279impl std::str::FromStr for ReviewClosedReason {
280 type Err = std::convert::Infallible;
281 fn from_str(s: &str) -> Result<Self, Self::Err> {
282 use ReviewClosedReason::*;
283 match s {
284 "acknowledged" => Ok(Acknowledged),
285 "approved" => Ok(Approved),
286 "canceled" => Ok(Canceled),
287 "disputed" => Ok(Disputed),
288 "payment_never_settled" => Ok(PaymentNeverSettled),
289 "redacted" => Ok(Redacted),
290 "refunded" => Ok(Refunded),
291 "refunded_as_fraud" => Ok(RefundedAsFraud),
292 v => {
293 tracing::warn!("Unknown value '{}' for enum '{}'", v, "ReviewClosedReason");
294 Ok(Unknown(v.to_owned()))
295 }
296 }
297 }
298}
299impl std::fmt::Display for ReviewClosedReason {
300 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
301 f.write_str(self.as_str())
302 }
303}
304
305impl std::fmt::Debug for ReviewClosedReason {
306 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
307 f.write_str(self.as_str())
308 }
309}
310#[cfg(feature = "serialize")]
311impl serde::Serialize for ReviewClosedReason {
312 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
313 where
314 S: serde::Serializer,
315 {
316 serializer.serialize_str(self.as_str())
317 }
318}
319impl miniserde::Deserialize for ReviewClosedReason {
320 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
321 crate::Place::new(out)
322 }
323}
324
325impl miniserde::de::Visitor for crate::Place<ReviewClosedReason> {
326 fn string(&mut self, s: &str) -> miniserde::Result<()> {
327 use std::str::FromStr;
328 self.out = Some(ReviewClosedReason::from_str(s).expect("infallible"));
329 Ok(())
330 }
331}
332
333stripe_types::impl_from_val_with_from_str!(ReviewClosedReason);
334#[cfg(feature = "deserialize")]
335impl<'de> serde::Deserialize<'de> for ReviewClosedReason {
336 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
337 use std::str::FromStr;
338 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
339 Ok(Self::from_str(&s).expect("infallible"))
340 }
341}
342#[derive(Clone, Eq, PartialEq)]
344#[non_exhaustive]
345pub enum ReviewOpenedReason {
346 Manual,
347 Rule,
348 Unknown(String),
350}
351impl ReviewOpenedReason {
352 pub fn as_str(&self) -> &str {
353 use ReviewOpenedReason::*;
354 match self {
355 Manual => "manual",
356 Rule => "rule",
357 Unknown(v) => v,
358 }
359 }
360}
361
362impl std::str::FromStr for ReviewOpenedReason {
363 type Err = std::convert::Infallible;
364 fn from_str(s: &str) -> Result<Self, Self::Err> {
365 use ReviewOpenedReason::*;
366 match s {
367 "manual" => Ok(Manual),
368 "rule" => Ok(Rule),
369 v => {
370 tracing::warn!("Unknown value '{}' for enum '{}'", v, "ReviewOpenedReason");
371 Ok(Unknown(v.to_owned()))
372 }
373 }
374 }
375}
376impl std::fmt::Display for ReviewOpenedReason {
377 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
378 f.write_str(self.as_str())
379 }
380}
381
382impl std::fmt::Debug for ReviewOpenedReason {
383 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
384 f.write_str(self.as_str())
385 }
386}
387#[cfg(feature = "serialize")]
388impl serde::Serialize for ReviewOpenedReason {
389 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
390 where
391 S: serde::Serializer,
392 {
393 serializer.serialize_str(self.as_str())
394 }
395}
396impl miniserde::Deserialize for ReviewOpenedReason {
397 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
398 crate::Place::new(out)
399 }
400}
401
402impl miniserde::de::Visitor for crate::Place<ReviewOpenedReason> {
403 fn string(&mut self, s: &str) -> miniserde::Result<()> {
404 use std::str::FromStr;
405 self.out = Some(ReviewOpenedReason::from_str(s).expect("infallible"));
406 Ok(())
407 }
408}
409
410stripe_types::impl_from_val_with_from_str!(ReviewOpenedReason);
411#[cfg(feature = "deserialize")]
412impl<'de> serde::Deserialize<'de> for ReviewOpenedReason {
413 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
414 use std::str::FromStr;
415 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
416 Ok(Self::from_str(&s).expect("infallible"))
417 }
418}
419impl stripe_types::Object for Review {
420 type Id = stripe_shared::ReviewId;
421 fn id(&self) -> &Self::Id {
422 &self.id
423 }
424
425 fn into_id(self) -> Self::Id {
426 self.id
427 }
428}
429stripe_types::def_id!(ReviewId);