File size: 3,227 Bytes
0dff816
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header('Location: login.php');
    exit;
}

require_once '../../db.php';
require_once '../api/main_account.php';

$mainAccount = new MainAccount();
$pendingPayments = $mainAccount->getPendingPayments();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $payment_id = $_POST['payment_id'];
    $action = $_POST['action'];
    $notes = $_POST['notes'] ?? '';
    
    if ($action === 'verify') {
        $result = $mainAccount->verifyPayment($payment_id, $_SESSION['admin_id'], $notes);
    } else {
        $result = $mainAccount->rejectPayment($payment_id, $_SESSION['admin_id'], $notes);
    }
    
    if ($result['success']) {
        $message = $action === 'verify' ? "Payment verified successfully!" : "Payment rejected!";
    } else {
        $error = $result['error'];
    }
}
?>

<!-- Admin Payment Verification Interface -->
<div class="container mx-auto p-6">
    <h1 class="text-2xl font-bold mb-6">Payment Verification</h1>
    
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
        <?php foreach ($pendingPayments as $payment): ?>
        <div class="bg-white rounded-lg shadow p-6">
            <div class="flex justify-between items-center mb-4">
                <h3 class="font-bold">Payment #<?php echo $payment['id']; ?></h3>
                <span class="bg-yellow-100 text-yellow-800 px-2 py-1 rounded text-sm">Pending</span>
            </div>
            
            <div class="space-y-2">
                <p><strong>User:</strong> <?php echo $payment['username']; ?></p>
                <p><strong>Amount:</strong> KES <?php echo number_format($payment['amount']); ?></p>
                <p><strong>Phone:</strong> <?php echo $payment['phone_number']; ?></p>
                <p><strong>M-Pesa Code:</strong> <?php echo $payment['mpesa_code']; ?></p>
                <p><strong>Submitted:</strong> <?php echo date('M j, Y H:i', strtotime($payment['created_at'])); ?></p>
            </div>
            
            <?php if ($payment['screenshot']): ?>
            <div class="mt-4">
                <img src="../uploads/payments/<?php echo $payment['screenshot']; ?>" 
                     alt="Payment Proof" class="rounded border max-w-full">
            </div>
            <?php endif; ?>
            
            <form method="POST" class="mt-4 space-y-2">
                <input type="hidden" name="payment_id" value="<?php echo $payment['id']; ?>">
                <textarea name="notes" placeholder="Verification notes..." class="w-full p-2 border rounded"></textarea>
                <div class="flex gap-2">
                    <button type="submit" name="action" value="verify" 
                            class="flex-1 bg-green-500 text-white p-2 rounded hover:bg-green-600">
                        Verify
                    </button>
                    <button type="submit" name="action" value="reject" 
                            class="flex-1 bg-red-500 text-white p-2 rounded hover:bg-red-600">
                        Reject
                    </button>
                </div>
            </form>
        </div>
        <?php endforeach; ?>
    </div>
</div>