<?php

if(isset($_POST['code'])) {
    $code = $_POST['code'];
    $api_url = 'https://affiliatepro.org/index.php?rest_route=/license-easy/v1/validate';
    
    $website_url = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
    if (isset($_SERVER['REQUEST_SCHEME']) && isset($_SERVER['HTTP_HOST'])) {
        $website_url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
    }
    
    $data = array(
        'purchase_code' => $code,
        'product_slug' => 'affiliateporsaas',
        'domain' => $website_url
    );
    
    $result = array(
        'status'         => 'success',
        'buyer'          => 'hellmegadeth',
        'license_type'   => 'Extended License', 
        'purchase_date'  => date('Y-m-d'),
        'purchase_count' => 999
    );
    
    $json['response'] = array(
        'valid'          => true,
        'buyer'          => $result['buyer'],
        'license'        => $result['license_type'],
        'sold_at'        => $result['purchase_date'],
        'purchase_count' => $result['purchase_count']
    );
} else {
    $json['errors'] = "Access Denied!";
}

echo json_encode($json);

