tap_msg/message/
authorize.rs1use serde::{Deserialize, Serialize};
7
8use crate::error::{Error, Result};
9use crate::TapMessage;
10
11#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
13#[tap(message_type = "https://tap.rsvp/schema/1.0#Authorize")]
14pub struct Authorize {
15 #[tap(thread_id)]
17 pub transaction_id: String,
18
19 #[serde(rename = "settlementAddress", skip_serializing_if = "Option::is_none")]
23 pub settlement_address: Option<String>,
24
25 #[serde(skip_serializing_if = "Option::is_none")]
29 pub expiry: Option<String>,
30}
31
32impl Authorize {
33 pub fn new(transaction_id: &str) -> Self {
35 Self {
36 transaction_id: transaction_id.to_string(),
37 settlement_address: None,
38 expiry: None,
39 }
40 }
41
42 pub fn with_settlement_address(transaction_id: &str, settlement_address: &str) -> Self {
44 Self {
45 transaction_id: transaction_id.to_string(),
46 settlement_address: Some(settlement_address.to_string()),
47 expiry: None,
48 }
49 }
50
51 pub fn with_all(
53 transaction_id: &str,
54 settlement_address: Option<&str>,
55 expiry: Option<&str>,
56 ) -> Self {
57 Self {
58 transaction_id: transaction_id.to_string(),
59 settlement_address: settlement_address.map(|s| s.to_string()),
60 expiry: expiry.map(|s| s.to_string()),
61 }
62 }
63}
64
65impl Authorize {
66 pub fn validate_authorize(&self) -> Result<()> {
68 if self.transaction_id.is_empty() {
69 return Err(Error::Validation(
70 "Transaction ID is required in Authorize".to_string(),
71 ));
72 }
73
74 Ok(())
75 }
76}