diff --git a/app/Middleware/QuotaMiddleware.php b/app/Middleware/QuotaMiddleware.php index 0dff7c1..fa09e02 100644 --- a/app/Middleware/QuotaMiddleware.php +++ b/app/Middleware/QuotaMiddleware.php @@ -230,6 +230,11 @@ final class QuotaMiddleware $companiesLimit = (int)$sub['max_companies']; $usersLimit = (int)($sub['max_users'] ?? 999); + // Check for pending payment request + $stmt = $db->prepare("SELECT id, plan_id, internal_reference FROM payment_requests WHERE tenant_id = ? AND status = 'pending' LIMIT 1"); + $stmt->execute([$tenantId]); + $pendingPayment = $stmt->fetch(); + return [ 'has_subscription' => true, 'plan_id' => $sub['plan_id'] ?? 'free', @@ -239,6 +244,11 @@ final class QuotaMiddleware 'status' => $sub['status'], 'ai_features' => (bool)($sub['ai_features'] ?? false), 'jofotara_enabled' => (bool)($sub['jofotara_enabled'] ?? false), + 'pending_payment' => $pendingPayment ? [ + 'id' => $pendingPayment['id'], + 'plan_id' => $pendingPayment['plan_id'], + 'reference' => $pendingPayment['internal_reference'] + ] : null, 'invoices' => [ 'used' => $invoicesUsed, diff --git a/app/middleware/QuotaMiddleware.php b/app/middleware/QuotaMiddleware.php index 0dff7c1..fa09e02 100644 --- a/app/middleware/QuotaMiddleware.php +++ b/app/middleware/QuotaMiddleware.php @@ -230,6 +230,11 @@ final class QuotaMiddleware $companiesLimit = (int)$sub['max_companies']; $usersLimit = (int)($sub['max_users'] ?? 999); + // Check for pending payment request + $stmt = $db->prepare("SELECT id, plan_id, internal_reference FROM payment_requests WHERE tenant_id = ? AND status = 'pending' LIMIT 1"); + $stmt->execute([$tenantId]); + $pendingPayment = $stmt->fetch(); + return [ 'has_subscription' => true, 'plan_id' => $sub['plan_id'] ?? 'free', @@ -239,6 +244,11 @@ final class QuotaMiddleware 'status' => $sub['status'], 'ai_features' => (bool)($sub['ai_features'] ?? false), 'jofotara_enabled' => (bool)($sub['jofotara_enabled'] ?? false), + 'pending_payment' => $pendingPayment ? [ + 'id' => $pendingPayment['id'], + 'plan_id' => $pendingPayment['plan_id'], + 'reference' => $pendingPayment['internal_reference'] + ] : null, 'invoices' => [ 'used' => $invoicesUsed, diff --git a/app/modules_app/payments/delete.php b/app/modules_app/payments/delete.php new file mode 100644 index 0000000..2b8509a --- /dev/null +++ b/app/modules_app/payments/delete.php @@ -0,0 +1,45 @@ +prepare("SELECT id FROM payment_requests WHERE id = ? AND tenant_id = ? AND status = 'pending'"); + $stmt->execute([$paymentId, $tenantId]); + $payment = $stmt->fetch(); + + if (!$payment) { + json_error('لا يمكن حذف هذا الطلب (قد يكون مقبولاً بالفعل أو غير موجود).', 404); + } + + $stmt = $db->prepare("DELETE FROM payment_requests WHERE id = ? AND tenant_id = ?"); + $stmt->execute([$paymentId, $tenantId]); + + // Log deletion + $logStmt = $db->prepare("INSERT INTO audit_logs (tenant_id, user_id, action, entity_type, entity_id) VALUES (?, ?, 'payment.deleted', 'payment', ?)"); + $logStmt->execute([$tenantId, $decoded['user_id'], $paymentId]); + + json_success([], 'تم إلغاء طلب الدفع بنجاح.'); + +} catch (\Throwable $e) { + error_log("Payment Delete Error: " . $e->getMessage()); + json_error('حدث خطأ أثناء حذف طلب الدفع.', 500); +} diff --git a/public/index.php b/public/index.php index ade5f9c..796af84 100644 --- a/public/index.php +++ b/public/index.php @@ -77,6 +77,7 @@ $routes = [ 'v1/payments/my-requests' => ['GET', 'payments/my_requests.php'], 'v1/payments/review' => ['POST', 'payments/review.php'], 'v1/payments/stats' => ['GET', 'payments/stats.php'], + 'v1/payments/delete' => ['POST', 'payments/delete.php'], // Voice Assistant Proxies 'v1/voice/transcribe' => ['POST', 'voice/transcribe.php'], diff --git a/public/shell.php b/public/shell.php index c40410f..a72c572 100644 --- a/public/shell.php +++ b/public/shell.php @@ -7,7 +7,7 @@