<?php
require_once 'config/database.php';

echo "Debugging Zashof API Key:\n";
echo "========================\n";

try {
    // Direct database query to check settings
    $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key LIKE 'zashof_%'");
    $settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    
    foreach ($settings as $key => $value) {
        // For API key, show only first and last few characters
        $display_value = $value;
        if ($key === 'zashof_api_key' && strlen($value) > 20) {
            $display_value = substr($value, 0, 10) . '...' . substr($value, -10);
        }
        
        echo $key . ": " . $display_value . "\n";
    }
    
    // Check if API key exists and is not empty
    if (isset($settings['zashof_api_key']) && !empty($settings['zashof_api_key'])) {
        echo "\nAPI Key Status: VALID\n";
        echo "API Key Length: " . strlen($settings['zashof_api_key']) . " characters\n";
    } else {
        echo "\nAPI Key Status: MISSING or EMPTY\n";
    }
    
    // Test the Zashof class
    require_once 'includes/zashof.php';
    $zashof = new ZashofPayment();
    
    echo "\nZashofPayment Class Test:\n";
    echo "========================\n";
    echo "isEnabled(): " . ($zashof->isEnabled() ? 'YES' : 'NO') . "\n";
    
    $configStatus = $zashof->getConfigStatus();
    echo "Config Status:\n";
    foreach ($configStatus as $key => $value) {
        echo "  " . $key . ": " . ($value ? 'SET' : 'NOT SET') . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>