delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! PayPal seller case models.
//!
//! A *seller case* is PayPal's own dispute record, which exists for sales this
//! platform never processed — external and subscription sales included — so it
//! is kept apart from [`DisputeResponse`](crate::core::models::dispute::DisputeResponse),
//! the processor-agnostic dispute raised against a DeloPay payment.
//!
//! Money arrives as a decimal **string** in the case's own currency, exactly as
//! PayPal reports it: parsing it into a float here would round a figure a
//! seller is about to argue about.

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

/// A seller action PayPal offers on a case.
///
/// `"send_message"`, `"make_offer"`, `"accept_claim"`, `"provide_evidence"`,
/// `"appeal"`, `"escalate"`, `"acknowledge_return_item"`,
/// `"provide_supporting_info"` and `"update_communication"`.
///
/// Read the case's [`available_actions`](PaypalDisputeCase::available_actions)
/// rather than assuming: which actions exist depends on the case's stage, and
/// PayPal withdraws them as it moves.
pub type PaypalDisputeAction = String;

/// One PayPal seller case.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeCase {
    /// PayPal's case id.
    pub case_id: String,
    /// The dispute id as the connector reports it.
    #[serde(default)]
    pub connector_dispute_id: Option<String>,
    /// The connector account the case was read with.
    #[serde(default)]
    pub merchant_connector_id: Option<String>,
    /// The shop the case maps to, when it maps to one.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The DeloPay payment the case maps to. `None` for a sale this platform
    /// never processed — an external or subscription sale — which is the
    /// reason these cases have their own surface.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// The payment attempt the case maps to.
    #[serde(default)]
    pub attempt_id: Option<String>,
    /// PayPal's invoice id for the sale, when it carries one.
    #[serde(default)]
    pub invoice_id: Option<String>,
    /// The PayPal seller account the case belongs to.
    #[serde(default)]
    pub seller_id: Option<String>,
    /// PayPal transaction ids the case covers.
    #[serde(default = "Vec::new")]
    pub transaction_ids: Vec<String>,
    /// Which environment the case was read from.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// PayPal's own status for the case, verbatim.
    #[serde(default)]
    pub status: Option<String>,
    /// PayPal's own stage for the case, verbatim.
    #[serde(default)]
    pub stage: Option<String>,
    /// The buyer's stated reason.
    #[serde(default)]
    pub reason: Option<String>,
    /// PayPal's code for that reason.
    #[serde(default)]
    pub reason_code: Option<String>,
    /// The disputed amount, as a decimal string in
    /// [`currency`](Self::currency).
    #[serde(default)]
    pub amount: Option<String>,
    /// Three-letter ISO 4217 currency of [`amount`](Self::amount).
    #[serde(default)]
    pub currency: Option<String>,
    /// When the seller must answer by (RFC 3339). **The deadline that costs
    /// money**: past it PayPal decides without the seller.
    #[serde(default)]
    pub seller_response_due_date: Option<String>,
    /// When the buyer must answer by (RFC 3339).
    #[serde(default)]
    pub buyer_response_due_date: Option<String>,
    /// When PayPal opened the case (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// When this record was last refreshed from PayPal (RFC 3339).
    #[serde(default)]
    pub updated_at: Option<String>,
    /// How the case ended, once it has.
    #[serde(default)]
    pub outcome: Option<String>,
    /// The actions PayPal currently offers on this case. An action absent here
    /// is refused, so drive the buttons from this list rather than from the
    /// stage.
    #[serde(default = "Vec::new")]
    pub available_actions: Vec<PaypalDisputeAction>,
    /// How many PayPal webhooks have been delivered for the case.
    #[serde(default)]
    pub webhook_delivery_count: Option<i64>,
    /// The provider event this record was last written from.
    #[serde(default)]
    pub provider_event_id: Option<String>,
    /// PayPal's full case document, verbatim.
    #[serde(default)]
    pub details: Option<Value>,
    /// Who opened the case: `"payment_provider"`, `"bank_card_issuer"` or
    /// `"unknown"`. `None` on older records.
    #[serde(default)]
    pub origin: Option<String>,
    /// What kind of case it is: `"inquiry"`, `"dispute"`,
    /// `"bank_chargeback"`, `"pre_chargeback_alert"` or `"unknown"`. `None`
    /// on older records.
    #[serde(default)]
    pub category: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A page of cases imported from PayPal.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeImportResponse {
    /// The cases this page imported.
    #[serde(default = "Vec::new")]
    pub cases: Vec<PaypalDisputeCase>,
    /// The token for the next page. `None` means the import is complete —
    /// stop, rather than re-sending the last token.
    #[serde(default)]
    pub next_page_token: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a seller action did.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeActionResponse {
    /// The request id the action was deduplicated on.
    #[serde(default)]
    pub request_id: Option<String>,
    /// What PayPal answered.
    ///
    /// An **unknown** outcome means the action's effect could not be
    /// established: reconcile the case — re-read it with a forced sync — rather
    /// than sending the action again under a new request id, which is how a
    /// case ends up conceded twice.
    #[serde(default)]
    pub outcome: Option<String>,
    /// The case as it stands after the action.
    #[serde(default)]
    pub case: Option<PaypalDisputeCase>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One action already taken on a case.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaypalDisputeActionRecord {
    /// The request id the action was sent under.
    #[serde(default)]
    pub request_id: Option<String>,
    /// Which action it was.
    #[serde(default)]
    pub action: Option<String>,
    /// What PayPal answered.
    #[serde(default)]
    pub outcome: Option<String>,
    /// Who sent it, when the record names an actor.
    #[serde(default)]
    pub actor: Option<String>,
    /// When it was sent (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// The request body as it was sent.
    #[serde(default)]
    pub request: Option<Value>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A document attached to, or downloaded from, a case.
///
/// The bytes travel base64-encoded in [`data_base64`](Self::data_base64), so a
/// caller that wants the file must decode it. Evidence can be large: keep it
/// out of logs.
#[derive(Debug, Clone, Deserialize, serde::Serialize)]
pub struct PaypalDisputeDocument {
    /// File name, as PayPal knows it.
    pub name: String,
    /// The file's media type.
    pub content_type: String,
    /// The file's bytes, base64-encoded.
    pub data_base64: String,
}