<?php 
require_once('../library.php'); 
require_once('../redd/basic-functions.php'); 
$blockchain_root = "https://blockchain.info/";
$root_url = 'https://api.blockchain.info/v2/receive';
$secret_t = '5gCgbLU8SmK31ZzsMLGKe1??62CfA5EcG6j';
$my_xpub = 'xpub6DRUkwWYGnoarDMuZUKQZcUA1P9H32AHM7qwQUqKaGWXjeV74VfxtQDAZwi2bmSLtM2PkKMbEQZFgMFF4ZbbjAFgs9ubwLebhqcSwriNJMD';
$my_api_key = 'bb86b427-4609-4950-8384-34f05b9ea357';

$secret = $_GET['secret'];
$trn_id = $_GET['tranId'];
$transaction_hash = $_GET['transaction_hash'];
$value_in_satoshi = $_GET['value'];
$value_in_btc = $value_in_satoshi / 100000000;
$value_in_usd =  $value_in_btc * $_SESSION['btc_value'] ;
$check_trn_id = $lib->sqlQuery("SELECT * FROM transactions WHERE `transactionid`='".$trn_id."' ");
$results = mysqli_fetch_assoc($check_trn_id);

 if ($_GET['address'] != $results['pay-address']) {
    echo 'Incorrect Receiving Address';
  return;
} 

if ($_GET['secret'] != $secret_t) {
  echo 'Invalid Secret';
  return;
}

if ($_GET['tranId'] != $results['transactionid']) {
  echo 'Invalid transaction id';
  return;
}

if ($_GET['confirmations'] >= 3) {

    $query = "UPDATE $lib->investment SET 
		`amtinbtc`='".mysqli_real_escape_string($this->connectDb(),$value_in_btc)."', 
		`amount`='".mysqli_real_escape_string($this->connectDb(),$value_in_usd)."'
		WHERE `id`='".$tranId."'";
	$msg1  = $admin->confirmPay($_GET['tranId']);
/* 	$email_id = $results['email']; 
		//$cal->selectFrmDB($deposit_tb,'email','transaction_id',$trn_id);
	$name_id = $cal->selectFrmDB($user_tb,'first_name','email',$email_id);
	$coin = $cal->selectFrmDB($deposit_tb,'coin_type','transaction_id',$trn_id);
	$plan = $cal->selectFrmDB($deposit_tb,'plan_type','transaction_id',$trn_id);
	$amount = $cal->selectFrmDB($deposit_tb,'amount','transaction_id',$trn_id);
	
	$fields = array('deposit_status','received_status','transaction_hash');
	$values = array('confirmed','Recieved',$transaction_hash);
	$msg1 = $cal->update($deposit_tb,$fields,$values,'transaction_id',$trn_id);
///referal
	$fieldsR = array('status');
	$valuesR = array('confirmed');
	$msg = $cal->update($referral_tb,$fieldsR,$valuesR,'transaction_id',$trn_id);
$email_call->ConfirmPaymentNotify($amount,$plan,$coin,$trn_id,$name_id,$email_id); */

  if($msg1=="Transaction Confirmed Successfully") {
	   echo "*ok*";
  }
} else {
  //Waiting for confirmations
  //create a pending payment entry
   echo "Waiting for confirmations";
}














?>