<?php
    
    $apiLoop   = "STOP";
    $status    = "";   
    $ApiBal    = "";   
    $respoMsg  = "";   
    $txnId     = "";   
    $errCode   = "";   
    $OrderID   = "";   
	$partnerId = "";  
	$LapuApi   = "";
	
    $apiToken = "5304f696e952416f8989e2186bb4dd3b";
    if($OpCode==5 || $OpCode==4)
    {
        $field1 = $mnum;
    }
    else
    {
        $field1 = "";
    }
    
    $apiUrl="https://www.ytcpay.co.in/apiservice.asmx/Recharge?apiToken=$apiToken&mn=$mnum&amt=$amount&op=$ApiOpCode&reqid=$newrechid&field1=$field1&field2=''"; 
	
	$quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','REQUEST','$apiUrl')";
	mysqli_query($con,$quApiHit);
	
	
	$curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => $apiUrl,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
    ));

    $response = curl_exec($curl);
    $result   = simplexml_load_string($response);
    curl_close($curl);
    
    $quApiHit="INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','RESULT','$response')";
	mysqli_query($con,$quApiHit);
	
    $status    = $result->status;                                            
	$ApiBal    = $result->balance;
    $respoMsg  = $result->remark;   
    $txnId     = $result->field1;   
    $errCode   = $result->ec;
    $partnerId = $result->apirefid;
    
    $OrderID   = $newrechid;
	$Printmsg  = $respoMsg;
	$LapuApi   = $api;
	
	
	$updateLapu="UPDATE recharge SET Api='$api', Lapu='$LapuApi' where Id='$newrechid'";
	mysqli_query($con,$updateLapu);
    
	    if($status=="SUCCESS")
        {
            require'../LinkFile/rechSuccess.php';
        }
        else if($status=="FAILED" || $status=="REFUND" )
        {
            if($countSetApi>$x)
	    	{
		        $apiLoop="CONTINUE";
		    }
		    else
		    {
		        if(chk_msg($respoMsg,'Insufbalan')==10)
	            {
	                $respoMsg   ="Failed !";
	                $OpDeactive = "UPDATE comm_slab SET Status='DEACTIVE' WHERE Userid='$userid' AND OpCode='$OpCode'";
	                mysqli_query($con,$OpDeactive);
	            }
	
		        require'../LinkFile/rechFailed.php';
		    }   
        }
        else if($status=="PENDING")
        {
            require'../LinkFile/rechPending.php';
        }
    
?>