use crate::config::{Client, Response};
use crate::ids::ReviewId;
use crate::params::{Expand, Expandable, List, Object, RangeQuery, Timestamp};
use crate::resources::{Charge, PaymentIntent};
use serde_derive::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Review {
pub id: ReviewId,
#[serde(skip_serializing_if = "Option::is_none")]
pub billing_zip: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub charge: Option<Expandable<Charge>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub closed_reason: Option<ReviewClosedReason>,
pub created: Timestamp,
#[serde(skip_serializing_if = "Option::is_none")]
pub ip_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ip_address_location: Option<RadarReviewResourceLocation>,
pub livemode: bool,
pub open: bool,
pub opened_reason: ReviewOpenedReason,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_intent: Option<Expandable<PaymentIntent>>,
pub reason: ReviewReason,
#[serde(skip_serializing_if = "Option::is_none")]
pub session: Option<RadarReviewResourceSession>,
}
impl Review {
pub fn list(client: &Client, params: ListReviews<'_>) -> Response<List<Review>> {
client.get_query("/reviews", ¶ms)
}
pub fn retrieve(client: &Client, id: &ReviewId, expand: &[&str]) -> Response<Review> {
client.get_query(&format!("/reviews/{}", id), &Expand { expand })
}
}
impl Object for Review {
type Id = ReviewId;
fn id(&self) -> Self::Id {
self.id.clone()
}
fn object(&self) -> &'static str {
"review"
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RadarReviewResourceLocation {
#[serde(skip_serializing_if = "Option::is_none")]
pub city: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub country: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub latitude: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub longitude: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RadarReviewResourceSession {
#[serde(skip_serializing_if = "Option::is_none")]
pub browser: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub device: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub platform: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
#[derive(Clone, Debug, Serialize, Default)]
pub struct ListReviews<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<RangeQuery<Timestamp>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<ReviewId>,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<ReviewId>,
}
impl<'a> ListReviews<'a> {
pub fn new() -> Self {
ListReviews {
created: Default::default(),
ending_before: Default::default(),
expand: Default::default(),
limit: Default::default(),
starting_after: Default::default(),
}
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ReviewClosedReason {
Approved,
Disputed,
Refunded,
RefundedAsFraud,
}
impl ReviewClosedReason {
pub fn as_str(self) -> &'static str {
match self {
ReviewClosedReason::Approved => "approved",
ReviewClosedReason::Disputed => "disputed",
ReviewClosedReason::Refunded => "refunded",
ReviewClosedReason::RefundedAsFraud => "refunded_as_fraud",
}
}
}
impl AsRef<str> for ReviewClosedReason {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for ReviewClosedReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ReviewOpenedReason {
Manual,
Rule,
}
impl ReviewOpenedReason {
pub fn as_str(self) -> &'static str {
match self {
ReviewOpenedReason::Manual => "manual",
ReviewOpenedReason::Rule => "rule",
}
}
}
impl AsRef<str> for ReviewOpenedReason {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for ReviewOpenedReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ReviewReason {
Approved,
Disputed,
Manual,
Refunded,
RefundedAsFraud,
Rule,
}
impl ReviewReason {
pub fn as_str(self) -> &'static str {
match self {
ReviewReason::Approved => "approved",
ReviewReason::Disputed => "disputed",
ReviewReason::Manual => "manual",
ReviewReason::Refunded => "refunded",
ReviewReason::RefundedAsFraud => "refunded_as_fraud",
ReviewReason::Rule => "rule",
}
}
}
impl AsRef<str> for ReviewReason {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for ReviewReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}