<?php
    $apiLoop   = "STOP";
    $status    = "";   
    $ApiBal    = "";   
    $respoMsg  = "";   
    $txnId     = "";   
    $OrderID   = "";   
	$partnerId = "";  
	$LapuApi   = "";
	
    $apiUsrId  = "3334";
    $apiToken  = "e696918427bc39de4a0761dbddd35ad9";
    $apiUrl    = "https://api.rechargebuysale.com/ExchangeTransactionAPI?UserID=$apiUsrId&Token=$apiToken&Account=$mnum&Amount=$amount&SPKey=$ApiOpCode&APIRequestID=$newrechid&Format=1";
	
	$ApiHitReq = "INSERT INTO api_hit (Date,Time,TxnId,ApiName,Type,Disc) VALUES ('$date','$time','$newrechid','$api','REQUEST','$apiUrl')";
	mysqli_query($con,$ApiHitReq);
	
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $apiUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    $result   = json_decode($response);
	
    $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->bal;
    $respoMsg  = $result->msg;   
    $txnId     = $result->opid;
    $partnerId = $result->rpid;
	   
    $OrderID   = $newrechid;
	$Printmsg  = $respoMsg;
	$LapuApi   = $api;
	$updateLapu="UPDATE recharge SET Api='$api', Lapu='$LapuApi', ApiTxnId='$partnerId' WHERE Id='$newrechid'";
	mysqli_query($con,$updateLapu);
    
	    if($status=="SUCCESS" || $status=="2")
        {
            require'../LinkFile/rechSuccess.php';
        }
        else if($status=="FAILED" || $status=="3")
        {
            if($countSetApi>$x)
	    	{
		        $apiLoop="CONTINUE";
		    }
		    else
		    {
		        
		        require'../LinkFile/rechFailed.php';
		    }   
        }
        else if($status=="PENDING" || $status=="1")
        {
            require'../LinkFile/rechPending.php';
        }
    
?>