rustkernel_payments/types.rs
1//! Payment processing types.
2
3use std::collections::HashMap;
4
5// ============================================================================
6// Payment Types
7// ============================================================================
8
9/// Payment transaction.
10#[derive(Debug, Clone)]
11pub struct Payment {
12 /// Payment ID.
13 pub id: String,
14 /// Payer account.
15 pub payer_account: String,
16 /// Payee account.
17 pub payee_account: String,
18 /// Amount.
19 pub amount: f64,
20 /// Currency.
21 pub currency: String,
22 /// Payment type.
23 pub payment_type: PaymentType,
24 /// Status.
25 pub status: PaymentStatus,
26 /// Initiated timestamp.
27 pub initiated_at: u64,
28 /// Completed timestamp.
29 pub completed_at: Option<u64>,
30 /// Reference.
31 pub reference: String,
32 /// Priority.
33 pub priority: PaymentPriority,
34 /// Attributes.
35 pub attributes: HashMap<String, String>,
36}
37
38/// Payment type.
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
40pub enum PaymentType {
41 /// ACH transfer.
42 ACH,
43 /// Wire transfer.
44 Wire,
45 /// Real-time payment.
46 RealTime,
47 /// Internal transfer.
48 Internal,
49 /// Check.
50 Check,
51 /// Card payment.
52 Card,
53}
54
55/// Payment status.
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub enum PaymentStatus {
58 /// Initiated.
59 Initiated,
60 /// Pending validation.
61 Pending,
62 /// Validated.
63 Validated,
64 /// In processing.
65 Processing,
66 /// Completed.
67 Completed,
68 /// Failed.
69 Failed,
70 /// Cancelled.
71 Cancelled,
72 /// Reversed.
73 Reversed,
74}
75
76/// Payment priority.
77#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
78pub enum PaymentPriority {
79 /// Low priority.
80 Low = 0,
81 /// Normal priority.
82 Normal = 1,
83 /// High priority.
84 High = 2,
85 /// Urgent.
86 Urgent = 3,
87}
88
89/// Payment processing result.
90#[derive(Debug, Clone)]
91pub struct ProcessingResult {
92 /// Processed payments.
93 pub processed: Vec<String>,
94 /// Failed payments.
95 pub failed: Vec<(String, String)>,
96 /// Pending payments.
97 pub pending: Vec<String>,
98 /// Statistics.
99 pub stats: ProcessingStats,
100}
101
102/// Processing statistics.
103#[derive(Debug, Clone)]
104pub struct ProcessingStats {
105 /// Total count.
106 pub total_count: usize,
107 /// Processed count.
108 pub processed_count: usize,
109 /// Failed count.
110 pub failed_count: usize,
111 /// Total amount processed.
112 pub total_amount: f64,
113 /// Average processing time (microseconds).
114 pub avg_processing_time_us: f64,
115}
116
117// ============================================================================
118// Flow Analysis Types
119// ============================================================================
120
121/// Payment flow.
122#[derive(Debug, Clone)]
123pub struct PaymentFlow {
124 /// Source node.
125 pub source: String,
126 /// Target node.
127 pub target: String,
128 /// Total volume.
129 pub volume: f64,
130 /// Transaction count.
131 pub count: usize,
132 /// Average amount.
133 pub avg_amount: f64,
134}
135
136/// Flow analysis result.
137#[derive(Debug, Clone)]
138pub struct FlowAnalysisResult {
139 /// Payment flows.
140 pub flows: Vec<PaymentFlow>,
141 /// Node metrics.
142 pub node_metrics: HashMap<String, NodeMetrics>,
143 /// Overall metrics.
144 pub overall_metrics: OverallMetrics,
145 /// Anomalies detected.
146 pub anomalies: Vec<FlowAnomaly>,
147}
148
149/// Node metrics.
150#[derive(Debug, Clone)]
151pub struct NodeMetrics {
152 /// Node ID.
153 pub node_id: String,
154 /// Total inflow.
155 pub total_inflow: f64,
156 /// Total outflow.
157 pub total_outflow: f64,
158 /// Net flow.
159 pub net_flow: f64,
160 /// Inbound connections.
161 pub inbound_count: usize,
162 /// Outbound connections.
163 pub outbound_count: usize,
164 /// Centrality score.
165 pub centrality: f64,
166}
167
168/// Overall flow metrics.
169#[derive(Debug, Clone)]
170pub struct OverallMetrics {
171 /// Total volume.
172 pub total_volume: f64,
173 /// Total transactions.
174 pub total_transactions: usize,
175 /// Unique payers.
176 pub unique_payers: usize,
177 /// Unique payees.
178 pub unique_payees: usize,
179 /// Average transaction size.
180 pub avg_transaction_size: f64,
181 /// Peak hour.
182 pub peak_hour: Option<u32>,
183 /// Network density.
184 pub network_density: f64,
185}
186
187/// Flow anomaly.
188#[derive(Debug, Clone)]
189pub struct FlowAnomaly {
190 /// Anomaly type.
191 pub anomaly_type: FlowAnomalyType,
192 /// Related node or edge.
193 pub entity: String,
194 /// Description.
195 pub description: String,
196 /// Severity (0-1).
197 pub severity: f64,
198 /// Timestamp.
199 pub timestamp: u64,
200}
201
202/// Flow anomaly type.
203#[derive(Debug, Clone, Copy, PartialEq, Eq)]
204pub enum FlowAnomalyType {
205 /// Unusual volume.
206 UnusualVolume,
207 /// Unusual frequency.
208 UnusualFrequency,
209 /// New connection.
210 NewConnection,
211 /// Circular flow.
212 CircularFlow,
213 /// Rapid movement.
214 RapidMovement,
215 /// Structuring.
216 Structuring,
217}
218
219// ============================================================================
220// Account Types
221// ============================================================================
222
223/// Account for payment processing.
224#[derive(Debug, Clone)]
225pub struct PaymentAccount {
226 /// Account ID.
227 pub id: String,
228 /// Account type.
229 pub account_type: AccountType,
230 /// Balance.
231 pub balance: f64,
232 /// Available balance.
233 pub available_balance: f64,
234 /// Currency.
235 pub currency: String,
236 /// Status.
237 pub status: AccountStatus,
238 /// Daily limit.
239 pub daily_limit: Option<f64>,
240 /// Daily used.
241 pub daily_used: f64,
242}
243
244/// Account type.
245#[derive(Debug, Clone, Copy, PartialEq, Eq)]
246pub enum AccountType {
247 /// Checking account.
248 Checking,
249 /// Savings account.
250 Savings,
251 /// Operating account.
252 Operating,
253 /// Settlement account.
254 Settlement,
255 /// Escrow account.
256 Escrow,
257}
258
259/// Account status.
260#[derive(Debug, Clone, Copy, PartialEq, Eq)]
261pub enum AccountStatus {
262 /// Active.
263 Active,
264 /// Frozen.
265 Frozen,
266 /// Closed.
267 Closed,
268 /// Pending.
269 Pending,
270}
271
272// ============================================================================
273// Validation Types
274// ============================================================================
275
276/// Validation result.
277#[derive(Debug, Clone)]
278pub struct ValidationResult {
279 /// Is valid.
280 pub is_valid: bool,
281 /// Errors.
282 pub errors: Vec<ValidationError>,
283 /// Warnings.
284 pub warnings: Vec<ValidationWarning>,
285}
286
287/// Validation error.
288#[derive(Debug, Clone)]
289pub struct ValidationError {
290 /// Error code.
291 pub code: String,
292 /// Error message.
293 pub message: String,
294 /// Field (if applicable).
295 pub field: Option<String>,
296}
297
298/// Validation warning.
299#[derive(Debug, Clone)]
300pub struct ValidationWarning {
301 /// Warning code.
302 pub code: String,
303 /// Warning message.
304 pub message: String,
305}