<?php
    require'../connection.php';
    
    $status   = "";
    $errorMsg = "";   
    $respoMsg = "";   
    $txnId    = "";   
    $LapuNo   = "";   
    $ApiBal   = "";   
	$roffer   = "";  
	$is_roam  = "";   
	$LapuApi  = "";
	
	$order_id = "35236817674363676437";
	$api      = "M_ROBO";
	
    $apiHTTPurl = "https://mrobotics.in/api/order_id_status?";
    $apiUrl     = "api_token=37a1e7bd-3d24-4d73-8c17-ecd76d5a847e&order_id=$order_id";
	$reqUrl     = $apiHTTPurl.$apiUrl;
	
	$quApiHit   = "INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$order_id','$api','Check Status','$reqUrl')";
	mysqli_query($con,$quApiHit);
	
	$ch = curl_init();
	if (!$ch)
    {
        die("Couldn't initialize a cURL handle");
    }
    curl_setopt($ch, CURLOPT_URL,$apiHTTPurl); // Target URL
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS,$apiUrl);
    $result = curl_exec ($ch);
    
    $quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$order_id','$api','Check Status','$result')";
	mysqli_query($con,$quApiHit);
	
    $result = (array)json_decode($result);
	
    $status   = $result['status'];
    $error    = $result['error'];  
    $errorMsg = $result['errorMessage'];  
    $respoMsg = $result['response'];   
    $txnId    = $result['tnx_id'];
    $LapuNo   = $result['lapu_no'];   
    $ApiBal   = $result['balance'];   
	$roffer   = $result['roffer'];  
	$is_roam  = $result['is_roaming'];   
	$LapuApi  = $LapuNo;
	
	if($status=="SUCCESS" || $status=="success")
	{
	    require'../LinkFile/rechSuccess.php';
	}
	elseif($status=="FAILED" || $status=="failure")
	{
	    require'../LinkFile/rechFailed.php';
	}
	elseif($error == "true")
	{
	    echo $errorMsg;
	} 

?>