<?php
	include_once('../config.php');   
	             
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    } 
     
 
 
 
 
            
                $_POST['Data']  = $_REQUEST['UPI'];
                $_POST['idset']  =  1;
                if($_POST['idset'])
                {
                    
                    $stmt=$conn->prepare("select marchant,nm from UI__Rgst  where  UPI3=:UPI3  ");   
                    $stmt->bindValue(':UPI3',  $_POST['Data'] , PDO::PARAM_STR);  
                    $stmt->execute(); 
                    if($stmt->rowCount() > 0)
                    { 
                        $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                        $Uvnam = $Result->nm;  
                         
                        
                    }else 
                    { 
                        $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE UPI=:UPI");  
                        $stmt->execute(array(':UPI'=>$_POST['Data']));
                        $affected_rows = $stmt->rowCount();	     
                        
                        if($affected_rows > 0)
                        {
                            $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                            $Uvnam =  $Result->nm;  
                            
                        }else
                        {   
                            
                            $set = 0; 
                            if(strpos($_POST['Data'], 'DP') !== false)
                                $set = 1;

                             
                            if($set==1) 
                            {
                                $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE cuurentId=:cuurentId");  
                                $stmt->bindValue(':cuurentId',  $_POST['Data'], PDO::PARAM_STR);  
                                $stmt->execute();     
                                $affected_rows = $stmt->rowCount();	 
                                if($affected_rows > 0)
                                {
                                    $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                                    $Uvnam =  $Result->nm;  
                                } 
                            }else
                            {
                                if(strlen($_POST['Data'])==6)
                                {
                                    $data =  $_POST['Data'];
                                    $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE cuurentId like '%$data%' ");  
                                    //$stmt->bindValue(':cuurentId',  $_POST['Data'], PDO::PARAM_STR);  
                                    $stmt->execute(); 
                                    $affected_rows = $stmt->rowCount();	 
                                    if($affected_rows > 0)
                                    {
                                        $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                                        $Uvnam = $Result->nm;  
                                    }  
                                }
                                
                            } 
                            
                        }
                        
                         
                    }
                }
                else
                {    
                    
                    $stmt=$conn->prepare("select nm  from  UI__Rgst  where  UPI3=:UPI3     ");   
                    $stmt->bindValue(':UPI3',  $_POST['Data'] , PDO::PARAM_STR);  
                    $stmt->execute();  
                    
                    if($stmt->rowCount()>0)
                    {
                             
                        $Result = $stmt->fetch(PDO::FETCH_OBJ);    
                        $Uvnam = $Result->nm;
                         
                        
                    }
                    else 
                    {
                            $stmt = $conn->prepare("SELECT nm FROM UI__Rgst WHERE UPI=:UPI");  
                            $stmt->execute(array(':UPI'=>$_POST['Data']));
                            $affected_rows = $stmt->rowCount();	      
                             
                            
                            if($affected_rows < 1)
                            {
                              
        
                                    $stmt = $conn->prepare("SELECT name FROM UI__UPIVefy WHERE upi=:UPI");  
                                    $stmt->execute(array(':UPI'=>$_POST['Data']));
                                     
                                    if($stmt->rowCount() < 1)
                                    {
                    				$RechargeAccess_token = "c1IJbwdJ7NaChZ6a6UFECH0h0Cq6MiHteJ3G5x3G";
                    				$Rand = mt_rand(24556,234455);  
                    				$EnterOtpAdhar = trim($_POST['Data']);
                    				$data_string = '{"number":"'.$EnterOtpAdhar.'","client_id":"'.$Rand.'","provider_id":"384"}'; 
                    			 
                    				$ch = curl_init();
                    				curl_setopt($ch, CURLOPT_URL, 'https://mobileapi.in/api/v1/verify/upi');
                    				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 ".$RechargeAccess_token;
                    				$headers[] = "Content-Type: application/json";
                    				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
                    				$result = curl_exec($ch);   
                    				$Var = json_decode($result);
                    				
                    				
            				
                                    $stmt=$conn->prepare("insert into test (name)  value(:name) ");      
                                    $stmt->bindValue(':name', $data_string.":".$result , PDO::PARAM_STR);    
                                    $stmt->execute();  
                                    
                    				
                    				if($Var->status_id==1)
                    				{ 
                                            $stmt=$conn->prepare("insert into UI__UPIVefy (upi,name,Tdate,ById)  value(:upi,:name,:Tdate,:ById) ");    
                                            $stmt->bindValue(':upi', $EnterOtpAdhar , PDO::PARAM_STR);   
                                            $stmt->bindValue(':name', $Var->name , PDO::PARAM_STR);   
                                            $stmt->bindValue(':Tdate', date("d-M-Y H:i"), PDO::PARAM_STR);   
                                            $stmt->bindValue(':ById', $_SESSION['userId'], PDO::PARAM_STR);  
                                            $stmt->execute();   
                                            $Uvnam =  $Var->name;
                    				}else
                    				    echo "Error";
                    				    
                                   }else
                                   {
         
                                        $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                        $stmt=$conn->prepare("update UI__UPIVefy set ById=:ById  where  upi=:upi ");    
                                        $stmt->bindValue(':ById', $_SESSION['userId'], PDO::PARAM_STR);  
                                        $stmt->bindValue(':upi', trim($_POST['Data']) , PDO::PARAM_STR);     
                                        $stmt->execute();  
                                        $Uvnam = $Result->name;
                                   }
                               }
                    }
                }
                




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