delopay 0.2.1

Official Rust SDK for the DeloPay payments API
Documentation
//! Shared value types used across resources.
//!
//! The large open vocabularies (currency, intent status, payment method) are
//! kept as `String` on purpose: the backend evolves them frequently, and a
//! closed Rust enum would reject a brand-new value and break deserialization.
//! Small, stable vocabularies are modeled as real enums.

use serde::{Deserialize, Serialize};

/// Three-letter ISO 4217 currency code, e.g. `"EUR"`, `"USD"`.
pub type Currency = String;

/// Lifecycle status of a payment intent, e.g. `"requires_payment_method"`,
/// `"requires_confirmation"`, `"processing"`, `"succeeded"`, `"failed"`.
pub type IntentStatus = String;

/// Payment method family, e.g. `"card"`, `"wallet"`, `"bank_redirect"`.
pub type PaymentMethod = String;

/// Payment method sub-type, e.g. `"credit"`, `"apple_pay"`, `"eps"`.
pub type PaymentMethodType = String;

/// How and when funds are captured.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CaptureMethod {
    /// Capture automatically on authorization.
    Automatic,
    /// Authorize now, capture later (via the `payments` resource `capture` call).
    Manual,
}

/// Whether to request 3-D Secure authentication.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AuthenticationType {
    /// Request 3-D Secure.
    ThreeDs,
    /// Do not request 3-D Secure.
    NoThreeDs,
}

/// Whether to save the payment method for future use.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SetupFutureUsage {
    /// Charge later without the customer present (recurring).
    OffSession,
    /// Reuse while the customer is present.
    OnSession,
}

/// Inline customer details, used when creating a customer on-the-fly on a payment.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct CustomerInfo {
    /// Existing customer ID, when reusing one.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    /// Customer name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Customer email address.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<String>,
    /// Customer phone number.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub phone: Option<String>,
    /// Customer phone country code, e.g. `"+1"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub phone_country_code: Option<String>,
}

/// Status of a refund, e.g. `"succeeded"`, `"pending"`, `"failed"`, `"review"`.
pub type RefundStatus = String;
/// Status of a mandate, e.g. `"active"`, `"revoked"`.
pub type MandateStatus = String;
/// Dispute lifecycle stage, e.g. `"dispute"`, `"pre_dispute"`, `"pre_arbitration"`.
pub type DisputeStage = String;
/// Dispute status, e.g. `"dispute_opened"`, `"dispute_won"`, `"dispute_lost"`.
pub type DisputeStatus = String;
/// Payout status, e.g. `"success"`, `"failed"`, `"pending"`.
pub type PayoutStatus = String;
/// Payout method family, e.g. `"card"`, `"bank"`, `"wallet"`.
pub type PayoutType = String;
/// Status of a payment attempt, e.g. `"charged"`, `"failure"`, `"pending"`.
pub type AttemptStatus = String;
/// Subscription lifecycle status, e.g. `"active"`, `"paused"`, `"cancelled"`.
pub type SubscriptionStatus = String;
/// Status of a subscription invoice, e.g. `"invoice_paid"`, `"payment_failed"`.
pub type InvoiceStatus = String;
/// Billing interval unit for a subscription price. Capitalized on the wire:
/// `"Day"`, `"Week"`, `"Month"`, `"Year"`.
pub type SubscriptionPeriodUnit = String;
/// Status of an asynchronous poll, e.g. `"pending"`, `"completed"`, `"not_found"`.
pub type PollStatus = String;

/// Refund processing type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RefundType {
    /// Refund immediately.
    Instant,
    /// Schedule the refund.
    Scheduled,
}

/// Generic paginated list envelope: `{ "data": [...], "size"?, "total_count"? }`.
///
/// Any additional envelope fields are preserved in [`extra`](ListResponse::extra).
#[derive(Debug, Clone, Deserialize)]
pub struct ListResponse<T> {
    /// The page of items.
    #[serde(default = "Vec::new")]
    pub data: Vec<T>,
    /// Number of items in this page, when the API reports it.
    #[serde(default)]
    pub size: Option<i64>,
    /// Total number of matching items, when the API reports it.
    #[serde(default)]
    pub total_count: Option<i64>,
    /// Any additional envelope fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, serde_json::Value>,
}

/// Street-address details.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct AddressDetails {
    /// Address line 1.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub line1: Option<String>,
    /// Address line 2.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub line2: Option<String>,
    /// Address line 3.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub line3: Option<String>,
    /// City / town.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub city: Option<String>,
    /// State / province / region.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state: Option<String>,
    /// Postal / ZIP code.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub zip: Option<String>,
    /// Two-letter ISO 3166 country code, e.g. `"DE"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<String>,
    /// First name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub first_name: Option<String>,
    /// Last name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_name: Option<String>,
}

/// A phone number split into national number + country code.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct PhoneDetails {
    /// National phone number (digits).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub number: Option<String>,
    /// Dialing country code, e.g. `"+49"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country_code: Option<String>,
}

/// A billing or shipping address: street details, phone, and email.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Address {
    /// Street-address details.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub address: Option<AddressDetails>,
    /// Phone number.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub phone: Option<PhoneDetails>,
    /// Contact email.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<String>,
}