22 lines
637 B
PHP
22 lines
637 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
header('Content-Type: application/json');
|
|
require_once '../db/config.php';
|
|
|
|
$code = $_GET['code'] ?? '';
|
|
|
|
if (empty($code)) {
|
|
echo json_encode(['success' => false, 'error' => 'Kode voucher harus diisi']);
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
$stmt = $db->prepare("SELECT * FROM vouchers WHERE code = ? AND is_used = 0 AND (expires_at IS NULL OR expires_at > NOW())");
|
|
$stmt->execute([$code]);
|
|
$voucher = $stmt->fetch();
|
|
|
|
if ($voucher) {
|
|
echo json_encode(['success' => true, 'voucher' => $voucher]);
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => 'Voucher tidak valid atau sudah kedaluwarsa']);
|
|
} |