Files
Siro/payment_server/v2/main/ride/payment/getAllPayment.php
T
Hamza-AyedandClaude Opus 5 61d6380861 Fix SQL injection and stale status matching in the wallet endpoints
The three endpoints the driver app calls for its wallet built their queries by
interpolating the driver id straight into SQL. Anything the app sent went into
the statement, and these run against the payments database.

They also matched only status = 'Finished'. The current ride pipeline writes
'completed', so a driver's completed rides, pending payouts and weekly
earnings all read as zero regardless of how much they had driven — which is
what the wallet errors in the admin error log are sitting next to.

getAllPayment.php, driverStatistic.php and getCountRide.php now bind the id
and match either spelling. Verified no interpolated identifier remains and
every rewritten condition is balanced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-25 17:57:52 +03:00

70 lines
1.8 KiB
PHP

<?php
include "../../connect.php";
$driverID = filterRequest("driverID");
$sql = "SELECT
(
SELECT
COUNT(*)
FROM
`ride`
WHERE
LOWER(`ride`.`status`) IN ('finished','completed')
AND `ride`.`created_at` BETWEEN CURRENT_DATE() + INTERVAL 7 HOUR AND CURRENT_DATE() + INTERVAL 10 HOUR
AND `ride`.`driver_id` = :driverID
) AS morning_count,
(
SELECT
COUNT(*)
FROM
`ride`
WHERE
LOWER(`ride`.`status`) IN ('finished','completed')
AND `ride`.`created_at` BETWEEN CURRENT_DATE() + INTERVAL 15 HOUR AND CURRENT_DATE() + INTERVAL 18 HOUR
AND `ride`.`driver_id` = :driverID
) AS afternoon_count,
(
SELECT
COALESCE(SUM(amount), 0) AS total_amount
FROM
payments
WHERE
isGiven = 'waiting' AND `driverID` = :driverID
) AS total_amount,
(
SELECT
COALESCE(SUM(price), 0) AS total_amount
FROM
ride
WHERE
`driver_id` = :driverID
AND LOWER(`ride`.`status`) IN ('finished','completed')
AND `ride`.`created_at` > CURRENT_DATE() - INTERVAL 1 WEEK
) AS total_amount_last_week
FROM
dual
LIMIT 1;
";
/**
* كان معرّف السائق يُدمج في نص الاستعلام مباشرةً (حقن SQL)، وكانت الحالة
* تُطابق 'Finished' فقط بينما خط الرحلات الحالي يكتب 'completed' — فتظهر
* أرباح السائق ورحلاته أصفاراً.
*/
$stmt = $con->prepare($sql);
$stmt->bindValue(':driverID', $driverID);
$stmt->execute();
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");
}
?>