-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathdeposit-flow-manager.js
More file actions
134 lines (116 loc) · 4.64 KB
/
Copy pathdeposit-flow-manager.js
File metadata and controls
134 lines (116 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Deposit Flow Manager - La Tanda Fintech
* Gestión del flujo de depósitos
*/
class DepositFlowManager {
constructor() {
this.API_BASE = 'https://latanda.online';
this.currentDeposit = null;
this.depositMethods = ['bank_transfer', 'mobile_money', 'crypto'];
console.log('💰 Deposit Flow Manager initialized');
}
async initDeposit(userId, amount, method) {
this.currentDeposit = {
id: 'DEP-' + Date.now(),
user_id: userId,
amount: amount,
method: method,
status: 'initiated',
created_at: new Date().toISOString(),
steps: []
};
this.addStep('initiated', 'Depósito iniciado');
return this.currentDeposit;
}
addStep(status, message) {
if (this.currentDeposit) {
this.currentDeposit.steps.push({
status: status,
message: message,
timestamp: new Date().toISOString()
});
this.currentDeposit.status = status;
}
}
async submitBankDeposit(depositData) {
try {
this.addStep('pending_transfer', 'Esperando transferencia bancaria');
var response = await fetch(this.API_BASE + '/api/wallet/deposit/bank-transfer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('auth_token')
},
body: JSON.stringify(depositData)
});
var result = await response.json();
if (result.success) {
this.currentDeposit = Object.assign(this.currentDeposit || {}, result.data);
this.addStep('pending_transfer', 'Instrucciones de transferencia generadas');
return { success: true, data: result.data };
} else {
this.addStep('failed', result.message || 'Error al procesar depósito');
return { success: false, message: result.message };
}
} catch (error) {
console.error('Deposit error:', error);
this.addStep('failed', 'Error de conexión');
return { success: false, message: 'Error de conexión' };
}
}
async uploadReceipt(depositId, file) {
try {
this.addStep('uploading', 'Subiendo comprobante...');
var formData = new FormData();
formData.append('receipt', file);
formData.append('deposit_id', depositId);
var response = await fetch(this.API_BASE + '/api/deposit/upload-receipt', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('auth_token')
},
body: formData
});
var result = await response.json();
if (result.success) {
this.addStep('processing', 'Comprobante recibido - En revisión');
return { success: true, data: result.data };
} else {
this.addStep('upload_failed', result.message || 'Error al subir comprobante');
return { success: false, message: result.message };
}
} catch (error) {
console.error('Upload error:', error);
this.addStep('upload_failed', 'Error al subir comprobante');
return { success: false, message: 'Error de conexión' };
}
}
async trackDeposit(depositId) {
try {
var response = await fetch(this.API_BASE + '/api/deposit/track/' + depositId, {
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('auth_token')
}
});
return await response.json();
} catch (error) {
console.error('Track error:', error);
return { success: false, message: 'Error al consultar estado' };
}
}
getAvailableMethods() {
return [
{ id: 'bank_transfer', name: 'Transferencia Bancaria', icon: '🏦', fee: '2%' },
{ id: 'mobile_money', name: 'Tigo/Claro Money', icon: '📱', fee: '1.5%' },
{ id: 'crypto', name: 'Criptomonedas', icon: '₿', fee: '0.5%' }
];
}
getCurrentDeposit() {
return this.currentDeposit;
}
clearCurrentDeposit() {
this.currentDeposit = null;
}
}
window.DepositFlowManager = new DepositFlowManager();
console.log('✅ Deposit Flow Manager loaded');