swift_mt_message/messages/
mt900.rs

1use crate::fields::*;
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::{SwiftMessage, serde_swift_fields};
4
5/// # MT900: Confirmation of Debit
6///
7/// This message is used by a financial institution to confirm to another financial institution
8/// that a debit has been made to the sender's account held with the receiver, or that
9/// the sender's account held with a third party has been debited. This message serves
10/// as official confirmation of debit transactions and facilitates reconciliation between
11/// financial institutions.
12///
13/// ## Key Features
14/// - **Debit confirmation**: Official confirmation of debit transactions
15/// - **Account reconciliation**: Facilitates reconciliation between institutions
16/// - **Audit trail**: Creates audit records for debit transactions
17/// - **Settlement confirmation**: Confirms settlement debits
18/// - **Liquidity management**: Account balance change notifications
19///
20/// ## Field Structure
21/// All fields follow the enhanced macro system with proper validation rules.
22/// The message provides comprehensive debit transaction confirmation capabilities.
23///
24/// ## Usage Guidelines
25/// Used for ad-hoc confirmations of significant debit transactions requiring confirmation,
26/// exception cases for problem resolution, and when audit trail documentation is required.
27#[serde_swift_fields]
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
29#[validation_rules(MT900_VALIDATION_RULES)]
30pub struct MT900 {
31    /// **Transaction Reference Number** - Field 20
32    ///
33    /// Unique sender's reference identifying this specific debit confirmation.
34    /// Used throughout the confirmation lifecycle for tracking, reconciliation, and audit.
35    /// Must be unique within the sender's system per business day.
36    #[field("20", mandatory)]
37    pub field_20: GenericReferenceField,
38
39    /// **Related Reference** - Field 21
40    ///
41    /// Reference to the original transaction or message that resulted in this debit.
42    /// Critical for linking the confirmation back to the initiating transaction
43    /// and maintaining complete audit trails.
44    #[field("21", mandatory)]
45    pub field_21: GenericReferenceField,
46
47    /// **Account Identification** - Field 25
48    ///
49    /// Identifies the specific account that has been debited. This account
50    /// is typically held by the sender with the receiver, or with a third party
51    /// as specified in the original transaction.
52    #[field("25", mandatory)]
53    pub field_25: GenericTextField,
54
55    /// **Value Date, Currency, Amount** - Field 32A
56    ///
57    /// Core debit details specifying when the debit was effective, in what currency,
58    /// and for what amount. The value date indicates when the debit actually
59    /// took effect on the account.
60    #[field("32A", mandatory)]
61    pub field_32a: Field32A,
62
63    /// **Date/Time Indication** - Field 13D (Optional)
64    ///
65    /// Provides precise timing information for when the debit was processed,
66    /// including UTC offset for accurate time coordination across time zones.
67    #[field("13D", optional)]
68    pub field_13d: Option<Field13D>,
69
70    /// **Ordering Institution** - Field 52a (Optional)
71    ///
72    /// Identifies the financial institution that ordered or initiated the
73    /// transaction that resulted in this debit. May include additional
74    /// clearing or routing information.
75    #[field("52", optional)]
76    pub field_52a: Option<GenericBicField>,
77
78    /// **Sender to Receiver Information** - Field 72 (Optional)
79    ///
80    /// Free-format field for additional information about the debit transaction.
81    /// May contain structured codes, exchange rate information, or narrative
82    /// details relevant to the debit confirmation.
83    #[field("72", optional)]
84    pub field_72: Option<GenericMultiLineTextField<6, 35>>,
85}
86
87/// Enhanced validation rules for MT900
88const MT900_VALIDATION_RULES: &str = r#"{
89  "rules": [
90    {
91      "id": "REF_FORMAT",
92      "description": "Transaction and related references must not have invalid slash patterns",
93      "condition": {
94        "and": [
95          {"!": {"startsWith": [{"var": "field_20.value"}, "/"]}},
96          {"!": {"endsWith": [{"var": "field_20.value"}, "/"]}},
97          {"!": {"includes": [{"var": "field_20.value"}, "//"]}},
98          {"!": {"startsWith": [{"var": "field_21.value"}, "/"]}},
99          {"!": {"endsWith": [{"var": "field_21.value"}, "/"]}},
100          {"!": {"includes": [{"var": "field_21.value"}, "//"]}}
101        ]
102      }
103    },
104    {
105      "id": "AMOUNT_POSITIVE",
106      "description": "Debit amount must be positive",
107      "condition": {
108        ">": [{"var": "field_32a.amount"}, 0]
109      }
110    },
111    {
112      "id": "REQUIRED_FIELDS",
113      "description": "All mandatory fields must be present and non-empty",
114      "condition": {
115        "and": [
116          {"!=": [{"var": "field_20.value"}, ""]},
117          {"!=": [{"var": "field_21.value"}, ""]},
118          {"!=": [{"var": "field_25.value"}, ""]}
119        ]
120      }
121    }
122  ]
123}"#;