<?php
  

 header('Content-Type : application/json');
  
    require_once('../../db.php');


	// API parameter
    
	if(isset($_REQUEST['apikey']) && isset($_REQUEST['service']) && isset($_REQUEST['smartNo']) && isset($_REQUEST['variation']) ){
	
	$apikey = $_REQUEST['apikey'];
	
	$serviceID = $_REQUEST['service'];
	$smartNo = $_REQUEST['smartNo'];
	$network = $_REQUEST['service'];
	$vcode = $_REQUEST['variation'];
	$auth = "paid";
	
	
	$apikey = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $apikey);
	$serviceID = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $serviceID);
	$smartNo  = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $smartNo);
	$network = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $network);
    $vcode = str_replace( array( '+', '-', '/', '(', ')',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $vcode);

	// check if the account is valid

	
	$retr = mysqli_query($conn,"SELECT * FROM users WHERE apikey='$apikey' ");

	$rob = mysqli_fetch_array($retr);
	
	$user = $rob['apikey'];
	$aut = $rob['level'];
	
	$arr = array("$apikey","$auth");
	
	$pair = array("$user","$aut");		
	
	if($arr === $pair){






  if($network === 'dstv'){
	$gladNet = "2";
	
	}elseif($network === 'gotv'){
		
		$gladNet = "1";
		}elseif($network === 'startimes'){
		
		$gladNet = "3";	
			
			}elseif($network === 'airtel'){
				
				$gladNet = "2";
				}


$qryApi = mysqli_query($conn,"SELECT * FROM api_setting");
$apidata = mysqli_fetch_array($qryApi);

$key = $apidata['APIkey']; 



$host ="https://vtuafrica.com.ng/portal/api/merchant-verify/tv.php?apikey=$key&service=$serviceID&smartNo=$smartNo&variation=$vcode";



//Initialize cURL.
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $host);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

 
$data = curl_exec($ch);

$result = json_decode($data);



//Close the cURL handle.
curl_close($ch);

$name = $result->description->Customer;	   

$mgs = $result->description->message;




if($result->code =='100' || $result->code =='101'){


 $message = "VERIFICATION SUCCESSFUL";


	response(100,array("Customer"=>$name,"IUC"=>$smartNo,"message"=>$message)); 

}else{ 
$stat = "Failed";

	response(204,array("IUC"=>$smartNo,"message"=>$mgs)); }

	

	
  } 
  
 else{  
    
    response(103,"INVALID ACCOUNT"); 


    }


} // close wrong parameter



	  else{ 
	   
	   response(400,"INVALID PARAMETER"); 
	       
	       
	   }
	    

function response($status,$status_message)
{
	
	
	$response['code']=$status;
	$response['description']=$status_message;
	
	
	$json_response = json_encode($response);
	echo $json_response;
}
    
    ?>
    
  
   	

