delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
//! Conversations between a buyer and a shop's team.
//!
//! There is one conversation per buyer, shop and mode. The buyer side (the
//! shop's customer portal and the buyer account) and the team side (the
//! dashboard inbox) see the same conversation through different shapes.
//!
//! `Debug` on the team-side summary prints no buyer name or email address.

use std::fmt;

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

use crate::core::models::buyer_case::BuyerCaseEvent;

/// A file a message carries, or one uploaded for the next message.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationAttachment {
    /// File id, named in a message's `attachments`.
    pub id: String,
    /// The name it was uploaded under.
    pub file_name: String,
    /// `pdf`, `png`, `jpeg`, `webp` or `text`.
    pub file_type: String,
    /// Size in bytes.
    pub size_bytes: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The shop's rules for files on messages.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationAttachmentRules {
    /// Whether messages may carry files at all.
    pub enabled: bool,
    /// Accepted file types: `pdf`, `png`, `jpeg`, `webp`, `text`.
    #[serde(default)]
    pub file_types: Vec<String>,
    /// The largest file accepted, in megabytes.
    pub max_file_megabytes: i32,
    /// The most files one message may carry.
    pub max_files: i32,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One of the buyer's conversations, as the buyer sees it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalConversation {
    /// Conversation id.
    pub id: String,
    /// The record the conversation belongs to, on the buyer account.
    #[serde(default)]
    pub record: Option<String>,
    /// The shop, as the message routes name it in `shop`.
    pub shop: String,
    /// The shop's name.
    pub shop_name: String,
    /// Whether the conversation belongs to test mode.
    pub test_mode: bool,
    /// `open` or `closed`.
    pub status: String,
    /// When the latest message was sent.
    pub last_message_at: String,
    /// Who sent it: `buyer` or `merchant`.
    pub last_message_by: String,
    /// Whether the buyer has messages they have not read.
    pub unread: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The buyer's conversations, the latest message first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalConversationList {
    /// The conversations.
    #[serde(default)]
    pub data: Vec<BuyerPortalConversation>,
    /// Whether conversations of records the buyer has not confirmed were
    /// left out.
    #[serde(default)]
    pub unconfirmed_records: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One message, as the buyer sees it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalMessage {
    /// Message id.
    pub id: String,
    /// `buyer` or `merchant`.
    pub sender: String,
    /// The first name of the team member who answered.
    #[serde(default)]
    pub sender_name: Option<String>,
    /// The text. May be empty when the message carries files.
    pub body: String,
    /// The purchase the message is about.
    #[serde(default)]
    pub purchase: Option<String>,
    /// The kind of that purchase.
    #[serde(default)]
    pub purchase_kind: Option<String>,
    /// Files the message carries.
    #[serde(default)]
    pub attachments: Vec<BuyerConversationAttachment>,
    /// When it was sent.
    pub created_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A step of one of the buyer's cases, shown in the conversation.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerCaseUpdate {
    /// The case id.
    pub case: String,
    /// `refund_request` or `dispute`.
    pub kind: String,
    /// The step.
    pub event: BuyerCaseEvent,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The conversation with one shop and its newest messages, oldest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalMessagePage {
    /// The conversation, once one exists.
    #[serde(default)]
    pub conversation: Option<BuyerPortalConversation>,
    /// The messages, oldest first.
    #[serde(default)]
    pub messages: Vec<BuyerPortalMessage>,
    /// Whether older messages exist; page back with `before`.
    #[serde(default)]
    pub has_more: bool,
    /// Steps of the buyer's cases at the shop.
    #[serde(default)]
    pub case_updates: Vec<BuyerCaseUpdate>,
    /// The shop's rules for files on messages.
    pub attachment_rules: BuyerConversationAttachmentRules,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One conversation in the team's inbox.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationSummary {
    /// Conversation id.
    pub id: String,
    /// The shop.
    pub profile_id: String,
    /// The buyer.
    pub customer_id: String,
    /// The buyer's name.
    #[serde(default)]
    pub customer_name: Option<String>,
    /// The buyer's email address.
    #[serde(default)]
    pub customer_email: Option<String>,
    /// Whether the conversation belongs to test mode.
    pub test_mode: bool,
    /// `open` or `closed`.
    pub status: String,
    /// The team member it is assigned to.
    #[serde(default)]
    pub assigned_user_id: Option<String>,
    /// That team member's name.
    #[serde(default)]
    pub assigned_user_name: Option<String>,
    /// Whether it is assigned to the caller.
    #[serde(default)]
    pub assigned_to_me: bool,
    /// When the latest message was sent.
    pub last_message_at: String,
    /// Who sent it: `buyer` or `merchant`.
    pub last_message_by: String,
    /// Whether the team has messages it has not read.
    pub unread: bool,
    /// When the conversation started.
    pub created_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

impl fmt::Debug for BuyerConversationSummary {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("BuyerConversationSummary")
            .field("id", &self.id)
            .field("profile_id", &self.profile_id)
            .field("customer_id", &self.customer_id)
            .field(
                "customer_name",
                &self.customer_name.as_ref().map(|_| "<redacted>"),
            )
            .field(
                "customer_email",
                &self.customer_email.as_ref().map(|_| "<redacted>"),
            )
            .field("test_mode", &self.test_mode)
            .field("status", &self.status)
            .field("assigned_user_id", &self.assigned_user_id)
            .field("assigned_to_me", &self.assigned_to_me)
            .field("last_message_at", &self.last_message_at)
            .field("last_message_by", &self.last_message_by)
            .field("unread", &self.unread)
            .field("created_at", &self.created_at)
            .finish_non_exhaustive()
    }
}

/// One page of the team's inbox, the latest message first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationList {
    /// The conversations.
    #[serde(default)]
    pub data: Vec<BuyerConversationSummary>,
    /// How many conversations match the filters, over all pages.
    pub total_count: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One message, as the team sees it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationMessage {
    /// Message id.
    pub id: String,
    /// `buyer` or `merchant`.
    pub sender: String,
    /// The first name the buyer sees for the team member who answered.
    #[serde(default)]
    pub sender_name: Option<String>,
    /// The team member who answered.
    #[serde(default)]
    pub sender_user_id: Option<String>,
    /// The text. May be empty when the message carries files.
    pub body: String,
    /// The purchase the message is about.
    #[serde(default)]
    pub purchase: Option<String>,
    /// The kind of that purchase.
    #[serde(default)]
    pub purchase_kind: Option<String>,
    /// Files the message carries.
    #[serde(default)]
    pub attachments: Vec<BuyerConversationAttachment>,
    /// When it was sent.
    pub created_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A team member's internal note. The buyer never sees one.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationNote {
    /// Note id.
    pub id: String,
    /// The team member who wrote it.
    pub author_user_id: String,
    /// That team member's name.
    #[serde(default)]
    pub author_name: Option<String>,
    /// The text.
    pub body: String,
    /// When it was written.
    pub created_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A step of a case of the buyer at the shop, shown in the conversation.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationCaseUpdate {
    /// `refund_request`, `dispute`, `paypal_case` or `subscription_dispute`.
    pub source: String,
    /// The id of the request or dispute.
    pub source_id: String,
    /// The payment it concerns.
    #[serde(default)]
    pub payment_id: Option<String>,
    /// The step.
    pub event: BuyerCaseEvent,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One conversation and its newest messages, oldest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationDetail {
    /// The conversation.
    pub conversation: BuyerConversationSummary,
    /// The messages, oldest first.
    #[serde(default)]
    pub messages: Vec<BuyerConversationMessage>,
    /// Whether older messages exist; page back with `before`.
    #[serde(default)]
    pub has_more: bool,
    /// Steps of the buyer's cases at the shop.
    #[serde(default)]
    pub case_updates: Vec<BuyerConversationCaseUpdate>,
    /// The team's internal notes.
    #[serde(default)]
    pub notes: Vec<BuyerConversationNote>,
    /// The shop's rules for files on answers.
    pub attachment_rules: BuyerConversationAttachmentRules,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}