<?php


	//includes functions and classes for remita constants
	require 'includes/tab_menu/remita_constants.php';
	include_once'includes/functions.php';

	$orderId = "";
	$response_code ="";
	$rrr = "";
	$response_message = "";
	$logs ='';

	$result = mysqli_query(dbc(),"SELECT tref FROM test_rrr2");
	while($row = mysql_fetch_array($result))
	{
			

		$orderId = $row['tref'];

		
			$response = remita_transaction_details($orderId);
			$response_code = $response['status'];
			// if (isset($response['RRR']))
			// {
				$rrr = $response['RRR'];
			// }else{
			// 	$rrr  ='';
			// }
			// $response_message = $response['message'];
			


			// if($response_code == '01' || $response_code == '00')
			// {

				$logs .= $orderId.'-'.$rrr.'-'.$response_code.'<br>';
				$query = "UPDATE test_rrr2 SET rrr = '$rrr', response_code = '$response_code'
						WHERE tref = '$orderId' ";
				mysqli_query(dbc(),$query);
					

		//	}
		



	}
		
	echo "$logs";



//Verify Transaction
function remita_transaction_details($orderId){
		$mert =  MERCHANTID;
		$api_key =  APIKEY;
		$concatString = $orderId . $api_key . $mert;
		$hash = hash('sha512', $concatString);
		$url 	= CHECKSTATUSURL . '/' . $mert  . '/' . $orderId . '/' . $hash . '/' . 'orderstatus.reg';
		//  Initiate curl
		$ch = curl_init();
		// Disable SSL verification
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		// Will return the response, if false it print the response
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		// Set the url
		curl_setopt($ch, CURLOPT_URL,$url);
		// Execute
		$result=curl_exec($ch);
		// Closing
		curl_close($ch);
		$response = json_decode($result, true);
		return $response;
	}

	






				 
    
                   
                 