<?php
  

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


	// API parameter
    
	if(isset($_REQUEST['apikey']) && isset($_REQUEST['network']) ){
	
	$apikey = $_REQUEST['apikey'];
	$network = $_REQUEST['network'];

	$auth = "paid";
	
	
	$apikey = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $apikey);
	$network = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $network);


	// 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){




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

$key = $apidata['APIkey']; 



$host ="https://vtuafrica.com.ng/portal/api/airtime-cash/verify.php?apikey=$key&network=$network";



//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);
   

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

$status = $result->description->status;

$sitephone = $result->description->Phone_Number;

$net = $result->description->Network;


if($result->code =='101' || $status == "Available"){



	response(100,array("status"=>$status,"message"=>$message,"Phone_Number"=>$sitephone,"Network"=>$net));

}else{ 

$stat = "Failed";
$sitephone = "";

	response(204,array("status"=>$status,"message"=>$message,"Phone_Number"=>$sitephone,"Network"=>$net)); 
	
	}

	

	
  } 
  
 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;
}
    
    ?>
    
  
   	

