delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! A customer's identity history: every email address, name and handle a
//! customer has been known by, with where it came from.
//!
//! Values are personal data. `Debug` on these types prints none of them, so a
//! response logged with `{:?}` does not carry a buyer's email into the log.

use std::fmt;

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

/// What became of one import row.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum CustomerIdentityImportOutcome {
    /// The value is new for this customer, kind and source label.
    Accepted,
    /// The customer already holds the value from the same source label.
    Unchanged,
    /// The row was refused; `reason` says why.
    Rejected,
    /// An outcome this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// One row's result, in the order the rows were sent.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerIdentityImportRowResult {
    /// The row's position in the request, from 0.
    pub row_index: u32,
    /// Your reference for the row, as sent.
    pub external_ref: String,
    #[serde(default)]
    pub customer_id: Option<String>,
    /// `email`, `name` or `handle`.
    #[serde(default)]
    pub kind: Option<String>,
    pub outcome: CustomerIdentityImportOutcome,
    /// Why a rejected row was refused, for example `invalid_customer_id`,
    /// `not_an_email`, `placeholder` or `customer_erased`.
    #[serde(default)]
    pub reason: Option<String>,
    /// The history entry the row maps to, once recorded.
    #[serde(default)]
    pub entry_id: Option<String>,
    /// How many other customers already hold the same value, stored or in an
    /// earlier row of the request. Only on an accepted or unchanged row of a
    /// preview or a first import.
    #[serde(default)]
    pub other_customers: Option<u32>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What an import would do. Nothing was written.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerIdentityImportPreviewResponse {
    pub rows_total: u32,
    pub rows_accepted: u32,
    pub rows_unchanged: u32,
    /// Rows refused by their content. A customer erased since cannot be seen
    /// here; the import refuses its rows with `customer_erased`.
    pub rows_rejected: u32,
    /// Distinct customer ids among the acceptable rows that have no customer
    /// yet. Their values are recorded under the id all the same.
    #[serde(default)]
    pub customers_without_record: u32,
    /// Acceptable rows whose value other customers hold too.
    #[serde(default)]
    pub rows_with_other_customers: u32,
    pub rows: Vec<CustomerIdentityImportRowResult>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// An import run and its rows.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerIdentityImportResponse {
    pub run_id: String,
    pub idempotency_key: String,
    /// `true` when this answers a repeated request and nothing was written.
    pub replayed: bool,
    pub rows_total: u32,
    pub rows_accepted: u32,
    pub rows_unchanged: u32,
    pub rows_rejected: u32,
    /// ISO 8601.
    pub created_at: String,
    /// Acceptable rows whose value other customers hold too. Only on a first
    /// import, not on a replay or a readback.
    #[serde(default)]
    pub rows_with_other_customers: Option<u32>,
    pub rows: Vec<CustomerIdentityImportRowResult>,
    /// The history entries the run's rows map to, as they stand now. Only on
    /// the readback (`Customers::retrieve_identity_import`).
    #[serde(default)]
    pub entries: Option<Vec<CustomerIdentityEntry>>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One value a customer has been known by, from one origin.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerIdentityEntry {
    pub id: String,
    pub customer_id: String,
    /// `email`, `name` or `handle`.
    pub kind: String,
    /// The value as first recorded.
    pub value: String,
    /// The value normalised as the import compares it.
    pub normalized_value: String,
    /// `import`, `psp`, `merchant_request` or `profile`.
    pub source: String,
    pub source_label: String,
    /// The processor's verdict on the payer's account, when it reported one.
    #[serde(default)]
    pub account_status: Option<String>,
    #[serde(default)]
    pub first_source_ref: Option<String>,
    #[serde(default)]
    pub last_source_ref: Option<String>,
    /// ISO 8601, when known.
    #[serde(default)]
    pub first_seen_at: Option<String>,
    /// ISO 8601, when known.
    #[serde(default)]
    pub last_seen_at: Option<String>,
    #[serde(default)]
    pub seen_count: u32,
    /// When the entry was first recorded, ISO 8601.
    pub recorded_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

impl fmt::Debug for CustomerIdentityEntry {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("CustomerIdentityEntry")
            .field("id", &self.id)
            .field("customer_id", &self.customer_id)
            .field("kind", &self.kind)
            .field("value", &"<redacted>")
            .field("normalized_value", &"<redacted>")
            .field("source", &self.source)
            .field("source_label", &self.source_label)
            .field("account_status", &self.account_status)
            .field("seen_count", &self.seen_count)
            .field("recorded_at", &self.recorded_at)
            .finish_non_exhaustive()
    }
}

/// The history of the customers asked for, or a search's matches.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerIdentityHistoryResponse {
    pub entries: Vec<CustomerIdentityEntry>,
    /// Search only: `true` when more entries match than were returned: a match
    /// past `limit`, or the candidate limit was reached. By customer, only the
    /// candidate limit; further pages are `next_cursor`.
    #[serde(default)]
    pub truncated: Option<bool>,
    /// Search by customer only: this page's customers.
    #[serde(default)]
    pub customers: Option<Vec<CustomerIdentityMatch>>,
    /// Search by customer only: how many customers match.
    #[serde(default)]
    pub total_customers: Option<u32>,
    /// Search by customer only: the `cursor` of the next page; absent on the
    /// last.
    #[serde(default)]
    pub next_cursor: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One customer's matching values in a search answered by customer.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CustomerIdentityMatch {
    pub customer_id: String,
    /// The customer's matching entries, newest first.
    pub entries: Vec<CustomerIdentityEntry>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}