delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! A buyer's cases and the evidence they hand in for one.
//!
//! A case is a refund request the buyer sent or a dispute about one of their
//! purchases. The same shapes answer the shop's customer portal and the buyer
//! account. Enumerated values arrive as strings, so a value added later does
//! not break decoding; each field lists the values known today.

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

/// The buyer's cases, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerCaseList {
    /// The cases.
    #[serde(default)]
    pub data: Vec<BuyerCase>,
    /// Whether more cases exist than were returned.
    #[serde(default)]
    pub has_more: bool,
    /// Whether cases of records the buyer has not confirmed were left out.
    #[serde(default)]
    pub unconfirmed_records: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One refund request or dispute, where it stands and who acts next.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerCase {
    /// Case id, as the evidence routes name it.
    pub id: String,
    /// `refund_request` or `dispute`.
    pub kind: String,
    /// `refund_request`, `inquiry`, `dispute`, `bank_chargeback`,
    /// `pre_chargeback_alert` or `unknown`.
    pub category: String,
    /// `buyer_portal`, `payment_provider`, `bank_card_issuer` or `unknown`.
    pub origin: String,
    /// Where the case stands, such as `waiting_for_merchant`, `approved`,
    /// `refunded`, `declined`, `open`, `under_review` or `resolved`.
    pub state: String,
    /// Who acts next: `buyer`, `merchant`, `operator`, `provider`,
    /// `reviewer`, `nobody` or `unknown`.
    pub next_actor: String,
    /// `pending`, `buyer_favour`, `merchant_favour`, `cancelled` or `unknown`.
    pub outcome: String,
    /// The record the case belongs to, on the buyer account.
    #[serde(default)]
    pub record: Option<String>,
    /// The shop the case is with.
    #[serde(default)]
    pub shop: Option<String>,
    /// The shop's name.
    pub shop_name: String,
    /// The purchase the case is about.
    #[serde(default)]
    pub purchase: Option<String>,
    /// The kind of that purchase.
    #[serde(default)]
    pub purchase_kind: Option<String>,
    /// The amount in question, in minor units.
    #[serde(default)]
    pub amount: Option<i64>,
    /// ISO 4217 currency of `amount`.
    #[serde(default)]
    pub currency: Option<String>,
    /// The amount the shop approved, in minor units.
    #[serde(default)]
    pub approved_amount: Option<i64>,
    /// The stated reason.
    #[serde(default)]
    pub reason: Option<String>,
    /// The buyer's message.
    #[serde(default)]
    pub message: Option<String>,
    /// The shop's reply.
    #[serde(default)]
    pub merchant_reply: Option<String>,
    /// The refund the case led to, when one was started.
    #[serde(default)]
    pub refund: Option<BuyerCaseRefund>,
    /// What of the payment can still be refunded.
    #[serde(default)]
    pub refund_balance: Option<BuyerCaseRefundBalance>,
    /// When the shop must answer by.
    #[serde(default)]
    pub merchant_respond_by: Option<String>,
    /// When the case was opened.
    pub created_at: String,
    /// When the case last changed.
    pub updated_at: String,
    /// Whether the case belongs to test mode.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// The recorded steps, oldest first.
    #[serde(default)]
    pub events: Vec<BuyerCaseEvent>,
    /// Whether `events` holds every step, or only the recent ones.
    #[serde(default)]
    pub history_complete: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The refund a case led to.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerCaseRefund {
    /// `pending`, `succeeded` or `failed`.
    pub status: String,
    /// Refunded amount, in minor units.
    pub amount: i64,
    /// ISO 4217 currency of `amount`.
    pub currency: String,
    /// When the refund was started.
    pub created_at: String,
    /// When the refund last changed.
    pub updated_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What of a payment can still be refunded.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerCaseRefundBalance {
    /// Captured amount, in minor units.
    pub captured_amount: i64,
    /// Already refunded, in minor units.
    pub succeeded_refund_amount: i64,
    /// Still refundable, in minor units.
    pub remaining_amount: i64,
    /// ISO 4217 currency of the amounts.
    pub currency: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One recorded step of a case.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerCaseEvent {
    /// When it happened.
    pub at: String,
    /// What happened, such as `opened`, `approved`, `declined`, `refunded`,
    /// `status_changed`, `deadline_changed` or `evidence_submitted`.
    pub kind: String,
    /// Who acted: `buyer`, `merchant`, `operator`, `provider`, `reviewer`,
    /// `nobody` or `unknown`.
    pub actor: String,
    /// The case state after the step.
    #[serde(default)]
    pub state: Option<String>,
    /// Who acts next after the step.
    #[serde(default)]
    pub next_actor: Option<String>,
    /// `inquiry`, `dispute`, `pre_arbitration` or `arbitration`.
    #[serde(default)]
    pub stage: Option<String>,
    /// When the next answer is due.
    #[serde(default)]
    pub respond_by: Option<String>,
    /// Amount the step concerns, in minor units.
    #[serde(default)]
    pub amount: Option<i64>,
    /// ISO 4217 currency of `amount`.
    #[serde(default)]
    pub currency: Option<String>,
    /// When the step was recorded, when that differs from `at`.
    #[serde(default)]
    pub recorded_at: Option<String>,
    /// A due date the step set.
    #[serde(default)]
    pub due_at: Option<String>,
    /// The reviewer's finding, on an `evidence_reviewed` step.
    #[serde(default)]
    pub evidence_outcome: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A case's evidence: what may be handed in and by when, the files saved and
/// handed in, and what the reviewer said.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerEvidence {
    /// Whether the buyer may hand in evidence for this case.
    pub available: bool,
    /// Why not: `not_offered`, `case_not_eligible` or `case_closed`.
    #[serde(default)]
    pub unavailable_reason: Option<String>,
    /// `awaiting_buyer`, `awaiting_review`, `information_requested` or
    /// `reviewed`.
    #[serde(default)]
    pub state: Option<String>,
    /// What a submission may carry.
    #[serde(default)]
    pub rules: Option<BuyerEvidenceRules>,
    /// The buyer's cut-off.
    #[serde(default)]
    pub deadline: Option<BuyerEvidenceDeadline>,
    /// When the review is expected.
    #[serde(default)]
    pub review_target: Option<String>,
    /// The payment provider's own cut-off.
    #[serde(default)]
    pub provider_deadline: Option<String>,
    /// `buyer`, `reviewer` or `nobody`.
    #[serde(default)]
    pub next_actor: Option<String>,
    /// Whether a submission is accepted now.
    #[serde(default)]
    pub can_submit: bool,
    /// Whether more time may be asked for now.
    #[serde(default)]
    pub can_request_extension: bool,
    /// Whether more time was asked for since the cut-off was last set.
    #[serde(default)]
    pub extension_requested: bool,
    /// Who reads the evidence: `delopay` or `delopay_and_shop`.
    #[serde(default)]
    pub audience: Option<String>,
    /// `supports_buyer`, `does_not_support_buyer` or `inconclusive`.
    #[serde(default)]
    pub outcome: Option<String>,
    /// Files uploaded for the case, handed in or not.
    #[serde(default)]
    pub saved_files: Vec<BuyerEvidenceFile>,
    /// Submissions, requests and reviews, oldest first.
    #[serde(default)]
    pub history: Vec<BuyerEvidenceEntry>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a submission may carry.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerEvidenceRules {
    /// Accepted file types: `pdf`, `png`, `jpeg`, `webp`, `text`.
    #[serde(default)]
    pub file_types: Vec<String>,
    /// The most files one submission may carry.
    pub max_files: i32,
    /// The largest file accepted, in bytes.
    pub max_file_bytes: i64,
    /// Whether a submission must carry an explanation.
    pub explanation_required: bool,
    /// The longest explanation accepted, in characters.
    pub explanation_max_chars: i32,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The buyer's cut-off for evidence.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerEvidenceDeadline {
    /// When it falls.
    pub due_at: String,
    /// `initial` or `supplement`.
    pub kind: String,
    /// Whether it has passed.
    pub passed: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A file uploaded for a case.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerEvidenceFile {
    /// File id.
    pub id: String,
    /// The name it was uploaded under.
    pub file_name: String,
    /// `pdf`, `png`, `jpeg`, `webp` or `text`.
    pub file_type: String,
    /// Size in bytes.
    pub size_bytes: i64,
    /// When it was uploaded.
    pub uploaded_at: String,
    /// Whether a submission took it. A submitted file stays.
    pub submitted: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One entry of a case's evidence history.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerEvidenceEntry {
    /// Entry id.
    pub id: String,
    /// `submitted`, `information_requested`, `replied`, `reviewed`,
    /// `deadline_changed`, `extension_requested`, `reviewer_assigned`,
    /// `note`, `reminded` or `reminder_failed`.
    pub kind: String,
    /// `buyer`, `delopay`, `shop` or `system`.
    pub actor: String,
    /// When it happened.
    pub at: String,
    /// The text handed in or written.
    #[serde(default)]
    pub body: Option<String>,
    /// The reason given.
    #[serde(default)]
    pub reason: Option<String>,
    /// The cut-off the entry set.
    #[serde(default)]
    pub due_at: Option<String>,
    /// The cut-off before this entry changed it.
    #[serde(default)]
    pub previous_due_at: Option<String>,
    /// The reviewer's finding, on a `reviewed` entry.
    #[serde(default)]
    pub outcome: Option<String>,
    /// Files handed in with the entry.
    #[serde(default)]
    pub files: Vec<BuyerEvidenceFile>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}