Update: 2026-05-09 17:21:01
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
45
app/modules_app/payments/delete.php
Normal file
45
app/modules_app/payments/delete.php
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user