41 lines
1.5 KiB
PHP
41 lines
1.5 KiB
PHP
<?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");
|
|
} |