delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! Export envelopes and the rows they carry.
//!
//! An export is **one read, never a paged walk**, and it is bounded: 25 000
//! rows, 500 for a PDF. Over the bound the request is refused with
//! `DE_07 export_row_limit_exceeded` naming the entity and the limit — a
//! truncated finance file answered with a `200` is the thing these endpoints
//! exist not to produce.

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

/// A JSON export: the rows, how many there are, and the filters they were
/// produced under.
///
/// [`filters`](Self::filters) echoes what the server actually applied, so a
/// file can be shown beside the question it answers rather than beside the
/// question the caller believes it asked.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ExportEnvelope<T> {
    /// The exported rows.
    #[serde(default = "Vec::new")]
    pub records: Vec<T>,
    /// How many rows the file holds.
    #[serde(default)]
    pub record_count: Option<i64>,
    /// The filters the export ran under, as the server resolved them.
    #[serde(default)]
    pub filters: Option<Value>,
    /// Any additional envelope fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One row of a transaction export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct TransactionExportRecord {
    /// The payment.
    pub payment_id: String,
    /// The merchant account it belongs to.
    #[serde(default)]
    pub merchant_id: Option<String>,
    /// The shop it belongs to.
    #[serde(default)]
    pub shop_id: Option<String>,
    /// The payment's status.
    #[serde(default)]
    pub status: Option<String>,
    /// Amount in minor units.
    #[serde(default)]
    pub amount: Option<i64>,
    /// Three-letter ISO 4217 currency code.
    #[serde(default)]
    pub currency: Option<String>,
    /// When the payment was created (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// The payment's environment. `None` when it never recorded one, which
    /// is not the same as `false`; a file can span both environments.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// Where the active attempt's money has got to, as the rail reports it.
    /// Present only on the merchant-level export.
    #[serde(default)]
    pub connector_settlement_status: Option<String>,
    /// Any additional row fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One row of a transaction line export: one per product line a payment
/// recorded, and one with `row_kind == "no_lines"` for each payment that
/// recorded none, so every payment of the per-payment export is present.
///
/// [`payment_amount`](Self::payment_amount) is set on each payment's **first
/// row only** and `None` on its further rows, so it sums to exactly what the
/// per-payment export's `amount` sums to for the same filters. The line
/// figures are in the line's own [`currency`](Self::currency) and need not
/// add up to the payment amount.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct TransactionLineExportRecord {
    /// The payment.
    pub payment_id: String,
    /// The merchant account it belongs to.
    pub merchant_id: String,
    /// The shop it belongs to.
    #[serde(default)]
    pub shop_id: Option<String>,
    /// When the payment was created (ISO 8601, UTC).
    #[serde(default)]
    pub created_at: Option<String>,
    /// The payment's status.
    pub status: String,
    /// The payment's environment. `None` when it never recorded one.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// The payment amount in minor units, on the payment's first row only.
    #[serde(default)]
    pub payment_amount: Option<i64>,
    /// The payment's currency.
    #[serde(default)]
    pub payment_currency: Option<String>,
    /// `"line"`, or `"no_lines"` for a payment without product lines. New
    /// kinds may be added.
    pub row_kind: String,
    /// The line's ID.
    #[serde(default)]
    pub line_id: Option<String>,
    /// The line's place in the payment, from 0.
    #[serde(default)]
    pub position: Option<i64>,
    /// The line an add-on or component belongs to.
    #[serde(default)]
    pub parent_line_id: Option<String>,
    /// `"product"`, `"addon"`, `"bundle"` or `"component"`.
    #[serde(default)]
    pub line_role: Option<String>,
    /// The catalog product the line resolved to.
    #[serde(default)]
    pub product_id: Option<String>,
    /// The product's name as it read when the payment was made.
    #[serde(default)]
    pub product_name: Option<String>,
    /// The name the caller used, when it was not the product's own.
    #[serde(default)]
    pub product_alias: Option<String>,
    /// Whether the line resolved to a catalog product; `false` on a
    /// `no_lines` row.
    #[serde(default)]
    pub attributed: bool,
    /// Units bought.
    #[serde(default)]
    pub quantity: Option<i64>,
    /// Unit price in minor units of `currency`.
    #[serde(default)]
    pub unit_amount: Option<i64>,
    /// `unit_amount × quantity`, in minor units of `currency`.
    #[serde(default)]
    pub line_total: Option<i64>,
    /// The line's own currency.
    #[serde(default)]
    pub currency: Option<String>,
    /// The tax rate as the caller reported it. `None` is not zero.
    #[serde(default)]
    pub tax_rate: Option<f64>,
    /// The tax amount in minor units of `currency`, as the caller reported
    /// it. `None` is not zero.
    #[serde(default)]
    pub tax_amount: Option<i64>,
    /// Any additional row fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One row of a refund export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct RefundExportRecord {
    /// The refund.
    pub refund_id: String,
    /// The payment it refunds.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// The shop it belongs to.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The refund's status.
    #[serde(default)]
    pub status: Option<String>,
    /// Amount in minor units.
    #[serde(default)]
    pub amount: Option<i64>,
    /// Three-letter ISO 4217 currency code.
    #[serde(default)]
    pub currency: Option<String>,
    /// The stated reason.
    #[serde(default)]
    pub reason: Option<String>,
    /// The connector that processed it.
    #[serde(default)]
    pub connector: Option<String>,
    /// Connector error code, when it failed.
    #[serde(default)]
    pub error_code: Option<String>,
    /// Connector error message, when it failed.
    #[serde(default)]
    pub error_message: Option<String>,
    /// When it was created (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// When it was last updated (RFC 3339).
    #[serde(default)]
    pub updated_at: Option<String>,
    /// Any additional row fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One row of a dispute export.
