delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! Refund requests buyers raise from the customer portal, and the results of
//! blocking the buyers of refunds in bulk.

use std::fmt;

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

use crate::core::models::dispute_workspace::DisputeBulkBlockedIdentifier;

/// A buyer's refund request.
///
/// The buyer's message is personal data: `Debug` prints `<redacted>` in its
/// place.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerRefundRequest {
    /// The request's id.
    pub id: String,
    /// The payment the buyer wants refunded.
    pub payment_id: String,
    /// The payment's shop.
    pub profile_id: String,
    /// The buyer.
    pub customer_id: String,
    /// `payment` for a one-off purchase, `renewal` for a subscription renewal.
    pub purchase_kind: String,
    /// `not_received`, `not_as_described`, `duplicate`, `cancelled_order` or
    /// `other`.
    pub reason: String,
    /// What the buyer wrote.
    pub message: String,
    /// The amount the buyer asked for, in minor units.
    pub amount: i64,
    /// Three-letter ISO 4217 currency code.
    pub currency: String,
    /// `requested`, `approved` or `declined`.
    pub status: String,
    /// The refund that approved the request.
    #[serde(default)]
    pub refund_id: Option<String>,
    /// The approved refund's amount, in minor units.
    #[serde(default)]
    pub approved_amount: Option<i64>,
    /// What the shop told the buyer.
    #[serde(default)]
    pub merchant_reply: Option<String>,
    /// The dashboard user or API key that decided.
    #[serde(default)]
    pub decided_by: Option<String>,
    /// Whether the request is a test request.
    pub test_mode: bool,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// ISO 8601 decision timestamp.
    #[serde(default)]
    pub decided_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

impl fmt::Debug for BuyerRefundRequest {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("BuyerRefundRequest")
            .field("id", &self.id)
            .field("payment_id", &self.payment_id)
            .field("profile_id", &self.profile_id)
            .field("customer_id", &self.customer_id)
            .field("purchase_kind", &self.purchase_kind)
            .field("reason", &self.reason)
            .field("message", &"<redacted>")
            .field("amount", &self.amount)
            .field("currency", &self.currency)
            .field("status", &self.status)
            .field("refund_id", &self.refund_id)
            .field("approved_amount", &self.approved_amount)
            .field("merchant_reply", &self.merchant_reply)
            .field("decided_by", &self.decided_by)
            .field("test_mode", &self.test_mode)
            .field("created_at", &self.created_at)
            .field("decided_at", &self.decided_at)
            .finish_non_exhaustive()
    }
}

/// One page of refund requests, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerRefundRequestList {
    /// The requests on this page.
    #[serde(default)]
    pub data: Vec<BuyerRefundRequest>,
    /// Every request matching the filters.
    pub total_count: i64,
    /// The page size applied.
    pub limit: i64,
    /// The offset applied.
    pub offset: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One identifier a block of a refund's buyer would name.
///
/// The identifier's value is personal data: `Debug` prints `<redacted>` in its
/// place.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct RefundBulkIdentifier {
    /// The identifier's kind, for example `email`, `ip` or `device_id`.
    pub kind: String,
    /// The identifier's value.
    pub value: String,
    /// The shop the entry would block in, or `None` for every shop.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// Where it was seen: `payment`, `paying_browser` or `seen`.
    pub source: String,
    /// Whether an entry already blocks it.
    pub already_blocked: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

impl fmt::Debug for RefundBulkIdentifier {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("RefundBulkIdentifier")
            .field("kind", &self.kind)
            .field("value", &"<redacted>")
            .field("profile_id", &self.profile_id)
            .field("source", &self.source)
            .field("already_blocked", &self.already_blocked)
            .finish_non_exhaustive()
    }
}

/// One selected refund's buyer, as a block would name them.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct RefundBulkBuyer {
    /// The refund.
    pub refund_id: String,
    /// The refund's payment.
    pub payment_id: String,
    /// The payment's shop.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// Every identifier a block would name.
    #[serde(default)]
    pub identifiers: Vec<RefundBulkIdentifier>,
    /// Identifiers left out of `identifiers` for length.
    #[serde(default)]
    pub omitted_count: i64,
    /// Why the buyer could not be read, when it could not.
    #[serde(default)]
    pub error_code: Option<String>,
    /// The matching error message.
    #[serde(default)]
    pub error_message: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a bulk block of refunds' buyers would name. Nothing was changed.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct RefundBulkBlockPreviewResponse {
    /// How many refunds were selected.
    pub selected_count: i64,
    /// Each found refund's buyer.
    #[serde(default)]
    pub refunds: Vec<RefundBulkBuyer>,
    /// The listed refund ids that were not found.
    #[serde(default)]
    pub not_found: Vec<String>,
    /// Whether more than `max_refunds` matched, so only the first were read.
    pub truncated: bool,
    /// The most refunds a preview reads.
    pub max_refunds: i64,
    /// The most refunds one bulk block acts on.
    pub max_run_refunds: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One refund's result of a bulk buyer block.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct RefundBulkBlockResult {
    /// The refund.
    pub refund_id: String,
    /// The refund's payment.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// `blocked`, `already_blocked`, `skipped` or `failed`.
    pub outcome: String,
    /// Why a skipped refund was left out: `not_found`, `no_identifiers` or
    /// `already_blocked`.
    #[serde(default)]
    pub reason: Option<String>,
    /// The identifiers the block named.
    #[serde(default)]
    pub identifiers: Vec<DisputeBulkBlockedIdentifier>,
    /// The error code of a failed refund.
    #[serde(default)]
    pub error_code: Option<String>,
    /// The error message of a failed refund.
    #[serde(default)]
    pub error_message: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Every refund's result of a bulk buyer block.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct RefundBulkBlockBuyerResponse {
    /// One result per listed refund.
    #[serde(default)]
    pub results: Vec<RefundBulkBlockResult>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}