delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! Payment log models: the traffic of one payment, that is the requests sent
//! to the payment provider, the webhooks the provider sent, and the webhooks
//! sent to the shop with every delivery attempt.
//!
//! Every body and header is masked by the API before it is returned.

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

/// The traffic of a payment, oldest first, without payloads.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogsResponse {
    /// The payment these entries belong to.
    pub payment_id: String,
    /// Whether requests to the payment provider and its webhooks are recorded
    /// for this payment's merchant right now.
    pub psp_traffic_recorded: bool,
    /// `true` when the caller's role may not see processor details; provider
    /// requests and provider webhooks are then left out.
    pub processor_details_hidden: bool,
    /// How many days provider requests are kept.
    pub connector_call_retention_days: i32,
    /// How many days provider webhooks are kept.
    pub incoming_webhook_retention_days: i32,
    /// Requests sent to the payment provider, oldest first.
    #[serde(default)]
    pub connector_calls: Vec<PaymentLogConnectorCall>,
    /// `true` when there were more provider requests than were returned.
    pub connector_calls_truncated: bool,
    /// Webhooks the payment provider sent about this payment, oldest first.
    #[serde(default)]
    pub incoming_webhooks: Vec<PaymentLogIncomingWebhook>,
    /// `true` when there were more provider webhooks than were returned.
    pub incoming_webhooks_truncated: bool,
    /// Webhooks sent to the shop about this payment and its refunds and
    /// disputes, oldest first.
    #[serde(default)]
    pub outgoing_webhooks: Vec<PaymentLogOutgoingWebhook>,
    /// `true` when there were more shop webhooks than were returned.
    pub outgoing_webhooks_truncated: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One request sent to the payment provider.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogConnectorCall {
    /// The identifier of this recorded request.
    pub id: String,
    /// ISO 8601 time the request was sent.
    pub started_at: String,
    /// The payment provider.
    pub connector: String,
    /// What the request did, such as `Authorize`, `Capture`, `PSync` or
    /// `Execute` (a refund).
    pub flow: String,
    /// The HTTP method.
    pub method: String,
    /// The provider URL the request was sent to.
    pub url: String,
    /// The HTTP status the provider answered with. `0` when no answer
    /// arrived.
    pub status_code: i32,
    /// How long the provider took to answer, in milliseconds.
    pub latency_ms: i64,
    /// The payment attempt the request was made for.
    #[serde(default)]
    pub attempt_id: Option<String>,
    /// The refund the request was made for.
    #[serde(default)]
    pub refund_id: Option<String>,
    /// The dispute the request was made for.
    #[serde(default)]
    pub dispute_id: Option<String>,
    /// The API request that made this call.
    pub request_id: String,
    /// Whether the request went to the provider's test environment. `None`
    /// when unknown.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// `true` when the call recorded an error.
    pub has_error: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One webhook the payment provider sent.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogIncomingWebhook {
    /// The identifier of this recorded delivery.
    pub event_id: String,
    /// ISO 8601 time it was received.
    pub received_at: String,
    /// The payment provider.
    pub connector: String,
    /// The provider's identifier for the event.
    #[serde(default)]
    pub provider_event_id: Option<String>,
    /// The provider's name for the event, such as
    /// `payment_intent.succeeded`.
    #[serde(default)]
    pub provider_event_type: Option<String>,
    /// The event the provider's event was understood as.
    #[serde(default)]
    pub mapped_event_type: Option<String>,
    /// The kind of object the event was about.
    #[serde(default)]
    pub object_type: Option<String>,
    /// The provider's identifier for that object.
    #[serde(default)]
    pub object_ref_id: Option<String>,
    /// The payment attempt the event was matched to.
    #[serde(default)]
    pub resolved_attempt_id: Option<String>,
    /// Whether the signature was verified. `None` when the delivery stopped
    /// before verification.
    #[serde(default)]
    pub source_verified: Option<bool>,
    /// What was done with it: `applied`, `ignored`, `duplicate`, `rejected`,
    /// `dropped`, `error` or `unrecognised`.
    pub outcome: String,
    /// More about the outcome, where recorded.
    #[serde(default)]
    pub outcome_detail: Option<String>,
    /// The HTTP status the provider was answered with.
    pub response_status: i32,
    /// How long the answer took, in milliseconds.
    pub latency_ms: i32,
    /// Whether the event came from the provider's test environment. `None`
    /// when unknown.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One webhook sent to the shop, with every delivery attempt.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogOutgoingWebhook {
    /// The identifier of the first delivery, shared by every retry.
    pub initial_attempt_id: String,
    /// The event that was sent, e.g. `payment_succeeded`.
    pub event_type: String,
    /// The object the event was about: this payment, or one of its refunds
    /// or disputes.
    pub object_id: String,
    /// ISO 8601 time the event was created.
    pub created_at: String,
    /// Whether one of the attempts was delivered. `None` while unknown.
    #[serde(default)]
    pub is_delivery_successful: Option<bool>,
    /// Why delivery stopped: `endpoint_rejected`, `retries_exhausted` or
    /// `no_webhook_url`.
    #[serde(default)]
    pub delivery_terminal_reason: Option<String>,
    /// Whether the event was routed as a test-mode event. `None` when
    /// unknown.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// Every delivery attempt, oldest first.
    #[serde(default)]
    pub attempts: Vec<PaymentLogOutgoingAttempt>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One delivery attempt of a shop webhook, as listed.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogOutgoingAttempt {
    /// The identifier of this attempt.
    pub event_id: String,
    /// ISO 8601 time the attempt was made.
    pub created_at: String,
    /// `initial_attempt`, `automatic_retry`, `manual_retry` or
    /// `manual_trigger`.
    #[serde(default)]
    pub delivery_attempt: Option<String>,
    /// Whether the shop's endpoint accepted it.
    pub is_webhook_notified: bool,
    /// The HTTP status the shop answered with. `None` when no answer
    /// arrived.
    #[serde(default)]
    pub status_code: Option<i32>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One provider request of a payment, with its masked request, response and
/// error.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogConnectorCallDetail {
    /// The request as listed.
    pub call: PaymentLogConnectorCall,
    /// The request body as sent, masked. A string when the body was not
    /// JSON; `None` when nothing was recorded.
    #[serde(default)]
    pub request: Option<Value>,
    /// The response body as received, masked. `None` when nothing was
    /// recorded.
    #[serde(default)]
    pub response: Option<Value>,
    /// The error recorded for the call, masked. `None` when there was none.
    #[serde(default)]
    pub error: Option<Value>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One provider webhook of a payment, with its masked headers and body.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogIncomingWebhookDetail {
    /// The webhook as listed.
    pub webhook: PaymentLogIncomingWebhook,
    /// The headers as received, masked. Credential headers were removed
    /// before storage; signature headers are kept.
    #[serde(default)]
    pub headers: Option<Value>,
    /// The body as received, masked.
    #[serde(default)]
    pub body: Option<Value>,
    /// Which secret verified the signature and whether the object matched.
    /// Never the secret itself.
    #[serde(default)]
    pub verification_detail: Option<Value>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Every delivery attempt of one shop webhook, with request and response.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogOutgoingWebhookDetail {
    /// The identifier of the first delivery, shared by every retry.
    pub initial_attempt_id: String,
    /// Every delivery attempt, oldest first.
    #[serde(default)]
    pub attempts: Vec<PaymentLogOutgoingDelivery>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One delivery attempt of a shop webhook, with what was sent and answered.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogOutgoingDelivery {
    /// The identifier of this attempt.
    pub event_id: String,
    /// ISO 8601 time the attempt was made.
    pub created_at: String,
    /// `initial_attempt`, `automatic_retry`, `manual_retry` or
    /// `manual_trigger`.
    #[serde(default)]
    pub delivery_attempt: Option<String>,
    /// Whether the shop's endpoint accepted it.
    pub is_webhook_notified: bool,
    /// The headers sent.
    #[serde(default)]
    pub request_headers: Vec<PaymentLogHeader>,
    /// The body sent, masked: parsed JSON where it is JSON, otherwise a
    /// string.
    #[serde(default)]
    pub request_body: Option<Value>,
    /// The HTTP status the shop answered with. `None` when no answer
    /// arrived.
    #[serde(default)]
    pub response_status_code: Option<i32>,
    /// The headers the shop answered with.
    #[serde(default)]
    pub response_headers: Vec<PaymentLogHeader>,
    /// The body the shop answered with, masked. `None` when there was none.
    #[serde(default)]
    pub response_body: Option<Value>,
    /// Why the delivery failed, when it did before an answer arrived.
    #[serde(default)]
    pub error_message: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One recorded HTTP header.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PaymentLogHeader {
    /// The header name.
    pub name: String,
    /// The header value, or a mask.
    pub value: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}