Port all fixes from IntaleqApp (Wallet, CLIQ, OTP, Docker)

This commit is contained in:
Hamza-Ayed
2026-08-01 03:58:37 +03:00
parent 12fc64dc9a
commit 915d517ba7
9 changed files with 100 additions and 70 deletions
@@ -7,7 +7,7 @@ try {
$userId = filterRequest("user_id");
$userType = filterRequest("user_type");
$amount = filterRequest("amount");
$cliqPhone = filterRequest("cliq_phone");
$cliqPhone = filterRequest("cliq_phone") ?: filterRequest("click_phone");
$phone = filterRequest("phone");
if (empty($userId) || empty($userType) || !is_numeric($amount) || $amount <= 0 || empty($cliqPhone)) {
@@ -37,14 +37,12 @@ try {
$upd = $con->prepare("
UPDATE cliq_invoices
SET amount = :amount,
phone = :phone,
cliq_phone = :cliq_phone,
updated_at = NOW()
WHERE id = :id
");
$upd->execute([
':amount' => $amount,
':phone' => $phone ?: null,
':cliq_phone' => $cliqPhone,
':id' => $existing['id'],
]);
@@ -62,15 +60,14 @@ try {
$ins = $con->prepare("
INSERT INTO cliq_invoices
(invoice_number, user_id, user_type, phone, amount, cliq_phone, status, created_at, updated_at)
(invoice_number, user_id, user_type, amount, cliq_phone, status, created_at, updated_at)
VALUES
(:invoice_number, :user_id, :user_type, :phone, :amount, :cliq_phone, 'pending', NOW(), NOW())
(:invoice_number, :user_id, :user_type, :amount, :cliq_phone, 'pending', NOW(), NOW())
");
$ins->execute([
':invoice_number' => $invoiceNumber,
':user_id' => $userId,
':user_type' => $userType,
':phone' => $phone ?: null,
':amount' => $amount,
':cliq_phone' => $cliqPhone
]);
@@ -3,13 +3,13 @@ include "../../connect.php";
$passenger_id = filterRequest("passenger_id");
$sql = "SELECT
COALESCE(dummy.passenger_id, '$passenger_id') AS passenger_id,
COALESCE(SUM(pw.balance), 0) AS total, -- Adjust column to represent payments
COALESCE(dummy.passenger_id, :passenger_id) AS passenger_id,
COALESCE(SUM(pw.balance), 0) AS total,
COALESCE(p.first_name, '') AS first_name,
COALESCE(p.last_name, '') AS last_name,
COALESCE(p.phone, '') AS phone
FROM
(SELECT '$passenger_id' AS passenger_id) AS dummy
(SELECT :passenger_id2 AS passenger_id) AS dummy
LEFT JOIN `passengerWallet` pw ON pw.passenger_id = dummy.passenger_id
LEFT JOIN passengers p ON p.id = dummy.passenger_id
GROUP BY
@@ -17,17 +17,13 @@ GROUP BY
LIMIT 0, 25;
";
$stmt = $con->prepare($sql);
$stmt->execute();
$stmt->execute(['passenger_id' => $passenger_id, 'passenger_id2' => $passenger_id]);
if ($stmt->rowCount() > 0) {
// Fetch the record
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
printSuccess( $row);
}
else{
// Print a failure message
printFailure($message = "No wallet record found");
// LEFT JOIN يُرجع دائماً صفاً واحداً على الأقل (balance=0 إذا لم توجد محفظة)
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!empty($row)) {
printSuccess($row);
} else {
printFailure("No wallet record found");
}
?>