<?php
include '../db.php';
include '../includes/tax_helpers.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $payment_method = $_POST['payment_method'] ?? '';
    $tax_rate = floatval($_POST['tax_rate'] ?? 0);
    
    if (!empty($payment_method) && isValidTaxRate($tax_rate)) {
        $stmt = $conn->prepare("INSERT INTO payment_method_tax_rates (payment_method, tax_rate) VALUES (?, ?) ON DUPLICATE KEY UPDATE tax_rate = ?");
        $stmt->bind_param("sdd", $payment_method, $tax_rate, $tax_rate);
        
        if ($stmt->execute()) {
            echo "success";
        } else {
            echo "error: " . $stmt->error;
        }
        $stmt->close();
    } else {
        echo "error: Invalid payment method or tax rate";
    }
} else {
    echo "error: Invalid request method";
}
?>
