File size: 25,724 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

session_start();
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
    header('Location: ../../index.php');
    exit;
}

// Get user data from session
$username = $_SESSION['username'];
$email = $_SESSION['email'];
$tier = $_SESSION['tier'];
$package = $_SESSION['package'];
$balance = $_SESSION['balance'];
$total_deposits = $_SESSION['total_deposits'];
$total_withdrawals = $_SESSION['total_withdrawals'];
$rewards = $_SESSION['rewards'];
$user_id = $_SESSION['user_id'];
$currency = $_SESSION['currency'] ?? 'KES';

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    require_once '../api/mpesa_service.php';
    require_once '../api/main_account.php';
    
    $amount = $_POST['amount'];
    $payment_method = $_POST['payment_method'];
    $phone_number = $_POST['phone_number'];
    
    // Validate input
    if (empty($amount) || empty($phone_number)) {
        $error = "Please fill all required fields";
    } elseif ($amount < 500) {
        $error = "Minimum recharge amount is 500 " . $currency;
    } else {
        if ($payment_method === 'M-Pesa') {
            // Process M-Pesa STK Push
            $mpesaService = new MpesaService();
            $result = $mpesaService->initiateSTKPush($phone_number, $amount, $user_id);
            
            if (isset($result['success'])) {
                $success = "M-Pesa prompt sent to your phone! Please enter your PIN to complete payment.";
                
                // Record pending transaction
                $mainAccount = new MainAccount();
                $mainAccount->recordPendingTransaction($user_id, $amount, $phone_number, $result['CheckoutRequestID']);
                
                // Add detailed success message
                $success .= " Check your phone for the M-Pesa prompt. Transaction ID: " . $result['CheckoutRequestID'];
                
            } else {
                $error = "Payment initiation failed: " . ($result['message'] ?? 'Please try again later.');
                
                // Log detailed error for debugging
                error_log("M-Pesa Error: " . print_r($result, true));
            }
        } elseif ($payment_method === 'Manual') {
            // Redirect to manual payment page
            $_SESSION['payment_amount'] = $amount;
            $_SESSION['payment_phone'] = $phone_number;
            header('Location: ../api/manual_payment.php');
            exit;
        }
    }
}

