tap_msg/message/
reject.rs

1//! Reject message type for the Transaction Authorization Protocol.
2//!
3//! This module defines the Reject message type, which is used
4//! for rejecting transactions in the TAP protocol.
5
6use serde::{Deserialize, Serialize};
7
8use crate::error::{Error, Result};
9use crate::TapMessage;
10
11/// Reject message body (TAIP-4).
12#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
13#[tap(message_type = "https://tap.rsvp/schema/1.0#Reject")]
14pub struct Reject {
15    /// ID of the transaction being rejected.
16    #[tap(thread_id)]
17    pub transaction_id: String,
18
19    /// Reason for rejection.
20    pub reason: String,
21}
22
23impl Reject {
24    /// Create a new Reject message
25    pub fn new(transaction_id: &str, reason: &str) -> Self {
26        Self {
27            transaction_id: transaction_id.to_string(),
28            reason: reason.to_string(),
29        }
30    }
31}
32
33impl Reject {
34    /// Custom validation for Reject messages
35    pub fn validate_reject(&self) -> Result<()> {
36        if self.transaction_id.is_empty() {
37            return Err(Error::Validation(
38                "Transaction ID is required in Reject".to_string(),
39            ));
40        }
41
42        if self.reason.is_empty() {
43            return Err(Error::Validation(
44                "Reason is required in Reject".to_string(),
45            ));
46        }
47
48        Ok(())
49    }
50}