Update: 2026-08-07 02:32:14
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// ============================================================
|
||||
// preview_cancel_fee.php — كم سيكلّف الإلغاء؟ (بلا إلغاء)
|
||||
//
|
||||
// نقطة قراءة خالصة: تحسب الرسم بنفس دالة الإلغاء الفعلي ولا تغيّر شيئاً.
|
||||
// بدونها لا يستطيع التطبيق تحذير الراكب قبل الضغط، فيكتشف الخصم بعد
|
||||
// فوات الأوان — وهذا أسرع طريق لشكوى ومراجعة سيئة.
|
||||
//
|
||||
// تستخدم computePassengerCancelFee نفسها عمداً: أي تحذير يخالف ما يُخصم
|
||||
// فعلاً أسوأ من غياب التحذير أصلاً.
|
||||
// ============================================================
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
require_once __DIR__ . '/../pricing/pricing_helper.php';
|
||||
require_once __DIR__ . '/cancel_fee_helper.php';
|
||||
|
||||
$rideId = filterRequest("ride_id");
|
||||
|
||||
if (!$rideId) {
|
||||
jsonError("Missing Ride ID");
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $con->prepare("SELECT * FROM ride WHERE id = ?");
|
||||
$stmt->execute([$rideId]);
|
||||
$ride = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$ride) {
|
||||
jsonError("Ride not found", 404);
|
||||
}
|
||||
|
||||
// رحلة بدأت فعلاً لا تُلغى أصلاً — نفس شرط الإلغاء الحقيقي.
|
||||
if (($ride['status'] ?? '') === 'Begin') {
|
||||
jsonError("Cannot cancel started ride");
|
||||
}
|
||||
|
||||
$exemptReason = '';
|
||||
$currency = 'SYP';
|
||||
$fee = computePassengerCancelFee(
|
||||
$con, $redisLocation ?? null, $rideId, $ride,
|
||||
$ride['driver_id'] ?? '0', $exemptReason, $currency
|
||||
);
|
||||
|
||||
jsonSuccess([
|
||||
'cancel_fee' => $fee,
|
||||
'fee_currency' => $currency,
|
||||
'fee_exempt' => $fee > 0 ? '' : $exemptReason,
|
||||
'will_charge' => $fee > 0,
|
||||
], "ok");
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("[preview_cancel_fee] " . $e->getMessage());
|
||||
jsonError("DB Error", 500);
|
||||
}
|
||||
Reference in New Issue
Block a user