<?php
/**
 * Fix UddoktaPay Settings Script
 * 
 * This script will automatically update the UddoktaPay base URL to the correct endpoint
 * if it's currently set to the placeholder value.
 */

require_once 'config/database.php';

echo "Checking UddoktaPay settings...\n";

try {
    // Get current settings
    $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key LIKE 'uddoktapay_%'");
    $results = $stmt->fetchAll();
    
    echo "Current UddoktaPay settings:\n";
    foreach ($results as $row) {
        echo "  " . $row['setting_key'] . " = " . $row['setting_value'] . "\n";
    }
    
    // Check if base URL is set to placeholder
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'uddoktapay_base_url'");
    $stmt->execute();
    $result = $stmt->fetch();
    
    if ($result && $result['setting_value'] === 'https://pay.your-domain.com') {
        echo "\nFixing UddoktaPay base URL...\n";
        
        // Update to correct URL
        $stmt = $pdo->prepare("UPDATE settings SET setting_value = 'https://api.uddoktapay.com' WHERE setting_key = 'uddoktapay_base_url'");
        $stmt->execute();
        
        echo "UddoktaPay base URL updated successfully!\n";
        
        // Verify the update
        $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'uddoktapay_base_url'");
        $stmt->execute();
        $result = $stmt->fetch();
        
        echo "New base URL: " . $result['setting_value'] . "\n";
    } else {
        echo "\nUddoktaPay base URL appears to be correctly configured.\n";
    }
    
    echo "\nUddoktaPay settings fix completed.\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>