
    <?php
  

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


	// API parameter
    
	if(isset($_REQUEST['apikey']) && isset($_REQUEST['service']) && isset($_REQUEST['meterNo']) && isset($_REQUEST['metertype']) ){
	
	$apikey = $_REQUEST['apikey'];
	
	$serviceID = $_REQUEST['service'];
	$meterNo = $_REQUEST['meterNo'];
	$metertype = $_REQUEST['metertype'];
	$auth = "paid";
	
	$apikey = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $apikey);
	$serviceID = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $serviceID);
	$meterNo  = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $meterNo);
	$metertype = str_replace( array( '+', '-', '/', '(', ')',   '_',  'drop',  '//', 'delete', 'update', 'insert', '$', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $metertype);
	
	// 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($serviceID === 'ikeja-electric'){
							$disco = "1";
							$pnt = "Ikeja Electricity Payment - IKEDC";
							
							}elseif($serviceID === 'portharcourt-electric'){
                               
								$disco = "4";
								$pnt = "Port Harcourt Electricity Payment - PHED";
								
								}elseif($serviceID === 'ibadan-electric'){
									
									$disco = "6";
									
									$pnt = "Ibadan Electricity Payment - IBEDC";
									
									}elseif($serviceID === 'kano-electric'){
										$disco = "3";
										
										$pnt = "Kano Electricity Payment - KEDCO";
										
										}elseif($serviceID === 'jos-electric'){
											
											$disco = "5";
											
										$pnt = "Jos Electricity Payment - JED";	
										
									}elseif($serviceID === 'eko-electric'){
										$disco = "2";
											
										$pnt = "Eko Electricity Payment - EKEDC";	
											}
											
										elseif($serviceID === 'abuja-electric'){
											$disco = "8";
											
										$pnt = "Abuja Electricity Payment - AEDC";	
											}
											
									elseif($serviceID === 'enugu-electric'){
										$disco = "9";
											
										$pnt = "Enugu Electricity Payment - EEDC";	
											}
											
											
									elseif($serviceID === 'kaduna-electric'){
										$disco = "7";
											
										$pnt = "Kaduna Electricity Payment - KAEDCO";	
											}


$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/disco.php?apikey=$key&service=$serviceID&meterNo=$meterNo&metertype=$metertype";




//{"code":100,"description":{"Customer":"UBI OBETEN ELEDER","customer_number":"Not supplied","Meter_No":"832505156101","staus":"VERIFICATION SUCCESSFUL"}} 




//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,"meterNo"=>$meterNo,"Meter_Type"=>$metertype,"service"=>$serviceID,"message"=> $message)); 

}else{ 
$stat = "Failed";

	response(204,array("service"=>$serviceID,"meterNo"=>$meterNo,"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;
}
    
    ?>
    
  
   	

