<?php
    require_once("../../autoloader.php");
    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');
    header("Access-Control-Allow-Methods: POST");
    header("Allow: POST, OPTIONS, PUT, DELETE");
    header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Origin");

    $headers = apache_request_headers();
    $response = array();
    $controller = new SubscriberModel;
   
    date_default_timezone_set('Africa/Lagos');
          

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $pin = $_POST['pin'];
    $id = $_POST['userId'];


 $result = $controller->verifyUserPin($id, $pin);
 if($result["status"]=="fail"){
        header('HTTP/1.0 200 Invalid Network Id');
        $response = array('status' => 'Incorrect Pin, Kindly Try Again', 'message' => 'Incorrect Pin');
        file_put_contents("airtime_fail_log.txt",json_encode($response))
        ;
        $jsonString = json_encode($response, JSON_UNESCAPED_SLASHES);
echo $jsonString;
        exit();
    }
    else{
       $response = array('status' => 'ok');
     
file_put_contents("airtime_fail_log.txt",json_encode($result, JSON_UNESCAPED_SLASHES));
$jsonString = json_encode($response, JSON_UNESCAPED_SLASHES);
echo $jsonString;
exit();
    
    }

    
} else {
    
    $response = array('status' => 'fail', 'message' => 'Invalid request method');
    file_put_contents("airtime_fail_log.txt",json_encode($response))
        ;
  $jsonString = json_encode($response, JSON_UNESCAPED_SLASHES);
echo $jsonString;
}


?>