<?php

header("Content-Type: application/json");

require_once("../config/database.php");

$db = getDB();

$code =
$_GET['code']
?? '';

$code =
$db->real_escape_string(
$code
);

$result =
$db->query("SELECT *

FROM coupons

WHERE code='$code'

AND is_active=1

LIMIT 1");

if($result->num_rows == 0){

echo json_encode([

"success" => false
]);

exit;
}

$coupon =
$result->fetch_assoc();

echo json_encode([

"success" => true,

"discount" =>
$coupon['discount_percent']
]);