Update: 2026-06-15 01:37:40

This commit is contained in:
Hamza-Ayed
2026-06-15 01:37:41 +03:00
parent f021ba5a35
commit 2321b78244
164 changed files with 1356 additions and 1560 deletions

View File

@@ -0,0 +1,103 @@
<?php
/**
* add_s2s_reward.php — Payment Server Endpoint
*
* Inserts wallet credit/debit records into driverWallet.
* Authenticated via X-S2S-Api-Key header matching the S2S_SHARED_KEY environment variable.
*/
require_once __DIR__ . '/../../jwtconnect.php';
define('S2S_SHARED_KEY', getenv('S2S_SHARED_KEY'));
$providedKey = $_SERVER['HTTP_X_S2S_API_KEY'] ?? '';
if (empty($providedKey) || $providedKey !== S2S_SHARED_KEY) {
http_response_code(401);
printFailure("Unauthorized: Invalid or missing X-S2S-Api-Key.");
exit;
}
$driverID = filterRequest("driverID");
$paymentID = filterRequest("paymentID");
$amount = filterRequest("amount");
$paymentMethod = filterRequest("paymentMethod");
$points = filterRequest("points"); // Optional raw points
if (empty($driverID) || empty($paymentID) || !isset($amount) || empty($paymentMethod)) {
printFailure("Missing required parameters: driverID, paymentID, amount, paymentMethod");
exit;
}
try {
$con->beginTransaction();
// Prevent duplicate challenge claims using paymentsDriverPoints table
if (strpos($paymentMethod, 'daily_') === 0 || strpos($paymentMethod, 'weekly_') === 0) {
$checkSql = "SELECT id FROM paymentsDriverPoints WHERE driverID = :driver_id AND payment_method = :challenge_id AND DATE(created_at) = CURDATE() FOR UPDATE";
$stmtCheck = $con->prepare($checkSql);
$stmtCheck->execute([
':driver_id' => $driverID,
':challenge_id' => $paymentMethod
]);
if ($stmtCheck->rowCount() > 0) {
$con->rollBack();
printFailure("Reward already claimed today");
exit();
}
}
$sql = "INSERT INTO `driverWallet` (
`driverID`,
`paymentID`,
`amount`,
`paymentMethod`
) VALUES (
:driverID,
:paymentID,
:amount,
:paymentMethod
);";
$stmt = $con->prepare($sql);
$stmt->execute([
':driverID' => $driverID,
':paymentID' => $paymentID,
':amount' => $amount,
':paymentMethod' => $paymentMethod
]);
if ($stmt->rowCount() > 0) {
// If points are provided, also insert into paymentsDriverPoints
if (!empty($points)) {
$sqlPoints = "INSERT INTO `paymentsDriverPoints` (
`amount`,
`payment_method`,
`driverID`
) VALUES (
:points,
:paymentMethod,
:driverID
);";
$stmtPoints = $con->prepare($sqlPoints);
$stmtPoints->execute([
':points' => $points,
':paymentMethod' => $paymentMethod,
':driverID' => $driverID
]);
}
$con->commit();
printSuccess("Record saved successfully");
} else {
$con->rollBack();
printFailure("Failed to save record");
}
} catch (Exception $e) {
if ($con->inTransaction()) {
$con->rollBack();
}
printFailure("An error occurred: " . $e->getMessage());
}
?>

View File

@@ -0,0 +1,67 @@
<?php
/**
* get_s2s_wallet_dashboard.php — Payment Server Endpoint
*
* Returns wallet metrics (challenge points, today's earnings) for a driver.
* Authenticated via X-S2S-Api-Key header matching the S2S_SHARED_KEY environment variable.
*/
require_once __DIR__ . '/../../jwtconnect.php';
define('S2S_SHARED_KEY', getenv('S2S_SHARED_KEY'));
$providedKey = $_SERVER['HTTP_X_S2S_API_KEY'] ?? '';
if (empty($providedKey) || $providedKey !== S2S_SHARED_KEY) {
http_response_code(401);
printFailure("Unauthorized: Invalid or missing X-S2S-Api-Key.");
exit;
}
$driverID = filterRequest("driverID");
if (empty($driverID)) {
printFailure("Missing required parameter: driverID");
exit;
}
try {
// 1. Calculate Sum of claimed challenge points
$stmtChallengePoints = $con->prepare("
SELECT COALESCE(SUM(amount), 0)
FROM `paymentsDriverPoints`
WHERE driverID = :driver_id
AND (payment_method LIKE 'daily_%' OR payment_method LIKE 'weekly_%')
");
$stmtChallengePoints->execute([':driver_id' => $driverID]);
$challengePoints = (int)($stmtChallengePoints->fetchColumn() ?: 0);
// 2. Calculate Today's Earnings
$stmtTodayEarnings = $con->prepare("
SELECT COALESCE(SUM(amount), 0)
FROM payments
WHERE driverID = :driver_id
AND DATE(created_at) = CURDATE()
");
$stmtTodayEarnings->execute([':driver_id' => $driverID]);
$todayEarnings = (float)($stmtTodayEarnings->fetchColumn() ?: 0.0);
// 3. Calculate Total Wallet Balance
$stmtTotalWallet = $con->prepare("
SELECT COALESCE(SUM(amount), 0)
FROM `driverWallet`
WHERE driverID = :driver_id
");
$stmtTotalWallet->execute([':driver_id' => $driverID]);
$totalWallet = (float)($stmtTotalWallet->fetchColumn() ?: 0.0);
printSuccess([
"challengePoints" => $challengePoints,
"todayEarnings" => $todayEarnings,
"totalWallet" => $totalWallet
]);
} catch (Exception $e) {
printFailure("An error occurred: " . $e->getMessage());
}
?>

View File

@@ -0,0 +1,59 @@
<?php
/**
* add_s2s_debt.php — Payment Server Endpoint
*
* Inserts passenger wallet credit/debit records (debt/penalty).
* Authenticated via X-S2S-Api-Key header matching the S2S_SHARED_KEY environment variable.
*/
require_once __DIR__ . '/../../jwtconnect.php';
define('S2S_SHARED_KEY', getenv('S2S_SHARED_KEY'));
$providedKey = $_SERVER['HTTP_X_S2S_API_KEY'] ?? '';
if (empty($providedKey) || $providedKey !== S2S_SHARED_KEY) {
http_response_code(401);
printFailure("Unauthorized: Invalid or missing X-S2S-Api-Key.");
exit;
}
$passengerID = filterRequest("passengerID");
$amount = filterRequest("amount");
if (empty($passengerID) || !isset($amount)) {
printFailure("Missing required parameters: passengerID, amount");
exit;
}
try {
$con->beginTransaction();
$sql = "INSERT INTO `passengerWallet` (
`passenger_id`,
`balance`
) VALUES (
:passengerID,
:amount
);";
$stmt = $con->prepare($sql);
$stmt->execute([
':passengerID' => $passengerID,
':amount' => $amount
]);
if ($stmt->rowCount() > 0) {
$con->commit();
printSuccess("Record saved successfully");
} else {
$con->rollBack();
printFailure("Failed to save record");
}
} catch (Exception $e) {
if ($con->inTransaction()) {
$con->rollBack();
}
printFailure("An error occurred: " . $e->getMessage());
}
?>