File: /var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_discount_check.php
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
include("../../../../wp-config.php");
global $wpdb;
$PSY_DISCOUNT_CODE = $wpdb->prefix . PSY_DISCOUNT_CODE;
$json = file_get_contents('php://input');
$data = json_decode($json);
$type = $data->type;
$coupon_code = $data->coupon_code;
$curDate = date('Y-m-d');
if ($type == 'code') {
$checkCode = $wpdb->get_row("SELECT id,discount_code,discount_value,expiry_date,limit_count,used_count FROM $PSY_DISCOUNT_CODE where discount_code='$coupon_code' and status='1'");
$expiry = $checkCode->expiry_date;
$limit = $checkCode->limit_count;
$used = $checkCode->used_count;
$ref_did = $checkCode->id;
if ($checkCode->discount_code == $coupon_code) {
if ($curDate > $expiry) {
$revertArray[] = array("status" => "0", "message" => 'Sorry,this code is expired...');
}
else if($limit <= $used) {
$revertArray[] = array("status" => "0", "message" => "Sorry,this code offer is end now...");
}
else {
session_start();
$_SESSION['DISCOUNT_ID'] = $checkCode->id;
$revertArray[] = array("status" => "1","discount_id" => $ref_did, "percent" => $checkCode->discount_value, "message" => "Your code is applied...");
}
} else if ($checkCode->discount_code == '' || $checkCode->discount_code == null) {
$revertArray[] = array("status" => "0", "message" => 'Sorry,the code is incorrect or already used...');
} else {
$revertArray[] = array("status" => "0", "message" => 'Use code with capital letters...');
}
echo json_encode($revertArray);
}