delopay 0.2.0

Official Rust SDK for the DeloPay payments API
Documentation
//! The payment intent model.

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

use crate::core::models::common::{
    AttemptStatus, Currency, IntentStatus, PaymentMethod, PaymentMethodType,
};

/// A payment intent as returned by the API.
///
/// Unmodeled fields are preserved in [`extra`](PaymentResponse::extra) so new
/// API fields never break deserialization.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentResponse {
    /// Unique payment intent ID.
    pub payment_id: String,
    /// Merchant account ID that owns this payment.
    pub merchant_id: String,
    /// Current lifecycle status.
    pub status: IntentStatus,
    /// Authorized amount in minor units.
    pub amount: i64,
    /// Three-letter ISO 4217 currency code.
    pub currency: Currency,

    /// Net amount after discounts and tax, in minor units.
    #[serde(default)]
    pub net_amount: Option<i64>,
    /// Amount still available to capture, in minor units.
    #[serde(default)]
    pub amount_capturable: Option<i64>,
    /// Actual captured amount, in minor units (present after capture).
    #[serde(default)]
    pub amount_received: Option<i64>,
    /// Client secret for client-side confirmation (do not log or share).
    #[serde(default)]
    pub client_secret: Option<String>,
    /// Connector used to process this payment.
    #[serde(default)]
    pub connector: Option<String>,
    /// Associated customer ID.
    #[serde(default)]
    pub customer_id: Option<String>,
    /// Shop (business profile) ID.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// Payment method family used.
    #[serde(default)]
    pub payment_method: Option<PaymentMethod>,
    /// Gateway error code, if the payment failed.
    #[serde(default)]
    pub error_code: Option<String>,
    /// Human-readable error message, if the payment failed.
    #[serde(default)]
    pub error_message: Option<String>,
    /// Instructions for additional customer action (3DS redirect, etc.).
    #[serde(default)]
    pub next_action: Option<Value>,
    /// ISO 8601 creation timestamp.
    #[serde(default)]
    pub created: Option<String>,
    /// Arbitrary metadata.
    #[serde(default)]
    pub metadata: Option<Value>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A single attempt made on a payment, with its full failure detail. Returned
/// in the `data` array of `Payments::list_attempts` — useful for surfacing
/// retries across connectors (e.g. "attempt 1 stripe → insufficient_funds,
/// attempt 2 adyen → success").
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentAttemptResponse {
    /// Unique identifier for this attempt.
    pub attempt_id: String,
    /// Status of this attempt (distinct from the parent intent's status).
    pub status: AttemptStatus,

    /// Attempt amount in minor units.
    #[serde(default)]
    pub amount: Option<i64>,
    /// Three-letter ISO 4217 currency code.
    #[serde(default)]
    pub currency: Option<Currency>,
    /// Connector (gateway) this attempt was routed to, e.g. `"stripe"`.
    #[serde(default)]
    pub connector: Option<String>,
    /// Connector's transaction identifier for this attempt.
    #[serde(default)]
    pub connector_transaction_id: Option<String>,
    /// Payment method family used for this attempt.
    #[serde(default)]
    pub payment_method: Option<PaymentMethod>,
    /// Payment method sub-type used for this attempt.
    #[serde(default)]
    pub payment_method_type: Option<PaymentMethodType>,
    /// Raw connector error code, when the attempt failed.
    #[serde(default)]
    pub error_code: Option<String>,
    /// Human-readable error message, when the attempt failed.
    #[serde(default)]
    pub error_message: Option<String>,
    /// Delopay-unified decline code (from the gateway status map).
    #[serde(default)]
    pub unified_code: Option<String>,
    /// Delopay-unified, human-readable decline message.
    #[serde(default)]
    pub unified_message: Option<String>,
    /// When the attempt was created (RFC 3339).
    #[serde(default)]
    pub created_at: Option<String>,
    /// When the attempt was last modified (RFC 3339).
    #[serde(default)]
    pub modified_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}