<?php
session_start();
include 'cfg.php';

if (!isset($_SESSION['voucher_code'])) {
    http_response_code(400);
    exit("No voucher session");
}

$voucher_code = $_SESSION['voucher_code'];
$result = $_GET['result'] ?? '';

// Update voucher agar tidak bisa dipakai lagi
$stmt = $pdo->prepare("UPDATE vouchers SET is_used = 1 WHERE code = ?");
$stmt->execute([$voucher_code]);

// Hapus sesi agar tidak bisa kembali menggunakan back button
session_destroy();

echo "OK";
