Update: 2026-06-26 04:04:03

This commit is contained in:
Hamza-Ayed
2026-06-26 04:04:04 +03:00
parent aea0c8e44e
commit da9e6eb981
10 changed files with 325 additions and 112 deletions

View File

@@ -373,6 +373,7 @@ function calculateDynamicPrice($country, $minFare, $distance, $duration, $kazanR
// 2. Validate Promo Code
$discount = 0;
$promo_applied = false;
if (!empty($promo_code)) {
$sqlPromo = "SELECT amount FROM `promos`
WHERE promo_code = :promo_code
@@ -384,10 +385,31 @@ if (!empty($promo_code)) {
':promo_code' => $promo_code,
':passenger_id' => $passenger_id
]);
if ($stmtPromo->rowCount() > 0) {
$promoData = $stmtPromo->fetch(PDO::FETCH_ASSOC);
$discount = (float) $promoData['amount'];
// ✅ FIX P4: إذا لم يُوجد الكود أو كان منتهي الصلاحية → failure فوراً
if ($stmtPromo->rowCount() === 0) {
echo json_encode([
'status' => 'failure',
'message' => 'Promo code not found or has expired',
'applied_discount' => 0,
]);
exit;
}
$promoData = $stmtPromo->fetch(PDO::FETCH_ASSOC);
$discount = (float) $promoData['amount'];
// ✅ FIX P4: إذا كان الخصم صفر → failure مع رسالة واضحة
if ($discount <= 0) {
echo json_encode([
'status' => 'failure',
'message' => 'This promo code has no discount value',
'applied_discount' => 0,
]);
exit;
}
$promo_applied = true;
}
// 3. Fetch Passenger Wallet (Negative Balance / Debt)