delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! Whop Resolution Center cases: a buyer's claim before any chargeback, read
//! live from Whop through one connector account.
//!
//! The buyer's name, username and email are personal data: `Debug` on
//! [`WhopResolutionCase`] prints `<redacted>` in their place.

use std::fmt;

use serde::Deserialize;
use serde_json::Value;

/// A Whop resolution case as Whop reports it now.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct WhopResolutionCase {
    /// Whop's case id.
    pub case_id: String,
    /// The Whop connector account the case was read through.
    pub merchant_connector_id: String,
    /// Whether the case was read through the sandbox credentials.
    pub test_mode: bool,
    /// The shop of the case's payment, when matched.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The DeloPay payment, when matched.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// The DeloPay payment attempt, when matched.
    #[serde(default)]
    pub attempt_id: Option<String>,
    /// Whop's payment id.
    pub connector_payment_id: String,
    /// For example `awaiting_merchant`, `awaiting_customer`, `under_review` or
    /// `closed`.
    pub status: String,
    /// The buyer's reason.
    #[serde(default)]
    pub reason: Option<String>,
    /// How the case ended, once closed.
    #[serde(default)]
    pub outcome: Option<String>,
    /// The refund Whop made, if any.
    #[serde(default)]
    pub refund: Option<String>,
    /// Whether the case was escalated.
    #[serde(default)]
    pub escalated: bool,
    /// Whether the buyer appealed.
    #[serde(default)]
    pub customer_appealed: bool,
    /// The amount, as a decimal string.
    #[serde(default)]
    pub amount: Option<String>,
    /// Three-letter ISO 4217 currency code.
    #[serde(default)]
    pub currency: Option<String>,
    /// When the merchant must answer by, ISO 8601.
    #[serde(default)]
    pub response_due_at: Option<String>,
    /// ISO 8601 creation timestamp.
    #[serde(default)]
    pub created_at: Option<String>,
    /// ISO 8601 last-update timestamp.
    #[serde(default)]
    pub updated_at: Option<String>,
    /// Whop's product id.
    #[serde(default)]
    pub product_id: Option<String>,
    /// Whop's plan id.
    #[serde(default)]
    pub plan_id: Option<String>,
    /// The payment method type.
    #[serde(default)]
    pub payment_method_type: Option<String>,
    /// The card brand, for a card payment.
    #[serde(default)]
    pub card_brand: Option<String>,
    /// The card's last four digits, for a card payment.
    #[serde(default)]
    pub card_last4: Option<String>,
    /// The buyer's name.
    #[serde(default)]
    pub buyer_name: Option<String>,
    /// The buyer's Whop username.
    #[serde(default)]
    pub buyer_username: Option<String>,
    /// The buyer's email address.
    #[serde(default)]
    pub buyer_email: Option<String>,
    /// `accept`, `deny`, `reply` and `request_info`, as the case allows now.
    #[serde(default)]
    pub available_actions: Vec<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

impl fmt::Debug for WhopResolutionCase {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("WhopResolutionCase")
            .field("case_id", &self.case_id)
            .field("merchant_connector_id", &self.merchant_connector_id)
            .field("test_mode", &self.test_mode)
            .field("profile_id", &self.profile_id)
            .field("payment_id", &self.payment_id)
            .field("attempt_id", &self.attempt_id)
            .field("connector_payment_id", &self.connector_payment_id)
            .field("status", &self.status)
            .field("reason", &self.reason)
            .field("outcome", &self.outcome)
            .field("refund", &self.refund)
            .field("escalated", &self.escalated)
            .field("customer_appealed", &self.customer_appealed)
            .field("amount", &self.amount)
            .field("currency", &self.currency)
            .field("response_due_at", &self.response_due_at)
            .field("created_at", &self.created_at)
            .field("updated_at", &self.updated_at)
            .field("product_id", &self.product_id)
            .field("plan_id", &self.plan_id)
            .field("payment_method_type", &self.payment_method_type)
            .field("card_brand", &self.card_brand)
            .field("card_last4", &self.card_last4)
            .field(
                "buyer_name",
                &self.buyer_name.as_ref().map(|_| "<redacted>"),
            )
            .field(
                "buyer_username",
                &self.buyer_username.as_ref().map(|_| "<redacted>"),
            )
            .field(
                "buyer_email",
                &self.buyer_email.as_ref().map(|_| "<redacted>"),
            )
            .field("available_actions", &self.available_actions)
            .finish_non_exhaustive()
    }
}

/// One page of Whop cases, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct WhopResolutionCaseList {
    /// The cases on this page.
    #[serde(default)]
    pub cases: Vec<WhopResolutionCase>,
    /// Pass as `cursor` to read the next page; `None` on the last.
    #[serde(default)]
    pub next_cursor: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A file attached to a case event.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct WhopResolutionCaseAttachment {
    /// Whop's attachment id.
    pub id: String,
    /// The file name.
    #[serde(default)]
    pub filename: Option<String>,
    /// The file's media type.
    #[serde(default)]
    pub content_type: Option<String>,
    /// Where Whop serves the file.
    #[serde(default)]
    pub url: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One event of a case's timeline.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct WhopResolutionCaseEvent {
    /// Whop's event id.
    pub event_id: String,
    /// What happened.
    pub action: String,
    /// Who reported it.
    pub reporter_type: String,
    /// The event's text.
    #[serde(default)]
    pub details: Option<String>,
    /// Whether the buyer sees the event.
    #[serde(default)]
    pub viewable_by_customer: bool,
    /// ISO 8601 timestamp.
    #[serde(default)]
    pub created_at: Option<String>,
    /// Files attached to the event.
    #[serde(default)]
    pub attachments: Vec<WhopResolutionCaseAttachment>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One page of a case's timeline, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct WhopResolutionCaseEventList {
    /// The events on this page.
    #[serde(default)]
    pub events: Vec<WhopResolutionCaseEvent>,
    /// Pass as `cursor` to read the next page; `None` on the last.
    #[serde(default)]
    pub next_cursor: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The result of an action on a case.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct WhopResolutionCaseActionResponse {
    /// The request id the action was sent under.
    pub request_id: String,
    /// The action taken.
    pub action: String,
    /// `submitted`, or `unknown` when Whop's answer was lost: retry with the
    /// same `request_id`.
    pub outcome: String,
    /// The case after the action.
    pub case: WhopResolutionCase,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}