Spaces:
Running
Running
File size: 14,895 Bytes
a79063d |
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
// إدارة المحافظ الإلكترونية
class WalletManager {
constructor() {
this.supportedWallets = {
jawali: {
id: 'jawali',
name: 'جوالي',
nameEn: 'Jawali',
provider: 'WeCash YE',
packageId: 'com.ama.wecashmobileapp',
icon: 'https://play-lh.googleusercontent.com/NuKV_Snecpx633RHzIWvFauG32WBAk-jt3lcZOajw2w7VD8Hdt8h5Lb0pYLopB_Qk4Y=w240-h480',
color: '#4361ee',
features: ['transfer', 'bills', 'recharge', 'qr'],
supportedCurrencies: ['YER', 'SAR', 'USD'],
maxTransfer: 3000000,
fees: {
transfer: 20,
billPayment: 15,
recharge: 10
}
},
onecash: {
id: 'onecash',
name: 'ONE Cash',
nameEn: 'ONE Cash',
provider: 'ONECASHYE',
packageId: 'com.one.onecustomer',
icon: 'https://play-lh.googleusercontent.com/OF2xMRUmNH47BIaOTbv7GgvmLRTQbT1xHkFF_Ocswx6Jq5gfX4VlfAl_275UmjH2pg=w240-h480',
color: '#059669',
features: ['transfer', 'bills', 'recharge', 'qr', 'international'],
supportedCurrencies: ['YER', 'SAR', 'USD'],
maxTransfer: 3000000,
fees: {
transfer: 0, // مجاني للمستخدمين
billPayment: 10,
recharge: 5
}
},
cash: {
id: 'cash',
name: 'Cash',
nameEn: 'Cash',
provider: 'Tamkeen Financial',
packageId: 'com.tamkeen.sms',
icon: 'https://play-lh.googleusercontent.com/zkV8HeO6iF2xa77ObHdKfAXfrfjU5fgWB0XsWt7_DmG4VGSKob2jU_CrqWyKQtghQyE=w240-h480',
color: '#dc2626',
features: ['transfer', 'bills', 'recharge', 'qr', 'offline'],
supportedCurrencies: ['YER'],
maxTransfer: 2000000,
fees: {
transfer: 25,
billPayment: 20,
recharge: 15
}
},
jaib: {
id: 'jaib',
name: 'Jaib',
nameEn: 'Jaib Digital Wallet',
provider: 'AHD Financial',
packageId: 'com.ahd.jaib',
icon: 'https://play-lh.googleusercontent.com/EAaXnjh1FVPYpI5qWZwWvZIV5oD1hm9auDX0owOgREBjMAzYKX9od1USWRzlXIhRvKMx=w240-h480',
color: '#7c3aed',
features: ['transfer', 'bills', 'recharge', 'qr', 'entertainment'],
supportedCurrencies: ['YER'],
maxTransfer: 1500000,
fees: {
transfer: 15,
billPayment: 12,
recharge: 8
}
},
mfloos: {
id: 'mfloos',
name: 'mFloos',
nameEn: 'mFloos - Customers',
provider: 'Alkuraimi Islamic Microfinance Bank',
packageId: 'wallet.mfloos.com.mflooswallet.customer',
icon: 'https://play-lh.googleusercontent.com/mNvakjEk-3VX7icU5w4xmAhT4MQgGAGcQYpRvPkBLVTzD-sYnmzAH_wuglMujTsaqQ=w240-h480',
color: '#0891b2',
features: ['transfer', 'bills', 'recharge', 'banking'],
supportedCurrencies: ['YER'],
maxTransfer: 1000000,
fees: {
transfer: 10,
billPayment: 8,
recharge: 5
}
},
mobilemoney: {
id: 'mobilemoney',
name: 'Mobile Money',
nameEn: 'Mobile Money Wallet',
provider: 'CAC Bank',
packageId: 'cac.mobilemoney.app',
icon: 'https://play-lh.googleusercontent.com/51r7PLMlK0gVvITgOoJ7BnGX-9Gq3_ayiSiHHxSDbJZPCgABXI_LnU6jNCHAefWHvSPV=w240-h480',
color: '#ea580c',
features: ['transfer', 'bills', 'recharge', 'atm'],
supportedCurrencies: ['YER'],
maxTransfer: 2500000,
fees: {
transfer: 18,
billPayment: 15,
recharge: 12
}
}
};
this.userWallets = [];
this.init();
}
// تهيئة مدير المحافظ
init() {
this.loadUserWallets();
}
// تحميل محافظ المستخدم
loadUserWallets() {
const savedWallets = localStorage.getItem('unifiedWallet_userWallets');
if (savedWallets) {
this.userWallets = JSON.parse(savedWallets);
}
}
// حفظ محافظ المستخدم
saveUserWallets() {
localStorage.setItem('unifiedWallet_userWallets', JSON.stringify(this.userWallets));
}
// إضافة محفظة جديدة
async addWallet(walletId, accountNumber, pin) {
const walletInfo = this.supportedWallets[walletId];
if (!walletInfo) {
throw new Error('محفظة غير مدعومة');
}
// التحقق من صحة البيانات
if (!this.validateAccountNumber(accountNumber)) {
throw new Error('رقم الحساب غير صحيح');
}
if (!this.validatePin(pin)) {
throw new Error('رمز PIN غير صحيح');
}
// التحقق من عدم وجود المحفظة مسبقاً
const existingWallet = this.userWallets.find(w => w.id === walletId);
if (existingWallet) {
throw new Error('هذه المحفظة مضافة مسبقاً');
}
// محاكاة التحقق من المحفظة
await this.verifyWalletCredentials(walletId, accountNumber, pin);
// إضافة المحفظة
const newWallet = {
id: walletId,
accountNumber: accountNumber,
pin: this.encryptPin(pin),
balance: await this.fetchWalletBalance(walletId, accountNumber),
status: 'active',
addedAt: new Date().toISOString(),
lastSync: new Date().toISOString()
};
this.userWallets.push(newWallet);
this.saveUserWallets();
return newWallet;
}
// إزالة محفظة
removeWallet(walletId) {
const index = this.userWallets.findIndex(w => w.id === walletId);
if (index === -1) {
throw new Error('المحفظة غير موجودة');
}
this.userWallets.splice(index, 1);
this.saveUserWallets();
}
// تحديث رصيد محفظة
async updateWalletBalance(walletId) {
const wallet = this.userWallets.find(w => w.id === walletId);
if (!wallet) {
throw new Error('المحفظة غير موجودة');
}
const newBalance = await this.fetchWalletBalance(walletId, wallet.accountNumber);
wallet.balance = newBalance;
wallet.lastSync = new Date().toISOString();
this.saveUserWallets();
return newBalance;
}
// تحديث جميع الأرصدة
async updateAllBalances() {
const updatePromises = this.userWallets.map(wallet =>
this.updateWalletBalance(wallet.id)
);
await Promise.all(updatePromises);
}
// تنفيذ تحويل
async executeTransfer(fromWalletId, toWalletId, amount, recipientNumber, pin) {
const fromWallet = this.userWallets.find(w => w.id === fromWalletId);
if (!fromWallet) {
throw new Error('محفظة المرسل غير موجودة');
}
const fromWalletInfo = this.supportedWallets[fromWalletId];
const toWalletInfo = this.supportedWallets[toWalletId];
// التحقق من الرصيد
const fee = fromWalletInfo.fees.transfer;
const totalAmount = amount + fee;
if (fromWallet.balance < totalAmount) {
throw new Error('الرصيد غير كافي');
}
// التحقق من الحد الأقصى للتحويل
if (amount > fromWalletInfo.maxTransfer) {
throw new Error(`الحد الأقصى للتحويل هو ${fromWalletInfo.maxTransfer.toLocaleString()} ر.ي`);
}
// التحقق من رمز PIN
if (!this.verifyPin(pin, fromWallet.pin)) {
throw new Error('رمز PIN غير صحيح');
}
// تنفيذ التحويل
await this.processTransfer({
fromWallet: fromWalletId,
toWallet: toWalletId,
amount: amount,
fee: fee,
recipientNumber: recipientNumber,
timestamp: new Date().toISOString()
});
// تحديث الرصيد
fromWallet.balance -= totalAmount;
this.saveUserWallets();
return {
success: true,
transactionId: this.generateTransactionId(),
amount: amount,
fee: fee,
total: totalAmount,
newBalance: fromWallet.balance
};
}
// دفع فاتورة
async payBill(walletId, billType, billNumber, amount, pin) {
const wallet = this.userWallets.find(w => w.id === walletId);
if (!wallet) {
throw new Error('المحفظة غير موجودة');
}
const walletInfo = this.supportedWallets[walletId];
const fee = walletInfo.fees.billPayment;
const totalAmount = amount + fee;
if (wallet.balance < totalAmount) {
throw new Error('الرصيد غير كافي');
}
if (!this.verifyPin(pin, wallet.pin)) {
throw new Error('رمز PIN غير صحيح');
}
// تنفيذ دفع الفاتورة
await this.processBillPayment({
wallet: walletId,
billType: billType,
billNumber: billNumber,
amount: amount,
fee: fee,
timestamp: new Date().toISOString()
});
wallet.balance -= totalAmount;
this.saveUserWallets();
return {
success: true,
transactionId: this.generateTransactionId(),
amount: amount,
fee: fee,
total: totalAmount,
newBalance: wallet.balance
};
}
// شحن رصيد
async rechargeBalance(walletId, phoneNumber, amount, pin) {
const wallet = this.userWallets.find(w => w.id === walletId);
if (!wallet) {
throw new Error('المحفظة غير موجودة');
}
const walletInfo = this.supportedWallets[walletId];
const fee = walletInfo.fees.recharge;
const totalAmount = amount + fee;
if (wallet.balance < totalAmount) {
throw new Error('الرصيد غير كافي');
}
if (!this.verifyPin(pin, wallet.pin)) {
throw new Error('رمز PIN غير صحيح');
}
// تنفيذ شحن الرصيد
await this.processRecharge({
wallet: walletId,
phoneNumber: phoneNumber,
amount: amount,
fee: fee,
timestamp: new Date().toISOString()
});
wallet.balance -= totalAmount;
this.saveUserWallets();
return {
success: true,
transactionId: this.generateTransactionId(),
amount: amount,
fee: fee,
total: totalAmount,
newBalance: wallet.balance
};
}
// الحصول على معلومات محفظة
getWalletInfo(walletId) {
return this.supportedWallets[walletId];
}
// الحصول على محافظ المستخدم
getUserWallets() {
return this.userWallets.map(userWallet => {
const walletInfo = this.supportedWallets[userWallet.id];
return {
...walletInfo,
...userWallet,
accountNumber: userWallet.accountNumber
};
});
}
// التحقق من صحة رقم الحساب
validateAccountNumber(accountNumber) {
return /^[0-9]{9}$/.test(accountNumber);
}
// التحقق من صحة رمز PIN
validatePin(pin) {
return /^[0-9]{4,6}$/.test(pin);
}
// تشفير رمز PIN
encryptPin(pin) {
// تشفير بسيط للتجربة - في الإنتاج يجب استخدام تشفير قوي
return btoa(pin);
}
// فك تشفير رمز PIN
decryptPin(encryptedPin) {
return atob(encryptedPin);
}
// التحقق من رمز PIN
verifyPin(pin, encryptedPin) {
return pin === this.decryptPin(encryptedPin);
}
// توليد معرف معاملة
generateTransactionId() {
return 'TXN' + Date.now() + Math.random().toString(36).substr(2, 5).toUpperCase();
}
// محاكاة التحقق من بيانات المحفظة
async verifyWalletCredentials(walletId, accountNumber, pin) {
// محاكاة استدعاء API للتحقق
await new Promise(resolve => setTimeout(resolve, 1500));
// في التطبيق الحقيقي، سيتم التحقق من البيانات مع خوادم المحفظة
return true;
}
// محاكاة جلب رصيد المحفظة
async fetchWalletBalance(walletId, accountNumber) {
// محاكاة استدعاء API لجلب الرصيد
await new Promise(resolve => setTimeout(resolve, 1000));
// إرجاع رصيد عشوائي للتجربة
return Math.floor(Math.random() * 50000) + 1000;
}
// محاكاة تنفيذ التحويل
async processTransfer(transferData) {
await new Promise(resolve => setTimeout(resolve, 2000));
// في التطبيق الحقيقي، سيتم إرسال البيانات لخوادم المحفظة
console.log('تم تنفيذ التحويل:', transferData);
}
// محاكاة دفع الفاتورة
async processBillPayment(billData) {
await new Promise(resolve => setTimeout(resolve, 1500));
console.log('تم دفع الفاتورة:', billData);
}
// محاكاة شحن الرصيد
async processRecharge(rechargeData) {
await new Promise(resolve => setTimeout(resolve, 1000));
console.log('تم شحن الرصيد:', rechargeData);
}
}
// تصدير الكلاس للاستخدام في التطبيق الرئيسي
window.WalletManager = WalletManager;
|