delopay 0.4.0

Official Rust SDK for the DeloPay payments API
Documentation
//! Project models: the project itself and the merchant-level aggregates
//! returned by the project stats and overview endpoints.

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

use crate::core::models::shop::{CurrencyRevenue, ShopStats};

/// A project — an optional grouping layer that contains one or more shops.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectResponse {
    /// Unique project ID (the API field is `id`, not `project_id`).
    pub id: String,
    /// Merchant account that owns this project.
    pub merchant_id: String,
    /// Display name of the project.
    pub project_name: String,
    /// Whether the project is active.
    pub is_active: bool,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// ISO 8601 last-modification timestamp.
    pub modified_at: String,

    /// Free-form description.
    #[serde(default)]
    pub description: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Order and revenue figures for one project, plus its shops.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectStats {
    /// The project these figures belong to.
    pub project_id: String,
    /// Display name of the project.
    pub project_name: String,
    /// Number of successful orders in the window.
    pub orders: i64,
    /// Raw cross-currency minor-unit sum — do not display. Use
    /// [`revenue_usd`](Self::revenue_usd) or
    /// [`revenue_by_currency`](Self::revenue_by_currency).
    pub revenue: i64,
    /// FX-converted revenue in USD major units.
    pub revenue_usd: f64,
    /// Revenue split by the currency it was taken in.
    #[serde(default)]
    pub revenue_by_currency: Vec<CurrencyRevenue>,
    /// Orders left out of `revenue_usd` for want of a fresh USD rate.
    pub unconverted_orders: i64,
    /// Per-shop breakdown for the shops grouped under this project.
    #[serde(default)]
    pub shops: Vec<ShopStats>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Aggregate payment statistics across all of a merchant's projects, as
/// returned by the `projects.stats` endpoint.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProjectStatsResponse {
    /// Per-project breakdown.
    #[serde(default)]
    pub projects: Vec<ProjectStats>,
    /// Every shop of the merchant, including shops that belong to no project —
    /// those never appear under `projects[].shops`, since projects are an
    /// optional grouping layer. Look a single shop up here rather than walking
    /// the project tree.
    #[serde(default)]
    pub shops: Vec<ShopStats>,
    /// Total number of successful orders in the window.
    pub total_orders: i64,
    /// Raw cross-currency minor-unit sum — do not display. Use
    /// [`total_revenue_usd`](Self::total_revenue_usd).
    pub total_revenue: i64,
    /// FX-converted total revenue in USD major units.
    pub total_revenue_usd: f64,
    /// Total revenue split by the currency it was taken in.
    #[serde(default)]
    pub total_revenue_by_currency: Vec<CurrencyRevenue>,
    /// Orders left out of `total_revenue_usd` for want of a fresh USD rate.
    pub unconverted_orders: i64,
    /// Window the figures cover, in days. `None` when an all-time total was
    /// asked for.
    #[serde(default)]
    pub period_days: Option<i64>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One headline figure on the merchant overview, with its period-over-period
/// change.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantOverviewStat {
    /// Human-readable label for the figure.
    pub label: String,
    /// The figure itself.
    pub value: f64,
    /// Change against the previous window, in percent.
    pub change_percent: f64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// High-level merchant overview, as returned by the `projects.overview`
/// endpoint.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantOverviewResponse {
    /// Total number of shops.
    pub total_shops: MerchantOverviewStat,
    /// Number of active shops.
    pub active_shops: MerchantOverviewStat,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}