<?php
/**
 * Test script to verify bKash payment integration
 */
require_once 'config/database.php';
require_once 'includes/bKashPayment.php';

echo "<h1>bKash Payment Integration Test</h1>";

// Test configuration loading
echo "<h2>Configuration Test</h2>";
try {
    $config = get_bkash_config();
    echo "<p style='color: green;'>✓ Configuration loaded successfully</p>";
    echo "<pre>" . print_r($config, true) . "</pre>";
} catch (Exception $e) {
    echo "<p style='color: red;'>✗ Configuration error: " . $e->getMessage() . "</p>";
}

// Test bKash class
echo "<h2>Class Instantiation Test</h2>";
try {
    $bkash = new bKashPayment();
    echo "<p style='color: green;'>✓ bKashPayment class instantiated successfully</p>";
    
    // Test if enabled
    $enabled = $bkash->isEnabled();
    echo "<p>Enabled: " . ($enabled ? 'Yes' : 'No') . "</p>";
    
    if ($enabled) {
        echo "<p style='color: green;'>✓ bKash payment is enabled</p>";
        
        // Test configuration status
        $configStatus = $bkash->getConfigStatus();
        echo "<h3>Configuration Status:</h3>";
        echo "<ul>";
        echo "<li>Enabled: " . ($configStatus['enabled'] ? 'Yes' : 'No') . "</li>";
        echo "<li>App Key Set: " . ($configStatus['app_key_set'] ? 'Yes' : 'No') . "</li>";
        echo "<li>App Secret Set: " . ($configStatus['app_secret_set'] ? 'Yes' : 'No') . "</li>";
        echo "<li>Username Set: " . ($configStatus['username_set'] ? 'Yes' : 'No') . "</li>";
        echo "<li>Password Set: " . ($configStatus['password_set'] ? 'Yes' : 'No') . "</li>";
        echo "<li>Sandbox Mode: " . ($configStatus['sandbox_mode'] ? 'Yes' : 'No') . "</li>";
        echo "<li>Base URL: " . htmlspecialchars($configStatus['base_url']) . "</li>";
        echo "</ul>";
    } else {
        echo "<p style='color: orange;'>⚠ bKash payment is disabled (this is expected if not configured)</p>";
    }
} catch (Exception $e) {
    echo "<p style='color: red;'>✗ bKashPayment class error: " . $e->getMessage() . "</p>";
}

// Test table creation
echo "<h2>Database Tables Test</h2>";
try {
    $result = create_bkash_tables();
    if ($result) {
        echo "<p style='color: green;'>✓ Database tables created/verified successfully</p>";
    } else {
        echo "<p style='color: red;'>✗ Failed to create/verify database tables</p>";
    }
} catch (Exception $e) {
    echo "<p style='color: red;'>✗ Database tables error: " . $e->getMessage() . "</p>";
}

echo "<h2>Integration Status</h2>";
echo "<p>The bKash payment integration is ready for use. To test it:</p>";
echo "<ol>";
echo "<li>Go to Admin Panel → bKash Payment Settings</li>";
echo "<li>Enter your bKash Merchant credentials</li>";
echo "<li>Enable bKash Payment</li>";
echo "<li>Login as a student and go to 'ফি ম্যানেজ' → 'আমার ফি'</li>";
echo "<li>If you have due fees, you'll see an 'bKash Personal' payment button</li>";
echo "<li>Click the button to initiate payment</li>";
echo "</ol>";

echo "<p><a href='fees/my_fees.php'>Go to My Fees</a> | <a href='admin/bKash_settings.php'>Configure bKash Payment</a></p>";
?>