// Get currency rates for display
require_once '../../db.php';
$db = new Database();
$conn = $db->getConnection();
$currency_rates = [];
try {
    $stmt = $conn->prepare("SELECT target_currency, exchange_rate FROM currency_rates");
    $stmt->execute();
    $currency_rates = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
} catch (PDOException $e) {
    error_log("Currency rates error: " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Recharge | Japanese Motors</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700;800&display=swap" rel="stylesheet">
    <script src="https://unpkg.com/feather-icons"></script>
    <style>
        :root {
            --bg: #7b848d;
            --card: #7a2f3b;
            --card-2: #6f2630;
            --accent: #efdf2d;
            --muted: rgba(255,255,255,0.6);
            font-family: 'Poppins', system-ui, Arial;
        }
        
        body {
            background: var(--bg);
            font-family: 'Poppins', sans-serif;
            transition: all 0.3s ease;
            min-height: 100vh;
        }
        
        .sidebar {
            width: 250px;
            height: 100vh;
            background: #0d1321;
            color: #fff;
            position: fixed;
            top: 0;
            left: -250px;
            transition: all 0.3s ease;
            z-index: 1000;
            overflow-y: auto;
        }
        
        .sidebar.active {
            left: 0;
        }
        
        #content {
            margin-left: 0;
            transition: all 0.3s ease;
            width: 100%;
        }
        
        .sidebar.active ~ #content {
            margin-left: 250px;
            width: calc(100% - 250px);
        }
        
        header {
            background: #222;
            color: white;
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: relative;
            z-index: 900;
            transition: all 0.3s ease;
        }
        
        .menu-toggle {
            background: transparent;
            border: none;
            color: white;
            font-size: 1.5rem;
            cursor: pointer;
        }
        
        .logo-section {
            padding: 15px;
            border-bottom: 1px solid #1c2230;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .brand {
            font-size: 1.2rem;
            font-weight: 700;
            color: #ff9800;
        }
        
        .subtitle {
            font-size: 0.75rem;
            color: #aaa;
        }
        
        .menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .menu li a {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: white;
            text-decoration: none;
            transition: background 0.3s;
        }
        
        .menu li a:hover {
            background: #1c2230;
        }
        
        .menu li a i {
            margin-right: 12px;
        }
        
        .user-footer {
            padding: 15px;
            background: #222;
            display: flex;
            align-items: center;
            gap: 10px;
            position: sticky;
            bottom: 0;
        }
        
        .avatar {
            width: 35px;
            height: 35px;
            background: #444;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            color: white;
        }
        
        .card {
            background: var(--card);
            border-radius: 12px;
            padding: 26px;
            color: white;
            box-shadow: 0 6px 0 rgba(0,0,0,0.08) inset;
        }
        
        .btn {
            padding: 14px 24px;
            border-radius: 10px;
            background: var(--accent);
            color: #111;
            font-weight: 700;
            border: none;
            cursor: pointer;
            width: 100%;
            transition: all 0.3s ease;
        }
        
        .btn:hover {
            background: #d4c325;
        }
        
        .form-group {
            margin: 12px 0;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            color: rgba(255,255,255,0.85);
        }
        
        input, select {
            width: 100%;
            padding: 14px;
            border-radius: 10px;
            border: 1px solid rgba(255,255,255,0.1);
            background: rgba(255,255,255,0.1);
            color: white;
            box-sizing: border-box;
        }
        
        input:focus, select:focus {
            outline: none;
            border-color: var(--accent);
        }
        
        .payment-option {
            border: 2px solid transparent;
            border-radius: 10px;
            transition: all 0.3s ease;
            cursor: pointer;
            padding: 16px;
        }
        
        .payment-option.selected {
            border-color: var(--accent);
            background: rgba(239, 223, 45, 0.1);
        }
        
        .recharge-package {
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .recharge-package:hover {
            transform: translateY(-2px);
        }
        
        @media (max-width: 768px) {
            .sidebar.active ~ #content {
                margin-left: 0;
                width: 100%;
            }
            
            .sidebar.active {
                width: 100%;
                z-index: 1001;
            }
            
            #menu-toggle-close {
                display: block;
                position: absolute;
                right: 20px;
                top: 20px;
            }
        }
    </style>
