stripe/resources/generated/
review.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::ReviewId;
7use crate::params::{Expand, Expandable, List, Object, Paginable, RangeQuery, Timestamp};
8use crate::resources::{Charge, PaymentIntent, ReviewReason};
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "RadarReview".
12///
13/// For more details see <https://stripe.com/docs/api/radar/reviews/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct Review {
16    /// Unique identifier for the object.
17    pub id: ReviewId,
18
19    /// The ZIP or postal code of the card used, if applicable.
20    pub billing_zip: Option<String>,
21
22    /// The charge associated with this review.
23    pub charge: Option<Expandable<Charge>>,
24
25    /// The reason the review was closed, or null if it has not yet been closed.
26    ///
27    /// One of `approved`, `refunded`, `refunded_as_fraud`, `disputed`, or `redacted`.
28    pub closed_reason: Option<ReviewClosedReason>,
29
30    /// Time at which the object was created.
31    ///
32    /// Measured in seconds since the Unix epoch.
33    pub created: Timestamp,
34
35    /// The IP address where the payment originated.
36    pub ip_address: Option<String>,
37
38    /// Information related to the location of the payment.
39    ///
40    /// Note that this information is an approximation and attempts to locate the nearest population center - it should not be used to determine a specific address.
41    pub ip_address_location: Option<RadarReviewResourceLocation>,
42
43    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
44    pub livemode: bool,
45
46    /// If `true`, the review needs action.
47    pub open: bool,
48
49    /// The reason the review was opened.
50    ///
51    /// One of `rule` or `manual`.
52    pub opened_reason: ReviewOpenedReason,
53
54    /// The PaymentIntent ID associated with this review, if one exists.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub payment_intent: Option<Expandable<PaymentIntent>>,
57
58    /// The reason the review is currently open or closed.
59    ///
60    /// One of `rule`, `manual`, `approved`, `refunded`, `refunded_as_fraud`, `disputed`, or `redacted`.
61    pub reason: ReviewReason,
62
63    /// Information related to the browsing session of the user who initiated the payment.
64    pub session: Option<RadarReviewResourceSession>,
65}
66
67impl Review {
68    /// Returns a list of `Review` objects that have `open` set to `true`.
69    ///
70    /// The objects are sorted in descending order by creation date, with the most recently created object appearing first.
71    pub fn list(client: &Client, params: &ListReviews<'_>) -> Response<List<Review>> {
72        client.get_query("/reviews", params)
73    }
74
75    /// Retrieves a `Review` object.
76    pub fn retrieve(client: &Client, id: &ReviewId, expand: &[&str]) -> Response<Review> {
77        client.get_query(&format!("/reviews/{}", id), Expand { expand })
78    }
79}
80
81impl Object for Review {
82    type Id = ReviewId;
83    fn id(&self) -> Self::Id {
84        self.id.clone()
85    }
86    fn object(&self) -> &'static str {
87        "review"
88    }
89}
90
91#[derive(Clone, Debug, Default, Deserialize, Serialize)]
92pub struct RadarReviewResourceLocation {
93    /// The city where the payment originated.
94    pub city: Option<String>,
95
96    /// Two-letter ISO code representing the country where the payment originated.
97    pub country: Option<String>,
98
99    /// The geographic latitude where the payment originated.
100    pub latitude: Option<f64>,
101
102    /// The geographic longitude where the payment originated.
103    pub longitude: Option<f64>,
104
105    /// The state/county/province/region where the payment originated.
106    pub region: Option<String>,
107}
108
109#[derive(Clone, Debug, Default, Deserialize, Serialize)]
110pub struct RadarReviewResourceSession {
111    /// The browser used in this browser session (e.g., `Chrome`).
112    pub browser: Option<String>,
113
114    /// Information about the device used for the browser session (e.g., `Samsung SM-G930T`).
115    pub device: Option<String>,
116
117    /// The platform for the browser session (e.g., `Macintosh`).
118    pub platform: Option<String>,
119
120    /// The version for the browser session (e.g., `61.0.3163.100`).
121    pub version: Option<String>,
122}
123
124/// The parameters for `Review::list`.
125#[derive(Clone, Debug, Serialize, Default)]
126pub struct ListReviews<'a> {
127    #[serde(skip_serializing_if = "Option::is_none")]
128    pub created: Option<RangeQuery<Timestamp>>,
129
130    /// A cursor for use in pagination.
131    ///
132    /// `ending_before` is an object ID that defines your place in the list.
133    /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub ending_before: Option<ReviewId>,
136
137    /// Specifies which fields in the response should be expanded.
138    #[serde(skip_serializing_if = "Expand::is_empty")]
139    pub expand: &'a [&'a str],
140
141    /// A limit on the number of objects to be returned.
142    ///
143    /// Limit can range between 1 and 100, and the default is 10.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub limit: Option<u64>,
146
147    /// A cursor for use in pagination.
148    ///
149    /// `starting_after` is an object ID that defines your place in the list.
150    /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub starting_after: Option<ReviewId>,
153}
154
155impl<'a> ListReviews<'a> {
156    pub fn new() -> Self {
157        ListReviews {
158            created: Default::default(),
159            ending_before: Default::default(),
160            expand: Default::default(),
161            limit: Default::default(),
162            starting_after: Default::default(),
163        }
164    }
165}
166impl Paginable for ListReviews<'_> {
167    type O = Review;
168    fn set_last(&mut self, item: Self::O) {
169        self.starting_after = Some(item.id());
170    }
171}
172/// An enum representing the possible values of an `Review`'s `closed_reason` field.
173#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
174#[serde(rename_all = "snake_case")]
175pub enum ReviewClosedReason {
176    Approved,
177    Disputed,
178    Redacted,
179    Refunded,
180    RefundedAsFraud,
181}
182
183impl ReviewClosedReason {
184    pub fn as_str(self) -> &'static str {
185        match self {
186            ReviewClosedReason::Approved => "approved",
187            ReviewClosedReason::Disputed => "disputed",
188            ReviewClosedReason::Redacted => "redacted",
189            ReviewClosedReason::Refunded => "refunded",
190            ReviewClosedReason::RefundedAsFraud => "refunded_as_fraud",
191        }
192    }
193}
194
195impl AsRef<str> for ReviewClosedReason {
196    fn as_ref(&self) -> &str {
197        self.as_str()
198    }
199}
200
201impl std::fmt::Display for ReviewClosedReason {
202    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
203        self.as_str().fmt(f)
204    }
205}
206impl std::default::Default for ReviewClosedReason {
207    fn default() -> Self {
208        Self::Approved
209    }
210}
211
212/// An enum representing the possible values of an `Review`'s `opened_reason` field.
213#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
214#[serde(rename_all = "snake_case")]
215pub enum ReviewOpenedReason {
216    Manual,
217    Rule,
218}
219
220impl ReviewOpenedReason {
221    pub fn as_str(self) -> &'static str {
222        match self {
223            ReviewOpenedReason::Manual => "manual",
224            ReviewOpenedReason::Rule => "rule",
225        }
226    }
227}
228
229impl AsRef<str> for ReviewOpenedReason {
230    fn as_ref(&self) -> &str {
231        self.as_str()
232    }
233}
234
235impl std::fmt::Display for ReviewOpenedReason {
236    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
237        self.as_str().fmt(f)
238    }
239}
240impl std::default::Default for ReviewOpenedReason {
241    fn default() -> Self {
242        Self::Manual
243    }
244}