prepare("SELECT * FROM `paymentsLogSyria` WHERE order_ref = :order_ref AND status = 1 LIMIT 1"); $stmt->execute([':order_ref' => $orderRef]); $payment = $stmt->fetch(PDO::FETCH_ASSOC); if ($payment) break; sleep(2); } if (!$payment) { logError("VERIFY", "لم يتم تأكيد الدفع بعد عدة محاولات", ["orderRef" => $orderRef]); showHTMLPage("error", "لم يتم تأكيد الدفع", "لم نتمكن من تأكيد دفعتك بعد. قد تستغرق العملية بضع لحظات. يرجى التحقق من رصيدك في التطبيق لاحقاً أو التواصل مع الدعم الفني."); } try { $userId = $payment['user_id']; $amount = $payment['amount']; $paymentMethod = $payment['payment_method'] ?? 'ecash'; $finalAmount = calculateBonus($amount); $token = generatePaymentToken($userId, $finalAmount); if (!$token) throw new Exception("فشل إنشاء توكن محفظة الراكب"); $walletResult = addToPassengerWallet($userId, $finalAmount, $token); if (!$walletResult || ($walletResult['status'] ?? 'fail') != "success") { throw new Exception("فشل إضافة الرصيد لمحفظة الراكب"); } $siroToken = generatePaymentToken($userId, $amount); if (!$siroToken) throw new Exception("فشل إنشاء توكن محفظة سفر"); $siroWalletResult = addToSiroWallet($userId, $amount, $paymentMethod, $siroToken); if (!$siroWalletResult || ($siroWalletResult['status'] ?? 'fail') != "success") { throw new Exception("فشل إضافة الرصيد لمحفظة سفر"); } logError("VERIFY", "اكتملت العملية بنجاح", ["orderRef" => $orderRef, "userId" => $userId]); showHTMLPage("success", "تم الدفع بنجاح", "تمت إضافة الرصيد إلى محفظتك. شكرًا لاستخدامك Intaleq."); } catch (Exception $e) { logError("VERIFY_ERROR", $e->getMessage(), ["orderRef" => $orderRef]); showHTMLPage("error", "حدث خطأ", "لقد تم استلام دفعتك بنجاح، ولكن حدث خطأ أثناء تحديث رصيدك. يرجى التواصل مع الدعم الفني وتزويدهم بالرقم المرجعي: " . htmlspecialchars($orderRef)); } // --- دوال مساعدة --- function calculateBonus($amount) { if ($amount == 200000) return 205000; if ($amount == 400000) return 425000; if ($amount == 1000000) return 1040000; return $amount; } function generatePaymentToken($passengerId, $amount) { $url = BASE_URL . "/passengerWallet/addPaymentTokenPassenger.php"; $postData = ['passengerId' => $passengerId, 'amount' => $amount]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode != 200) return null; $data = json_decode($response, true); return $data['message'] ?? null; } function addToPassengerWallet($passengerId, $amount, $token) { $url = BASE_URL . "/passengerWallet/add.php"; $postData = ['passenger_id' => $passengerId, 'balance' => $amount, 'token' => $token]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode != 200) return null; return json_decode($response, true); } function addToSiroWallet($passengerId, $amount, $paymentMethod, $token) { $url = BASE_URL . "/siroWallet/add.php"; $postData = [ 'amount' => $amount, 'paymentMethod' => $paymentMethod, 'passengerId' => $passengerId, 'token' => $token, 'driverId' => 'passenger' ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode != 200) return null; return json_decode($response, true); } ?>