قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
107 lines
5.1 KiB
PHP
Executable File
107 lines
5.1 KiB
PHP
Executable File
<?php
|
|
// --- finalize_payment.php ---
|
|
// يحتوي على الدوال المنطقية لإضافة الرصيد للمستخدمين بعد تأكيد الدفع
|
|
|
|
// ملاحظة: هذا الملف لا يتم استدعاؤه مباشرة، بل يتم تضمينه في mtn_webhook_handler.php
|
|
|
|
/**
|
|
* دالة مركزية لإتمام الدفع بعد التحقق منه
|
|
* @param PDO $con اتصال قاعدة البيانات
|
|
* @param int $invoiceId معرّف الفاتورة في جدول mtn_invoices
|
|
* @return array نتيجة العملية
|
|
*/
|
|
function finalizeClickPayment(PDO $con, int $invoiceId): array
|
|
{
|
|
try {
|
|
// جلب تفاصيل الفاتورة
|
|
$stmt = $con->prepare("SELECT * FROM `cliq_invoices` WHERE id = :id AND status = 'completed' LIMIT 1");
|
|
$stmt->execute([':id' => $invoiceId]);
|
|
$invoice = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$invoice) {
|
|
return ['success' => false, 'message' => 'Invoice not found or not completed.'];
|
|
}
|
|
|
|
$userType = $invoice['user_type'];
|
|
$userId = $invoice['user_id'];
|
|
$amount = (float) $invoice['amount'];
|
|
$paymentMethod = 'click_cash'; // تحديد طريقة الدفع
|
|
|
|
// تحديد ما إذا كان المستخدم سائقاً أم راكباً
|
|
if ($userType === 'driver') {
|
|
return finalizeForDriver($con, $userId, $amount, $paymentMethod);
|
|
} elseif ($userType === 'passenger') {
|
|
return finalizeForPassenger($con, $userId, $amount, $paymentMethod);
|
|
} else {
|
|
return ['success' => false, 'message' => 'Unknown user type.'];
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
error_log("Finalization Exception: " . $e->getMessage());
|
|
return ['success' => false, 'message' => 'Finalization failed'];
|
|
}
|
|
}
|
|
|
|
// --- دوال مساعدة خاصة بالسائق ---
|
|
function finalizeForDriver(PDO $con, int $driverId, float $amount, string $paymentMethod): array
|
|
{
|
|
// حساب قيمة البونص كما في الكود الأصلي
|
|
$bonusAmount = match ((int)$amount) {
|
|
10000 => 10000.0,
|
|
20000 => 21000.0,
|
|
40000 => 45000.0,
|
|
100000 => 110000.0,
|
|
default => $amount,
|
|
};
|
|
|
|
// إنشاء سجل دفع جديد والحصول على ID
|
|
$paymentID = generatePaymentID($con, $driverId, $bonusAmount, $paymentMethod);
|
|
if (!$paymentID) throw new Exception('Failed to generate payment ID for driver.');
|
|
|
|
// إضافة الرصيد لمحفظة السائق
|
|
$stmtDriver = $con->prepare("INSERT INTO driverWallet (driverID, paymentID, amount, paymentMethod) VALUES (:driverID, :paymentID, :amount, :paymentMethod)");
|
|
$stmtDriver->execute([':driverID' => $driverId, ':paymentID' => $paymentID, ':amount' => $bonusAmount, ':paymentMethod' => $paymentMethod]);
|
|
if ($stmtDriver->rowCount() === 0) throw new Exception('Insert to driverWallet failed.');
|
|
|
|
// إضافة سجل محاسبي لمحفظة سفر
|
|
$stmtSiro = $con->prepare("INSERT INTO siroWallet (driverId, passengerId, amount, paymentMethod) VALUES (:driverId, 'driver', :amount, :paymentMethod)");
|
|
$stmtSiro->execute([':driverId' => $driverId, ':amount' => $amount, ':paymentMethod' => $paymentMethod]);
|
|
if ($stmtSiro->rowCount() === 0) throw new Exception('Insert to siroWallet failed.');
|
|
|
|
return ['success' => true, 'message' => 'Driver wallets updated.'];
|
|
}
|
|
|
|
function generatePaymentID(PDO $con, string $driverId, float $amount, string $method): ?string {
|
|
$stmt = $con->prepare("INSERT INTO paymentsDriverPoints (`amount`, `payment_method`, `driverID`) VALUES (:amount, :method, :driverID)");
|
|
$stmt->execute([':driverID' => $driverId, ':amount' => $amount, ':method' => $method]);
|
|
return $stmt->rowCount() > 0 ? $con->lastInsertId() : null;
|
|
}
|
|
|
|
|
|
// --- دوال مساعدة خاصة بالراكب ---
|
|
function finalizeForPassenger(PDO $con, string $passengerId, float $amount, string $paymentMethod): array
|
|
{
|
|
// حساب البونص للراكب
|
|
$finalAmount = calculatePassengerBonus($amount);
|
|
|
|
// إضافة الرصيد لمحفظة الراكب
|
|
$stmtPassenger = $con->prepare("INSERT INTO passengerWallet (passenger_id, balance) VALUES (:id, :amount) ON DUPLICATE KEY UPDATE balance = balance + :amount");
|
|
$stmtPassenger->execute([':id' => $passengerId, ':amount' => $finalAmount]);
|
|
if ($stmtPassenger->rowCount() === 0) throw new Exception('Update passengerWallet failed.');
|
|
|
|
// إضافة سجل محاسبي لمحفظة سفر
|
|
$stmtSiro = $con->prepare("INSERT INTO siroWallet (passengerId, driverId, amount, paymentMethod) VALUES (:passengerId, 'passenger', :amount, :paymentMethod)");
|
|
$stmtSiro->execute([':passengerId' => $passengerId, ':amount' => $amount, ':paymentMethod' => $paymentMethod]);
|
|
if ($stmtSiro->rowCount() === 0) throw new Exception('Insert to siroWallet for passenger failed.');
|
|
|
|
return ['success' => true, 'message' => 'Passenger wallets updated.'];
|
|
}
|
|
|
|
function calculatePassengerBonus(float $amount): float {
|
|
if ($amount == 20000) return 20500;
|
|
if ($amount == 40000) return 42500;
|
|
if ($amount == 100000) return 104000;
|
|
return $amount;
|
|
}
|
|
?>
|