Files
Siro/walletintaleq.intaleq.xyz/v2/main/ride/ecash/passenger/ecash_verify.php
2026-06-16 22:44:11 +03:00

181 lines
7.0 KiB
PHP
Executable File

<?php
// هذا الملف هو نقطة النهاية بعد الدفع، ويقوم بكل عمليات التحقق وإضافة الرصيد
include "../../../jwtconnect.php";
define("BASE_URL", "https://wl.tripz-egypt.com/v1/main/ride");
define("LOG_FILE", "../logs/payment_verification.log");
function logError($step, $message, $data = null) {
$logDir = dirname(LOG_FILE);
if (!is_dir($logDir)) { mkdir($logDir, 0755, true); }
$logEntry = "[" . date('Y-m-d H:i:s') . "] STEP {$step}: {$message}";
if ($data !== null) { $logEntry .= " | Data: " . json_encode($data, JSON_UNESCAPED_UNICODE); }
file_put_contents(LOG_FILE, $logEntry . PHP_EOL, FILE_APPEND);
}
function showHTMLPage($type, $title, $message) {
$color = $type === 'success' ? '#28a745' : '#dc3545';
$icon = $type === 'success' ? '✔' : '✖';
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title><?= htmlspecialchars($title) ?></title>
<style>
body {
background-color: #f4f6f9;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
text-align: center;
padding-top: 100px;
color: #333;
}
.container {
background: #fff;
padding: 40px 30px;
margin: auto;
max-width: 450px;
border-radius: 15px;
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
animation: fadeIn 1s ease-out;
}
.icon {
font-size: 64px;
color: <?= $color ?>;
margin-bottom: 15px;
}
h1 {
font-size: 28px;
color: <?= $color ?>;
}
p {
font-size: 18px;
margin-top: 10px;
color: #555;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<div class="container">
<div class="icon"><?= $icon ?></div>
<h1><?= htmlspecialchars($title) ?></h1>
<p><?= htmlspecialchars($message) ?></p>
</div>
</body>
</html>
<?php
exit;
}
$orderRef = $_GET['orderRef'] ?? null;
if (empty($orderRef)) {
showHTMLPage("error", "خطأ في الرابط", "الرقم المرجعي للطلب غير موجود.");
}
$payment = null;
$max_attempts = 5;
for ($attempts = 0; $attempts < $max_attempts; $attempts++) {
$stmt = $con->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);
}
?>