Update: 2026-05-09 17:21:01

This commit is contained in:
Hamza-Ayed
2026-05-09 17:21:01 +03:00
parent f75e2719fa
commit c94855ed9c
5 changed files with 198 additions and 84 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -0,0 +1,45 @@
<?php
/**
* Delete/Cancel Payment Request (Admin/Accountant)
* POST /api/v1/payments/delete
*/
declare(strict_types=1);
use App\Core\Database;
use App\Middleware\AuthMiddleware;
try {
$decoded = AuthMiddleware::check();
$db = Database::getInstance();
$tenantId = $decoded['tenant_id'];
$data = json_decode(file_get_contents('php://input'), true);
$paymentId = $data['payment_id'] ?? null;
if (!$paymentId) {
json_error('معرف طلب الدفع مطلوب.', 422);
}
// Only allow deleting PENDING requests
$stmt = $db->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);
}