diff --git a/backend/ride/pricing/get.php b/backend/ride/pricing/get.php index 17a9bf8d..7637c565 100644 --- a/backend/ride/pricing/get.php +++ b/backend/ride/pricing/get.php @@ -45,15 +45,19 @@ $hour = (int)$currentTime->format('H'); switch ($country) { case 'Syria': $minFare = 150.0; + $promoMaxDiscount = 30.0; break; case 'Egypt': $minFare = 20.0; + $promoMaxDiscount = 25.0; break; case 'Jordan': $minFare = 1.0; + $promoMaxDiscount = 0.30; break; default: $minFare = 0.0; + $promoMaxDiscount = 0.0; break; } @@ -450,10 +454,23 @@ foreach ($categories as $key => $carType) { $price_for_driver = $result['price_for_driver']; // Apply discount + $discountAmount = 0; if ($discount > 0 && $discount <= 100) { - $finalPrice = max(0, $withCommission - ($withCommission * ($discount / 100))); + $discountAmount = $withCommission * ($discount / 100); } else { - $finalPrice = max(0, $withCommission - $discount); + $discountAmount = $discount; + } + + // Cap discount by country-specific max + if ($promoMaxDiscount > 0 && $discountAmount > $promoMaxDiscount) { + $discountAmount = $promoMaxDiscount; + } + + $finalPrice = max(0, $withCommission - $discountAmount); + + // Ensure final price doesn't go below minimum fare + if ($finalPrice < $minFare) { + $finalPrice = $minFare; } // Add negative balance