Files
tripz-llc/payment_server/v2/main/ride/shamcash/save_transactions_new.php
T
Hamza-AyedandClaude Opus 5 4d8414c96b feat: استيراد كود سيرو إلى تريبز (سيرو @ecfe7568) — بلا تعديل
قرار المالك 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>
2026-07-27 05:14:13 +03:00

117 lines
4.2 KiB
PHP
Executable File

<?php
// shamcash/save_transactions.php
// يعتمد حصرياً على Note (Invoice Number)
ini_set('display_errors', 0);
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type");
$log_file = __DIR__ . '/transactions.log';
$last_id_file = __DIR__ . '/last_id.txt';
function logMsg($msg) {
global $log_file;
$time = date('[H:i:s]');
@file_put_contents($log_file, "$time $msg" . PHP_EOL, FILE_APPEND);
}
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200); exit;
}
// --- 1. الاتصال بقاعدة البيانات ---
// البحث عن jwtconnect.php في المجلدات العلوية
$possible_paths = [__DIR__ . '/../jwtconnect.php', __DIR__ . '/../../jwtconnect.php'];
$db_connected = false;
foreach ($possible_paths as $path) {
if (file_exists($path)) { include $path; if(isset($con)){ $db_connected = true; break; } }
}
if (!$db_connected) {
logMsg("CRITICAL: DB Connection Failed.");
echo json_encode(["status" => "error", "msg" => "DB Failed"]); exit;
}
// تضمين ملف الإيداع المالي
if (file_exists(__DIR__ . "/finalize_deposit.php")) {
include __DIR__ . "/finalize_deposit.php";
} else {
logMsg("CRITICAL: finalize_deposit.php missing"); exit;
}
// --- 2. استقبال البيانات ---
$raw = file_get_contents("php://input");
if (empty($raw)) { echo json_encode(["status" => "waiting"]); exit; }
$data = json_decode($raw, true);
if (!$data) { echo json_encode(["status" => "error"]); exit; }
if (!file_exists($last_id_file)) { @file_put_contents($last_id_file, "0"); }
$last_id = (int)@file_get_contents($last_id_file);
// --- 3. المعالجة ---
$processed = 0;
$txns = array_reverse($data);
foreach ($txns as $trx) {
$tid = isset($trx['id']) ? (int)$trx['id'] : 0;
if ($tid > $last_id) {
$amt = (float)($trx['amount'] ?? 0);
$note = $trx['note'] ?? '';
$status_log = "IGNORED";
// شرط الإيداع: مبلغ موجب + وجود ملاحظة رقمية
// نستخرج الأرقام فقط من الملاحظة (رقم الفاتورة)
$invoice_num = preg_replace('/[^0-9]/', '', $note);
if ($amt > 0 && !empty($invoice_num) && strlen($invoice_num) >= 5) {
// البحث المباشر عن الفاتورة برقمها والمبلغ
$stmt = $con->prepare("SELECT id FROM invoices_shamcash WHERE invoice_number = :inv AND amount = :amt AND status = 'pending' LIMIT 1");
$stmt->execute([':inv' => $invoice_num, ':amt' => $amt]);
$invoice = $stmt->fetch(PDO::FETCH_ASSOC);
if ($invoice) {
$inv_id = $invoice['id'];
// حجز الفاتورة فوراً
$upd = $con->prepare("UPDATE invoices_shamcash SET status = 'processing', transaction_id = :tid WHERE id = :id AND status = 'pending'");
$upd->execute([':tid' => $tid, ':id' => $inv_id]);
if ($upd->rowCount() > 0) {
// استدعاء الفاينلايز (مع البونص والتوكنات)
if (finalizeShamCashDeposit($con, $inv_id)) {
$status_log = "SUCCESS (Inv#$inv_id)";
} else {
$status_log = "FAILED_FINALIZE (Inv#$inv_id)";
// إعادة الحالة للفشل
$con->prepare("UPDATE invoices_shamcash SET status = 'failed' WHERE id = :id")->execute([':id' => $inv_id]);
}
} else {
$status_log = "RACE_CONDITION";
}
} else {
$status_log = "NO_MATCHING_INVOICE ($invoice_num)";
}
} elseif ($amt > 0) {
$status_log = "INVALID_NOTE";
}
logMsg("ID:$tid | Note:$note | Amt:$amt | $status_log");
$last_id = $tid;
$processed++;
}
}
if ($processed > 0) {
@file_put_contents($last_id_file, $last_id);
}
echo json_encode(["status" => "success", "processed" => $processed]);
?>