///
/// [`amount`](Self::amount) is a decimal **string**, as the dispute records it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct DisputeExportRecord {
    /// The dispute.
    pub dispute_id: String,
    /// The payment it was raised against.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// The attempt it was raised against.
    #[serde(default)]
    pub attempt_id: Option<String>,
    /// The shop it belongs to.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The dispute's lifecycle stage.
    #[serde(default)]
    pub dispute_stage: Option<String>,
    /// The dispute's status.
    #[serde(default)]
    pub dispute_status: Option<String>,
    /// Disputed amount, as a decimal string.
    #[serde(default)]
    pub amount: Option<String>,
    /// Three-letter ISO 4217 currency code.
    #[serde(default)]
    pub currency: Option<String>,
    /// The connector that reported it.
    #[serde(default)]
    pub connector: Option<String>,
    /// The connector's own status, verbatim.
    #[serde(default)]
    pub connector_status: Option<String>,
    /// The connector's own dispute id.
    #[serde(default)]
    pub connector_dispute_id: Option<String>,
    /// The connector's stated reason.
    #[serde(default)]
    pub connector_reason: Option<String>,
    /// The connector's code for that reason.
    #[serde(default)]
    pub connector_reason_code: Option<String>,
    /// Deadline to challenge (RFC 3339).
    #[serde(default)]
    pub challenge_required_by: Option<String>,
    /// When it was created (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// Any additional row fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One row of a payout export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PayoutExportRecord {
    /// The payout.
    pub payout_id: String,
    /// The shop it belongs to.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The customer paid out to.
    #[serde(default)]
    pub customer_id: Option<String>,
    /// The payout's status.
    #[serde(default)]
    pub status: Option<String>,
    /// Amount in minor units.
    #[serde(default)]
    pub amount: Option<i64>,
    /// Three-letter ISO 4217 currency code.
    #[serde(default)]
    pub currency: Option<String>,
    /// The payout's type.
    #[serde(default)]
    pub payout_type: Option<String>,
    /// The connector that processed it.
    #[serde(default)]
    pub connector: Option<String>,
    /// Connector error code, when it failed.
    #[serde(default)]
    pub error_code: Option<String>,
    /// Connector error message, when it failed.
    #[serde(default)]
    pub error_message: Option<String>,
    /// The merchant's own reference for the order.
    #[serde(default)]
    pub merchant_order_reference_id: Option<String>,
    /// When it was created (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// Any additional row fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One row of a subscription export.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SubscriptionExportRecord {
    /// The subscription.
    pub id: String,
    /// The merchant's own reference for it.
    #[serde(default)]
    pub merchant_reference_id: Option<String>,
    /// The shop it belongs to.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// The customer it bills.
    #[serde(default)]
    pub customer_id: Option<String>,
    /// The subscription's status.
    #[serde(default)]
    pub status: Option<String>,
    /// The plan it runs on.
    #[serde(default)]
    pub plan_id: Option<String>,
    /// The price it runs on.
    #[serde(default)]
    pub item_price_id: Option<String>,
    /// The coupon applied, when one is.
    #[serde(default)]
    pub coupon_code: Option<String>,
    /// Which environment it runs in.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// Any additional row fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One row of a merchant audit-log export.
///
/// The `real_actor_*` and `impersonation_kind` fields are what separate "the
/// user did this" from "somebody acting as that user did this": render the
/// real actor wherever one is present.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditLogExportRecord {
    /// When the change was recorded (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// What kind of actor made it.
    #[serde(default)]
    pub actor_kind: Option<String>,
    /// The acting user's id, as the log recorded it.
    #[serde(default)]
    pub actor_id: Option<String>,
    /// The acting user's name.
    #[serde(default)]
    pub actor_name: Option<String>,
    /// The person behind an impersonated session, when there was one.
    #[serde(default)]
    pub real_actor_id: Option<String>,
    /// That person's name.
    #[serde(default)]
    pub real_actor_name: Option<String>,
    /// What kind of impersonation it was, when it was one.
    #[serde(default)]
    pub impersonation_kind: Option<String>,
    /// The sign-in the change happened in.
    #[serde(default)]
    pub session_id: Option<String>,
    /// The address the change came from.
    #[serde(default)]
    pub ip_address: Option<String>,
    /// The client that made it.
    #[serde(default)]
    pub user_agent: Option<String>,
    /// The shop the change was scoped to.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// What was done.
    #[serde(default)]
    pub action: Option<String>,
    /// What kind of thing it was done to.
    #[serde(default)]
    pub entity_type: Option<String>,
    /// Which one.
    #[serde(default)]
    pub entity_id: Option<String>,
    /// Its name at the time.
    #[serde(default)]
    pub entity_name: Option<String>,
    /// The fields that changed, as the log renders them.
    #[serde(default)]
    pub changed_fields: Option<String>,
    /// Any additional row fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}