<?php
	include_once('../config.php');   
    include_once(ABS_PATH.'/custom_function/default.php');  
          
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
    
			    
    
    
    if(isset($_POST['Submit'])) 
    {   
                
				$URL  = 'https://daemon.takshitsolutions.com/api/app/v1/get-token?projectName=VIJAYx9A4ZkP2w7VfM1r8JdQ3L6tB0HxG7H8&userName='.$_SESSION['userId'];  
                $crl = curl_init();
                curl_setopt($crl, CURLOPT_URL, $URL);
                curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
                curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);  
                $response = curl_exec($crl); 
                $Data = json_decode($response); 
                
				
                $data_string = '{ 
                "TxtId":"'.$_POST['UTR'].'",
                "decimals":"6"
                }';
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,'https://daemon.takshitsolutions.com/api/app/v1/get-transaction-receipt');
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
                curl_setopt($ch, CURLOPT_POST, 1);
                $headers = array();
                $headers[] = "Accept: application/json";
                $headers[] = "Authorization: Bearer ".$Data->data;
                $headers[] = "Content-Type: application/json";
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                $result = curl_exec($ch);  
                $Deco = json_decode($result);   
                if( ($Deco->status=="SUCCESS") && (($Deco->IsRisk==0)) && (($Deco->toaddress=='TQHD8d25cyrzdVPBynrPDhip5YVv28J17C')) )
                {     
                    $stmt=$conn->prepare("select Addr   from      UI__USDTDeposite  where  Addr=:Addr  ");   
                    $stmt->bindValue(':Addr', $_POST['UTR'] , PDO::PARAM_STR); 
                    $stmt->execute();   
                    if($stmt->rowCount()<1)
                    { 
                        
                        $stmt=$conn->prepare("select *     from    UI__USDTINR    ");   
                        //$stmt->bindValue(':randNo', $_REQUEST['randNo'] , PDO::PARAM_STR); 
                        $stmt->execute(); 
                        $dateOfra = $stmt->fetch(PDO::FETCH_OBJ); 
			
			
                        $stmt=$conn->prepare("insert into   UI__USDTDeposite (custId,Tdate,Addr,fromAddr,amt,INRVAl) values(:custId,:Tdate,:UTR,:fromAddr,:amt,:INRVAl)"); 
                        $stmt->bindValue(':custId', $_SESSION['userId'] , PDO::PARAM_STR); 
                        $stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
                        $stmt->bindValue(':fromAddr', $Deco->fromaddress , PDO::PARAM_STR); 
                        $stmt->bindValue(':UTR',$_POST['UTR'], PDO::PARAM_STR);    
                        $stmt->bindValue(':amt',$Deco->amount, PDO::PARAM_STR);    
                        $stmt->bindValue(':INRVAl',$dateOfra->inrVal, PDO::PARAM_STR);    
                        $stmt->execute();   
                        $LAtINt = $conn->lastInsertId();
                        AddFundNew($_SESSION['userId'],round($Deco->amount*$dateOfra->inrVal),"USDT Deposite");  
                        $_SESSION['Regis'] = "Request Sent Successfully"; 
                        header("Location: USDT2.php?id=".$LAtINt); 
                        die;
                    }else
                    {
                        $_SESSION['Regis'] = "Transaction Hash Already Used "; 
                        header("Location: USDT.php?id=".$LAtINt); 
                        die;
                    }  
                } 
                $_SESSION['Regis'] = "Error in Deposite"; 
                header("Location: USDT.php"); 
                die;   
         }       
    
           

include_once("../view/dashboard/USDT1.php");
?>