sagapay_sdk/
models.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5/// Supported blockchain network types
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "UPPERCASE")]
8pub enum NetworkType {
9    ERC20,
10    BEP20,
11    TRC20,
12    POLYGON,
13    SOLANA,
14}
15
16impl fmt::Display for NetworkType {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            NetworkType::ERC20 => write!(f, "ERC20"),
20            NetworkType::BEP20 => write!(f, "BEP20"),
21            NetworkType::TRC20 => write!(f, "TRC20"),
22            NetworkType::POLYGON => write!(f, "POLYGON"),
23            NetworkType::SOLANA => write!(f, "SOLANA"),
24        }
25    }
26}
27
28/// Transaction status enum
29#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
30#[serde(rename_all = "UPPERCASE")]
31pub enum TransactionStatus {
32    Pending,
33    Processing,
34    Completed,
35    Failed,
36    Cancelled,
37}
38
39/// Transaction type enum
40#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
41#[serde(rename_all = "lowercase")]
42pub enum TransactionType {
43    Deposit,
44    Withdrawal,
45}
46
47/// Address type enum
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(rename_all = "UPPERCASE")]
50pub enum AddressType {
51    Temporary,
52    Permanent,
53}
54
55/// Parameters for creating a deposit
56#[derive(Debug, Clone, Serialize)]
57pub struct CreateDepositParams {
58    pub network_type: NetworkType,
59    pub contract_address: String,
60    pub amount: String,
61    pub ipn_url: String,
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub udf: Option<String>,
64    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
65    pub address_type: Option<String>,
66}
67
68/// Parameters for creating a withdrawal
69#[derive(Debug, Clone, Serialize)]
70pub struct CreateWithdrawalParams {
71    pub network_type: NetworkType,
72    pub contract_address: String,
73    pub address: String,
74    pub amount: String,
75    pub ipn_url: String,
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub udf: Option<String>,
78}
79
80/// Response from the create deposit endpoint
81#[derive(Debug, Clone, Deserialize)]
82pub struct DepositResponse {
83    pub id: String,
84    pub address: String,
85    #[serde(rename = "expiresAt")]
86    pub expires_at: DateTime<Utc>,
87    pub amount: String,
88    pub status: TransactionStatus,
89}
90
91/// Response from the create withdrawal endpoint
92#[derive(Debug, Clone, Deserialize)]
93pub struct WithdrawalResponse {
94    pub id: String,
95    pub status: TransactionStatus,
96    pub fee: String,
97}
98
99/// Token information
100#[derive(Debug, Clone, Deserialize)]
101pub struct Token {
102    pub network_type: NetworkType,
103    pub contract_address: String,
104    pub symbol: String,
105    pub name: String,
106    pub decimals: u8,
107}
108
109/// Transaction details
110#[derive(Debug, Clone, Deserialize)]
111pub struct Transaction {
112    pub id: String,
113    #[serde(rename = "transactionType")]
114    pub transaction_type: TransactionType,
115    pub status: TransactionStatus,
116    pub amount: String,
117    #[serde(rename = "createdAt")]
118    pub created_at: DateTime<Utc>,
119    #[serde(rename = "updatedAt")]
120    pub updated_at: DateTime<Utc>,
121    #[serde(rename = "txHash")]
122    pub tx_hash: Option<String>,
123    pub network_type: NetworkType,
124    pub contract_address: String,
125    pub address: String,
126    pub token: Token,
127}
128
129/// Response from the transaction status endpoint
130#[derive(Debug, Clone, Deserialize)]
131pub struct TransactionStatusResponse {
132    pub address: String,
133    #[serde(rename = "transactionType")]
134    pub transaction_type: TransactionType,
135    pub count: usize,
136    pub transactions: Vec<Transaction>,
137}
138
139/// Balance information
140#[derive(Debug, Clone, Deserialize)]
141pub struct Balance {
142    pub raw: String,
143    pub formatted: String,
144}
145
146/// Response from the wallet balance endpoint
147#[derive(Debug, Clone, Deserialize)]
148pub struct WalletBalanceResponse {
149    pub address: String,
150    pub network_type: NetworkType,
151    pub contract_address: String,
152    pub token: Token,
153    pub balance: Balance,
154}
155
156/// Webhook payload
157#[derive(Debug, Clone, Deserialize, Serialize)]
158pub struct WebhookPayload {
159    pub id: String,
160    #[serde(rename = "type")]
161    pub transaction_type: TransactionType,
162    pub status: TransactionStatus,
163    pub address: String,
164    pub network_type: NetworkType,
165    pub amount: String,
166    pub udf: Option<String>,
167    #[serde(rename = "txHash")]
168    pub tx_hash: Option<String>,
169    pub timestamp: DateTime<Utc>,
170}