<?php
include('../includes/session.php');
include('../includes/config.php');

error_reporting(E_ERROR | E_PARSE);

//var_dump($_POST);
//$echo = "";
if (isset($_GET['client_txn_id'])) {
	$key = "587a85ce847f26a9e7b9652017c09c39";	// Your Api Token https://merchant.upigateway.com/user/api_credentials
	//$post_data = new stdClass();
	//$post_data->key = $key;
	$client_txn_id = $_GET['client_txn_id']; // you will get client_txn_id in 
	$uddr = explode('_',$client_txn_id);
	$order_id = $uddr[0].'_'.$uddr[1];
	$phone = $uddr[2];
	$post_data = array("user_token"=>$key,"order_id"=>$order_id);

	$curl = curl_init();
	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://herobro.in/api/check-order-status',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'POST',
		CURLOPT_POSTFIELDS => json_encode($post_data),
		CURLOPT_HTTPHEADER => array(
			'Content-Type: application/json'
		),
	));
	$response = curl_exec($curl);
	curl_close($curl);
   
	$result = json_decode($response, true);
	 //echo $result['status'];
	 //echo json_encode($result,true);
	if ($result['status'] == 'COMPLETED') {
		// Txn Status = 'created', 'scanning', 'success','failure'
$msg="Your ID Active successfull Login id $phone DONE ".$_POST['password']." Click this link to login ->".$_SERVER['SERVER_NAME']."/login.php";
    SendWa($phone,$msg);
            
		if ($result['result']['status'] == 'SUCCESS') {
		   $sqlr = mysqli_query($ahk_conn,"UPDATE `users` SET `status`='1' WHERE `phone`='".$phone."'");

		}
		
		$txn_data = $result['result'];
		?>
		if($sqlr){?>
         <form method="post" action="../../register.php" name="f1">
                    			<input type="hidden" name="success" value="true">
                    			
                    		<script type="text/javascript">
                    			document.f1.submit();
                    		</script>
        <?php 
    }else{
        ?>
   <form method="post" action="../../register.php" name="f3">
            			<input type="hidden" name="failed" value="true">
            			
         <script type="text/javascript">
          document.f3.submit();
    </script>
        <?php
    }
		
	}else{
	    echo 'hu';
	}

    echo 'hj';

?>