</head>
<body>
    <!-- Sidebar -->
    <aside class="sidebar" id="sidebar">
        <button id="menu-toggle-close" class="menu-toggle" style="display: none;">
            <i data-feather="x"></i>
        </button>
        <div class="logo-section">
            <i data-feather="zap" class="text-yellow-400"></i>
            <div>
                <h2 class="brand">JMOTORS</h2>
                <p class="subtitle">Marketing Platform</p>
            </div>
        </div>

        <ul class="menu">
            <li><a href="index.php"><i data-feather="home"></i> Dashboard</a></li>
            <li><a href="meta-uploads.php"><i data-feather="upload"></i> Meta Uploads</a></li>
            <li><a href="transactions.php"><i data-feather="repeat"></i> Transactions</a></li>
            <li><a href="transfer.php"><i data-feather="send"></i> Transfer</a></li>
            <li><a href="daily-product.php"><i data-feather="shopping-bag"></i> Daily Product</a></li>
            <li><a href="withdraw.php"><i data-feather="dollar-sign"></i> Withdraw</a></li>
            <li><a href="packages.php"><i data-feather="package"></i> Packages</a></li>
            <li><a href="loan.php"><i data-feather="credit-card"></i> Loan</a></li>
            <li><a href="recharge.php"><i data-feather="battery-charging"></i> Recharge</a></li>
            <li><a href="agent-approval.php"><i data-feather="user-check"></i> Agent Approval</a></li>
            <li><a href="access-token.php"><i data-feather="key"></i> Access Token</a></li>
            <li><a href="agent-claim.php"><i data-feather="tag"></i> Agent Claim</a></li>
            <li><a href="team.php"><i data-feather="users"></i> Team</a></li>
        </ul>

        <ul class="menu bottom">
            <li><a href="profile.php"><i data-feather="user"></i> Profile</a></li>
            <li><a href="settings.php"><i data-feather="settings"></i> Settings</a></li>
            <li><a href="whatsapp-channel.php"><i data-feather="message-square"></i> Whatsapp Channel</a></li>
            <li><a href="customer-care.php"><i data-feather="headphones"></i> Customer Care</a></li>
        </ul>

        <div class="user-footer">
            <div class="avatar"><?php echo substr($username, 0, 2); ?></div>
            <div>
                <h4><?php echo $username; ?></h4>
                <p><?php echo $tier; ?> - Marketer</p>
            </div>
        </div>
    </aside>

    <!-- Main Content -->
    <div id="content">
        <header class="bg-gray-800 text-white p-4">
            <div class="flex items-center">
                <button class="menu-toggle" id="menu-toggle">
                    <i data-feather="menu"></i>
                </button>
                <div class="ml-4 font-bold text-xl">Jmotors</div>
            </div>
            <nav class="flex items-center space-x-6">
                <a href="transfer.php" class="hover:text-yellow-300">Transfer</a>
                <a href="loan.php" class="hover:text-yellow-300">Loans</a>
                <a href="dailyproduct.php" class="hover:text-yellow-300">New Product</a>
                <div class="w-9 h-9 rounded-full bg-gradient-to-r from-yellow-300 to-orange-400 flex items-center justify-center font-bold"><?php echo substr($username, 0, 2); ?></div>
            </nav>
        </header>

        <main class="p-4">
            <div class="max-w-2xl mx-auto">
                <?php if (isset($error)): ?>
                    <div class="bg-red-500 text-white p-4 rounded-lg mb-4 flex items-center">
                        <i data-feather="alert-circle" class="mr-2"></i>
                        <?php echo $error; ?>
                    </div>
                <?php endif; ?>
                
                <?php if (isset($success)): ?>
                    <div class="bg-green-500 text-white p-4 rounded-lg mb-4">
                        <div class="flex items-center">
                            <i data-feather="check-circle" class="mr-2"></i>
                            <?php echo $success; ?>
                        </div>
                        <div class="mt-2 text-sm">
                            <p>Check your phone for M-Pesa prompt. Enter your PIN to complete payment.</p>
                        </div>
                    </div>
                <?php endif; ?>

                <!-- Quick Deposit Section -->
                <div class="card mb-6">
                    <h2 class="text-xl font-bold mb-6 flex items-center gap-2">
                        <i data-feather="zap" class="text-yellow-400"></i> Quick Deposit
                    </h2>
                    
                    <form method="POST" action="" id="depositForm">
                        <div class="form-group">
                            <label>Amount (<?php echo $currency; ?>)</label>
                            <input type="number" name="amount" placeholder="Enter amount" required min="500" 
                                   class="bg-gray-800 border border-gray-700">
                            <div class="text-xs text-gray-400 mt-1">
                                Minimum amount: 500 <?php echo $currency; ?>
                                <?php 
                                if ($currency !== 'KES') {
                                    $kes_amount = $currency_rates[$currency] ? 500 / $currency_rates[$currency] : 500;
                                    echo ' (' . number_format($kes_amount, 2) . ' KES)';
                                }
                                ?>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label>Payment Method</label>
                            <div class="grid grid-cols-2 gap-4">
                                <div class="payment-option p-4 rounded-lg text-center cursor-pointer" data-method="M-Pesa">
                                    <i data-feather="smartphone" class="text-2xl mb-2 text-green-400"></i>
                                    <p>M-Pesa STK Push</p>
                                    <small class="text-gray-400">InstantAutomatic</small>
                                </div>
                                <div class="payment-option p-4 rounded-lg text-center cursor-pointer" data-method="Manual">
                                    <i data-feather="user-check" class="text-2xl mb-2 text-blue-400"></i>
                                    <p>Manual Verification</p>
                                    <small class="text-gray-400">AdminSecure</small>
                                </div>
                            </div>
                            <input type="hidden" name="payment_method" id="paymentMethod" value="M-Pesa" required>
                        </div>
                        
                        <div class="form-group">
                            <label>Your M-Pesa Phone Number</label>
                            <input type="tel" name="phone_number" placeholder="2547XXXXXXXX" required 
                                   pattern="254[0-9]{9}" class="bg-gray-800 border border-gray-700">
                        </div>
                        
                        <button type="submit" class="btn mt-6 bg-yellow-500 hover:bg-yellow-600 transition">
                            <i data-feather="credit-card" class="mr-2"></i> 
                            <span id="submitText">Initiate M-Pesa Payment</span>
                        </button>
                    </form>
                </div>

                <!-- Payment Methods Info -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <!-- M-Pesa STK Push Method -->
                    <div class="card">
                        <h3 class="text-lg font-bold mb-4 flex items-center gap-2">
                            <i data-feather="smartphone" class="text-green-400"></i> M-Pesa STK Push
                        </h3>
                        <ul class="space-y-2 text-sm">
                            <li class="flex items-center gap-2">
                                <i data-feather="check" class="text-green-400 w-4 h-4"></i>
                                Instant payment processing
                            </li>
                            <li class="flex items-center gap-2">
                                <i data-feather="check" class="text-green-400 w-4 h-4"></i>
                                Automatic balance update
                            </li>
                            <li class="flex items-center gap-2">
                                <i data-feather="check" class="text-green-400 w-4 h-4"></i>
                                Receipt sent to your phone
                            </li>
                        </ul>
                    </div>

                    <!-- Manual Verification Method -->
                    <div class="card">
                        <h3 class="text-lg font-bold mb-4 flex items-center gap-2">
                            <i data-feather="user-check" class="text-blue-400"></i> Manual Verification
                        </h3>
                        <ul class="space-y-2 text-sm">
                            <li class="flex items-center gap-2">
                                <i data-feather="check" class="text-blue-400 w-4 h-4"></i>
                                Upload payment screenshot
                            </li>
                            <li class="flex items-center gap-2">
                                <i data-feather="check" class="text-blue-400 w-4 h-4"></i>
                                Admin verification required
                            </li>
                            <li class="flex items-center gap-2">
                                <i data-feather="check" class="text-blue-400 w-4 h-4"></i>
                                ‎24/7 support available
                            </li>
                        </ul>
                        <div class="mt-4 p-3 bg-blue-900 bg-opacity-20 rounded-lg">
                            <p class="text-sm"><strong>Send to:</strong> Paybill 542542</p>
                            <p class="text-sm"><strong>Account:</strong> 00106664176150</p>
                        </div>
                    </div>
                </div>

                <!-- Package Bonuses -->
                <div class="card mt-6">
                    <h3 class="text-lg font-bold mb-4">Bonus Packages</h3>
                    <div class="grid grid-cols-2 md:grid-cols-3 gap-4">
                        <?php
                        $packages = [
                            500 => 5,
                            1000 => 15,
                            2000 => 40,
                            5000 => 120,
                            10000 => 300,
                            20000 => 700
                        ];
                        
                        foreach ($packages as $amount => $bonus): 
                            $display_amount = $currency === 'KES' ? $amount : number_format($amount * ($currency_rates[$currency] ?? 1), 2);
                        ?>
                            <div class="bg-gray-800 p-4 rounded-lg text-center cursor-pointer hover:bg-gray-700 transition recharge-package"
                                 data-amount="<?php echo $amount; ?>">
                                <div class="font-bold text-yellow-400"><?php echo $display_amount; ?> <?php echo $currency; ?></div>
                                <div class="text-xs mt-1 text-green-400">+<?php echo $bonus; ?> Bonus</div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>

                <!-- Currency Converter -->
                <div class="card mt-6">
                    <h3 class="text-lg font-bold mb-4">Currency Converter</h3>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm">
                        <?php foreach ($currency_rates as $curr => $rate): ?>
                            <?php if ($curr !== 'KES'): ?>
                                <div class="text-center">
                                    <span class="font-bold">1 <?php echo $curr; ?> =</span>
                                    <span class="text-yellow-400"><?php echo number_format(1/$rate, 2); ?> KES</span>
                                </div>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <script>
        feather.replace();
        
        document.addEventListener('DOMContentLoaded', function() {
            const toggleBtn = document.getElementById('menu-toggle');
            const closeBtn = document.getElementById('menu-toggle-close');
            const sidebar = document.getElementById('sidebar');
            const content = document.getElementById('content');
            
            // Toggle sidebar
            toggleBtn.addEventListener('click', function() {
                sidebar.classList.add('active');
                if (window.innerWidth <= 768) {
                    closeBtn.style.display = 'block';
                }
            });
            
            // Close sidebar
            closeBtn.addEventListener('click', function() {
                sidebar.classList.remove('active');
                closeBtn.style.display = 'none';
            });
            
            // Close sidebar when clicking outside on mobile
            document.addEventListener('click', function(event) {
                if (window.innerWidth <= 768 && sidebar.classList.contains('active')) {
                    if (!sidebar.contains(event.target) && event.target !== toggleBtn) {
                        sidebar.classList.remove('active');
                        closeBtn.style.display = 'none';
                    }
                }
            });

            // Package selection
            document.querySelectorAll('.recharge-package').forEach(package => {
                package.addEventListener('click', function() {
                    const amount = this.getAttribute('data-amount');
                    document.querySelector('input[name="amount"]').value = amount;
                });
            });
            
            // Payment method selection
            document.querySelectorAll('.payment-option').forEach(option => {
                option.addEventListener('click', function() {
                    // Remove selected class from all options
                    document.querySelectorAll('.payment-option').forEach(opt => {
                        opt.classList.remove('selected');
                    });
                    
                    // Add selected class to clicked option
                    this.classList.add('selected');
                    
                    // Update hidden input
                    const method = this.getAttribute('data-method');
                    document.getElementById('paymentMethod').value = method;
                    
                    // Update submit button text
                    const submitText = document.getElementById('submitText');
                    if (method === 'M-Pesa') {
                        submitText.textContent = 'Initiate M-Pesa Payment';
                    } else {
                        submitText.textContent = 'Proceed to Manual Payment';
                    }
                });
            });
            
            // Set first payment option as selected by default
            document.querySelector('.payment-option').classList.add('selected');
            
            // Form validation
            document.getElementById('depositForm').addEventListener('submit', function(e) {
                const amount = document.querySelector('input[name="amount"]').value;
                const phone = document.querySelector('input[name="phone_number"]').value;
                
                if (amount < 500) {
                    e.preventDefault();
                    alert('Minimum recharge amount is 500 ' + '<?php echo $currency; ?>');
                    return false;
                }
                
                if (!phone.match(/^254[0-9]{9}$/)) {
                    e.preventDefault();
                    alert('Please enter a valid M-Pesa phone number in the format 2547XXXXXXXX');
                    return false;
                }
            });
        });
        
        // Handle window resize
        window.addEventListener('resize', function() {
            const sidebar = document.getElementById('sidebar');
            const closeBtn = document.getElementById('menu-toggle-close');
            
            if (window.innerWidth > 768) {
                sidebar.classList.remove('active');
                closeBtn.style.display = 'none';
            }
        });
    </script>
</body>
</html>