Update: 2026-06-11 18:22:57
This commit is contained in:
41
walletintaleq.intaleq.xyz/v2/main/ride/payment/add.php
Normal file
41
walletintaleq.intaleq.xyz/v2/main/ride/payment/add.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
include "../../connect.php";
|
||||
///ride/payment/add.php
|
||||
$amount = filterRequest("amount");
|
||||
$payment_method = filterRequest("payment_method");
|
||||
$passengerID = filterRequest("passengerID");
|
||||
$rideId = filterRequest("rideId");
|
||||
$driverID = filterRequest("driverID");
|
||||
$token = filterRequest("token");
|
||||
|
||||
// ✅ تحقق من التوكن
|
||||
$stmt = $con->prepare("SELECT * FROM payment_tokens WHERE token = :token AND isUsed = FALSE");
|
||||
$stmt->execute([ ':token' => $token ]);
|
||||
$tokenData = $stmt->fetch();
|
||||
|
||||
if ($tokenData) {
|
||||
// ✅ إدخال الدفع بمفتاح قصير وخفيف
|
||||
$sql = "INSERT INTO payments (id, amount, payment_method, passengerID, rideId, driverID)
|
||||
VALUES (UUID_SHORT(), :amount, :payment_method, :passengerID, :rideId, :driverID)";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute([
|
||||
':amount' => $amount,
|
||||
':payment_method' => $payment_method,
|
||||
':passengerID' => $passengerID,
|
||||
':rideId' => $rideId,
|
||||
':driverID' => $driverID
|
||||
]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
printSuccess("Payment record created successfully");
|
||||
|
||||
// ✅ تحديث حالة التوكن
|
||||
$stmt = $con->prepare("UPDATE payment_tokens SET isUsed = TRUE WHERE id = :tokenID");
|
||||
$stmt->execute([ ':tokenID' => $tokenData['id'] ]);
|
||||
} else {
|
||||
printFailure("Failed to save record");
|
||||
}
|
||||
} else {
|
||||
printFailure("Invalid or already used token");
|
||||
}
|
||||
60
walletintaleq.intaleq.xyz/v2/main/ride/payment/get.php
Normal file
60
walletintaleq.intaleq.xyz/v2/main/ride/payment/get.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
|
||||
include "../../connect.php";
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
// الخطوة 1: جلب كل سجلات الدفع لليوم الحالي
|
||||
$sql_records = "SELECT
|
||||
id,
|
||||
amount,
|
||||
payment_method,
|
||||
isGiven,
|
||||
passengerID,
|
||||
rideId,
|
||||
created_at
|
||||
FROM
|
||||
payments
|
||||
WHERE
|
||||
driverID = ?
|
||||
AND DATE(created_at) = CURDATE()
|
||||
";
|
||||
|
||||
$stmt_records = $con->prepare($sql_records);
|
||||
$stmt_records->execute([$driverID]);
|
||||
$records = $stmt_records->fetchAll(PDO::FETCH_ASSOC);
|
||||
$count = $stmt_records->rowCount();
|
||||
|
||||
if ($count > 0) {
|
||||
// الخطوة 2: حساب المجموع اليومي في استعلام منفصل وآمن
|
||||
$sql_sum = "SELECT
|
||||
COALESCE(SUM(amount), 0) AS todayAmount
|
||||
FROM
|
||||
payments
|
||||
WHERE
|
||||
driverID = ?
|
||||
AND DATE(created_at) = CURDATE()
|
||||
-- AND isGiven !='waiting'";
|
||||
|
||||
$stmt_sum = $con->prepare($sql_sum);
|
||||
$stmt_sum->execute([$driverID]);
|
||||
$total_row = $stmt_sum->fetch(PDO::FETCH_ASSOC);
|
||||
$todayAmount = $total_row['todayAmount'];
|
||||
|
||||
// الخطوة 3: إضافة المجموع الكلي لكل سجل في القائمة
|
||||
$response_data = [];
|
||||
foreach ($records as $record) {
|
||||
$record['todayAmount'] = $todayAmount; // أضف المجموع هنا
|
||||
$response_data[] = $record;
|
||||
}
|
||||
|
||||
// إرسال البيانات بالهيكلية التي يتوقعها التطبيق
|
||||
printSuccess( $response_data);
|
||||
|
||||
} else {
|
||||
// في حالة عدم وجود أي دفعات اليوم
|
||||
printFailure($message = "No wallet record found");
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
include "../../connect.php";
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
$sql = "SELECT
|
||||
(
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
`ride`
|
||||
WHERE
|
||||
`ride`.`status` = 'Finished'
|
||||
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
|
||||
`ride`.`status` = 'Finished'
|
||||
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 `ride`.`status` = 'Finished'
|
||||
AND `ride`.`created_at` > CURRENT_DATE() - INTERVAL 1 WEEK
|
||||
) AS total_amount_last_week
|
||||
FROM
|
||||
dual
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
";
|
||||
$stmt = $con->prepare($sql);
|
||||
$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");
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
include "../../connect.php";
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
$sql = "SELECT
|
||||
driverID,
|
||||
COALESCE(SUM(amount), 0) AS total_amount,
|
||||
COALESCE(SUM(amount), 0) + COALESCE(
|
||||
(
|
||||
SELECT
|
||||
SUM(`amount`)
|
||||
FROM
|
||||
`paymentsDriverPoints`
|
||||
WHERE
|
||||
`payment_method` = 'fromBudgetToPoints' AND `driverID` = '$driverID'
|
||||
),
|
||||
0
|
||||
) AS diff
|
||||
FROM
|
||||
payments
|
||||
WHERE
|
||||
isGiven = 'waiting'
|
||||
AND `payment_method` IN ('visa-in', 'visa', 'visaRide', 'TransferFrom', 'payout', 'TransferTo')
|
||||
AND `driverID` = '$driverID'";
|
||||
$stmt = $con->prepare($sql);
|
||||
$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");
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
include "../../connect.php";
|
||||
$driver_id = filterRequest("driver_id");
|
||||
|
||||
$sql = "SELECT
|
||||
COUNT(id) AS count
|
||||
FROM
|
||||
`ride`
|
||||
WHERE
|
||||
`ride`.`status` = 'Finished'
|
||||
AND driver_id = '$driver_id'
|
||||
AND created_at >= CURDATE();
|
||||
";
|
||||
$stmt = $con->prepare($sql);
|
||||
$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");
|
||||
}
|
||||
?>
|
||||
141
walletintaleq.intaleq.xyz/v2/main/ride/payment/process_ride_payments.php
Executable file
141
walletintaleq.intaleq.xyz/v2/main/ride/payment/process_ride_payments.php
Executable file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* process_ride_payments.php — Payment Processing Server
|
||||
*
|
||||
* Receives S2S (Server-to-Server) requests from finish_ride_updates.php.
|
||||
* Authenticated via X-S2S-Api-Key header matching a shared secret.
|
||||
*
|
||||
* Flow:
|
||||
* 1. Validate X-S2S-Api-Key header
|
||||
* 2. BEGIN TRANSACTION
|
||||
* 3. Insert payment record
|
||||
* 4. Deduct from passenger wallet (if walletChecked)
|
||||
* 5. Settle passenger debt (if negative balance)
|
||||
* 6. Deduct driver points (8%)
|
||||
* 7. COMMIT / ROLLBACK on failure
|
||||
*/
|
||||
|
||||
// Adjust path as needed for your payment server structure
|
||||
require_once __DIR__ . '/../../jwtconnect.php';
|
||||
|
||||
// === Secure S2S Configuration ===
|
||||
define('S2S_SHARED_KEY', getenv('S2S_SHARED_KEY'));
|
||||
|
||||
// ============================================================
|
||||
// 1. API Key Authentication (X-S2S-Api-Key header)
|
||||
// ============================================================
|
||||
$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;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 2. Receive All Required Parameters
|
||||
// ============================================================
|
||||
$rideId = filterRequest("rideId");
|
||||
$driverId = filterRequest("driverId");
|
||||
$passengerId = filterRequest("passengerId");
|
||||
$paymentAmount = filterRequest("paymentAmount");
|
||||
$paymentMethod = filterRequest("paymentMethod");
|
||||
$walletChecked = filterRequest("walletChecked"); // 'true' or 'false'
|
||||
$passengerWalletBurc = filterRequest("passengerWalletBurc"); // passenger balance before operation
|
||||
$authToken = filterRequest("authToken"); // kept for logging/audit, not used for auth
|
||||
|
||||
// --- Validate required fields ---
|
||||
if (empty($rideId) || empty($driverId) || empty($passengerId) ||
|
||||
!isset($paymentAmount) || empty($paymentMethod) ||
|
||||
!isset($walletChecked) || !isset($passengerWalletBurc)) {
|
||||
printFailure("Missing required parameters for payment processing.");
|
||||
exit;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 3. Atomic Payment Processing
|
||||
// ============================================================
|
||||
try {
|
||||
// --- Begin Transaction ---
|
||||
$con->beginTransaction();
|
||||
|
||||
// 3a. Insert main payment record
|
||||
$finalPaymentMethod = ($walletChecked === 'true') ? $paymentMethod . "Ride" : $paymentMethod;
|
||||
$stmtPayment = $con->prepare(
|
||||
"INSERT INTO payments (id, amount, payment_method, passengerID, rideId, driverID)
|
||||
VALUES (UUID_SHORT(), :amount, :payment_method, :passengerID, :rideId, :driverID)"
|
||||
);
|
||||
$stmtPayment->execute([
|
||||
':amount' => $paymentAmount,
|
||||
':payment_method' => $finalPaymentMethod,
|
||||
':passengerID' => $passengerId,
|
||||
':rideId' => $rideId,
|
||||
':driverID' => $driverId,
|
||||
]);
|
||||
|
||||
if ($stmtPayment->rowCount() <= 0) {
|
||||
throw new Exception("Failed to create payment record.");
|
||||
}
|
||||
|
||||
// 3b. Deduct from passenger wallet (if wallet payment)
|
||||
if ($walletChecked === 'true') {
|
||||
$stmtPassengerWallet = $con->prepare(
|
||||
"INSERT INTO `passengerWallet` (`passenger_id`, `balance`)
|
||||
VALUES (:passenger_id, :balance)"
|
||||
);
|
||||
$stmtPassengerWallet->execute([
|
||||
':passenger_id' => $passengerId,
|
||||
':balance' => (-1) * floatval($paymentAmount),
|
||||
]);
|
||||
|
||||
if ($stmtPassengerWallet->rowCount() <= 0) {
|
||||
throw new Exception("Failed to deduct from passenger wallet.");
|
||||
}
|
||||
}
|
||||
|
||||
// 3c. Settle existing passenger debt (if balance was negative)
|
||||
if (floatval($passengerWalletBurc) < 0) {
|
||||
$stmtPassengerDebt = $con->prepare(
|
||||
"INSERT INTO `passengerWallet` (`passenger_id`, `balance`)
|
||||
VALUES (:passenger_id, :balance)"
|
||||
);
|
||||
$stmtPassengerDebt->execute([
|
||||
':passenger_id' => $passengerId,
|
||||
':balance' => (-1) * floatval($passengerWalletBurc),
|
||||
]);
|
||||
|
||||
if ($stmtPassengerDebt->rowCount() <= 0) {
|
||||
throw new Exception("Failed to settle passenger debt.");
|
||||
}
|
||||
}
|
||||
|
||||
// 3d. Deduct driver points (8% of payment amount)
|
||||
$pointsSubtraction = floatval($paymentAmount) * (-0.08);
|
||||
$stmtDriverPoints = $con->prepare(
|
||||
"INSERT INTO `driverWallet` (`driverID`, `paymentID`, `amount`, `paymentMethod`)
|
||||
VALUES (:driverID, :paymentID, :amount, :paymentMethod)"
|
||||
);
|
||||
$stmtDriverPoints->execute([
|
||||
':driverID' => $driverId,
|
||||
':paymentID' => 'rideId' . $rideId,
|
||||
':amount' => number_format($pointsSubtraction, 0, '', ''),
|
||||
':paymentMethod' => $paymentMethod,
|
||||
]);
|
||||
|
||||
if ($stmtDriverPoints->rowCount() <= 0) {
|
||||
throw new Exception("Failed to update driver wallet points.");
|
||||
}
|
||||
|
||||
// --- All operations succeeded → Commit ---
|
||||
$con->commit();
|
||||
|
||||
printSuccess("Payment processed successfully for ride $rideId.");
|
||||
|
||||
} catch (Exception $e) {
|
||||
// --- Any failure → Rollback all changes ---
|
||||
if (isset($con) && $con->inTransaction()) {
|
||||
$con->rollBack();
|
||||
}
|
||||
error_log("[process_ride_payments] Transaction FAILED for ride $rideId: " . $e->getMessage());
|
||||
printFailure("Transaction failed: " . $e->getMessage());
|
||||
}
|
||||
65
walletintaleq.intaleq.xyz/v2/main/ride/payment/update.php
Normal file
65
walletintaleq.intaleq.xyz/v2/main/ride/payment/update.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
include "../../connect.php";
|
||||
|
||||
$id = filterRequest("id");
|
||||
|
||||
// Create an empty array to store the column-value pairs
|
||||
$columnValues = array();
|
||||
|
||||
// Check if each column is set in the request and add it to the array
|
||||
if (isset($_POST["amount"])) {
|
||||
$amount = filterRequest("amount");
|
||||
$columnValues[] = "`amount` = '$amount'";
|
||||
}
|
||||
|
||||
if (isset($_POST["payment_method"])) {
|
||||
$payment_method = filterRequest("payment_method");
|
||||
$columnValues[] = "`payment_method` = '$payment_method'";
|
||||
}
|
||||
|
||||
if (isset($_POST["passengerID"])) {
|
||||
$passengerID = filterRequest("passengerID");
|
||||
$columnValues[] = "`passengerID` = '$passengerID'";
|
||||
}
|
||||
|
||||
if (isset($_POST["rideId"])) {
|
||||
$rideId = filterRequest("rideId");
|
||||
$columnValues[] = "`rideId` = '$rideId'";
|
||||
}
|
||||
|
||||
if (isset($_POST["driverID"])) {
|
||||
$driverID = filterRequest("driverID");
|
||||
$columnValues[] = "`driverID` = '$driverID'";
|
||||
}
|
||||
|
||||
if (isset($_POST["created_at"])) {
|
||||
$created_at = filterRequest("created_at");
|
||||
$columnValues[] = "`created_at` = '$created_at'";
|
||||
}
|
||||
|
||||
if (isset($_POST["updated_at"])) {
|
||||
$updated_at = filterRequest("updated_at");
|
||||
$columnValues[] = "`updated_at` = '$updated_at'";
|
||||
}
|
||||
|
||||
if (isset($_POST["isGiven"])) {
|
||||
$isGiven = filterRequest("isGiven");
|
||||
$columnValues[] = "`isGiven` = '$isGiven'";
|
||||
}
|
||||
|
||||
// Construct the SET clause of the update query using the column-value pairs
|
||||
$setClause = implode(", ", $columnValues);
|
||||
|
||||
$sql = "UPDATE `payments` SET $setClause WHERE `id` = '$id'";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Print a success message
|
||||
printSuccess($message = "Payment data updated successfully");
|
||||
} else {
|
||||
// Print a failure message
|
||||
printFailure($message = "Failed to update payment data");
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
include "../../connect.php";
|
||||
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
|
||||
$sql = "UPDATE `payments` SET `isGiven`='Paid' WHERE driverID='$driverID'";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Print a success message
|
||||
printSuccess($message = "Payment data updated successfully");
|
||||
} else {
|
||||
// Print a failure message
|
||||
printFailure($message = "Failed to update payment data");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user