delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! The merchant audit-log models.
//!
//! What a merchant is allowed to see of their own log, which is deliberately
//! less than what the platform records. Two redactions are structural rather
//! than cosmetic, and both are documented on the types that carry them:
//! a DeloPay actor is never named, and a DeloPay session is never described.

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

/// The parties a merchant can see in their own log.
///
/// `"delopay"` covers support acting on the account and the platform itself,
/// deliberately as one value: which of DeloPay's mechanisms it was is not the
/// merchant's question, and splitting it would leak internal structure.
///
/// Open-ended (`String`) rather than an enum, so a party added later reaches
/// the caller as data instead of a deserialization failure. Known values:
/// `"team_member"`, `"api_key"`, `"delopay"`, `"system"`.
pub type MerchantAuditActorKind = String;

/// Which relationship an impersonated change was made under.
///
/// `None` means **unknown** — a row written before this was recorded — which
/// is not the same as `"self_acted"`. Known values: `"self_acted"`,
/// `"admin_for_merchant"`, `"merchant_for_team_member"`.
pub type MerchantAuditImpersonationKind = String;

/// Who acted, as a merchant is allowed to see it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditActorInfo {
    /// `None` for a DeloPay actor: the merchant learns that support acted, not
    /// which employee it was.
    #[serde(default)]
    pub id: Option<String>,
    /// See [`MerchantAuditActorKind`].
    pub kind: MerchantAuditActorKind,
    /// The team member's email, or the label for a non-human actor.
    #[serde(default)]
    pub name: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The sign-in a change was made in.
///
/// Only ever present for the merchant's **own** people. A DeloPay support
/// session carries none: the employee's device, address and city are not the
/// merchant's to read back.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditSessionInfo {
    /// Session id — the grouping key for "everything done in one sign-in".
    pub id: String,
    /// Address the session signed in from.
    #[serde(default)]
    pub ip_address: Option<String>,
    #[serde(default)]
    pub user_agent: Option<String>,
    #[serde(default)]
    pub country_code: Option<String>,
    #[serde(default)]
    pub city: Option<String>,
    /// Approximate — derived from the IP, so a neighbourhood, not an address.
    #[serde(default)]
    pub latitude: Option<f64>,
    /// Approximate, on the same terms as [`latitude`](Self::latitude).
    #[serde(default)]
    pub longitude: Option<f64>,
    #[serde(default)]
    pub auth_method: Option<String>,
    #[serde(default)]
    pub started_at: Option<String>,
    #[serde(default)]
    pub last_seen_at: Option<String>,
    /// Set when the session was ended early.
    #[serde(default)]
    pub revoked_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One recorded change on a merchant's account or one of its shops.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditLogEntry {
    /// Unique entry id, as taken by [`crate::Audit::retrieve`].
    pub id: String,
    /// Who the change is attributed to.
    pub actor: MerchantAuditActorInfo,
    /// The person really acting, when it was one of the merchant's own — an
    /// admin signed in as a team member. `None` when nobody was impersonating,
    /// and also when it was DeloPay: `impersonation_kind` says an admin acted,
    /// and `actor` already says it was DeloPay.
    #[serde(default)]
    pub real_actor: Option<MerchantAuditActorInfo>,
    /// See [`MerchantAuditImpersonationKind`] — `None` is unknown, not
    /// "nobody impersonated".
    #[serde(default)]
    pub impersonation_kind: Option<MerchantAuditImpersonationKind>,
    /// The sign-in the change was made in, where the merchant may see it.
    #[serde(default)]
    pub session: Option<MerchantAuditSessionInfo>,
    /// The shop the change belongs to, when it was shop-scoped.
    #[serde(default)]
    pub profile_id: Option<String>,
    /// What was done, e.g. `"update"`.
    pub action: String,
    /// What it was done to, e.g. `"business_profile"`.
    pub entity_type: String,
    #[serde(default)]
    pub entity_id: Option<String>,
    /// What the entity was called. `None` when it has since been deleted.
    #[serde(default)]
    pub entity_name: Option<String>,
    /// Which fields the change touched. Names only, never values — the raw
    /// payload can carry connector credentials, so it is never forwarded.
    #[serde(default)]
    pub changed_fields: Vec<String>,
    /// ISO 8601 timestamp of the change.
    pub created_at: String,
    /// For a change to one setting: its key and its value before and after.
    #[serde(default)]
    pub setting_change: Option<MerchantAuditSettingChange>,
    /// The change line by line, where the entry records it.
    #[serde(default)]
    pub changes: Option<Vec<AuditChange>>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A change to one setting, as an audit entry records it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditSettingChange {
    /// The setting's key.
    pub key: String,
    /// Whether a value was stored before the change.
    pub was_set: bool,
    /// Whether a value is stored after the change; `false` when it was
    /// cleared.
    pub is_set: bool,
    /// The value before the change; `None` when none was stored.
    #[serde(default)]
    pub old_value: Option<Value>,
    /// The value after the change; `None` when it was cleared.
    #[serde(default)]
    pub new_value: Option<Value>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One line of an audited change.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct AuditChange {
    /// `"added"`, `"removed"`, `"replaced"`, `"changed"`, `"moved"` or
    /// `"reordered"`.
    pub op: String,
    /// `live` or `test`, on a checkout layout change.
    #[serde(default)]
    pub environment: Option<String>,
    /// Where: a layout tier, or `shops` / `payment_methods` on a connector
    /// account.
    #[serde(default)]
    pub group: Option<String>,
    /// The field that changed, for `changed` and `moved`.
    #[serde(default)]
    pub field: Option<String>,
    /// The item the line is about.
    #[serde(default)]
    pub item: Option<AuditChangeItem>,
    /// The item it replaced, for `replaced`.
    #[serde(default)]
    pub previous_item: Option<AuditChangeItem>,
    /// The value before.
    #[serde(default)]
    pub old_value: Option<Value>,
    /// The value after.
    #[serde(default)]
    pub new_value: Option<Value>,
    /// `true` when the values are secret and were not recorded.
    #[serde(default)]
    pub withheld: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What one line of an audited change is about.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct AuditChangeItem {
    /// `method`, `card`, `heading`, `general` or `account`.
    #[serde(default)]
    pub kind: Option<String>,
    /// The payment method.
    #[serde(default)]
    pub method: Option<String>,
    /// The connector.
    #[serde(default)]
    pub connector: Option<String>,
    /// The connector account.
    #[serde(default)]
    pub merchant_connector_id: Option<String>,
    /// The capability.
    #[serde(default)]
    pub capability: Option<String>,
    /// The preset.
    #[serde(default)]
    pub preset: Option<String>,
    /// The merchant's own label for the tile or the account.
    #[serde(default)]
    pub label: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One page of a merchant's audit log.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct MerchantAuditLogListResponse {
    /// The page, newest first.
    pub entries: Vec<MerchantAuditLogEntry>,
    /// How many entries the filter matched in total, which is what makes
    /// paging terminable without probing for the end.
    pub total_count: i64,
    /// Offset this page was read at.
    pub offset: i64,
    /// Page size this page was read with.
    pub limit: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}