<?php
	include_once('../config.php');    
                          
                        
                        $ary = json_decode('["payid=83339","status=success","operator_ref=967034692824","client_id=7yec4kWPNfstGHo","number=dikshaathwale@ibl","provider_id=328","wallet_type=1"]');;
                        
                        
                        //$ary = explode("&",$_SERVER['argv'][0]); 
                        $ex1 = explode("=",$ary[3]);
                        $client_id = end($ex1);  
                        
                        $ex1 = null;
                        $ex1 = explode("=",$ary[2]); 
                        $optRef = end($ex1);   
                        $UTR = end($ex1);  
                        
                        
                        $ex1 = null;
                        $ex1 = explode("=",$ary[5]);  
                        $ProviderId = end($ex1);  
                        
                         
                         
                       
                        $Job2_ncode2 = json_encode($ary);  
                        //$Job2_ncode2 =  json_encode(json_decode(file_get_contents( 'php://input' ), true ));        
                        $stmt=$conn->prepare("insert into UI__CallBackPay2Second(calBack,Tdate) values(:calBack,:Tdate)"); 
                        $stmt->bindValue(':calBack', $Job2_ncode2, PDO::PARAM_INT);    
                        $stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);     
                        $stmt->execute();   
                        
                        
                        $Job2_ncode2 = json_encode($ary);  
                        //$Job2_ncode2 =  json_encode(json_decode(file_get_contents( 'php://input' ), true ));        
                        $stmt=$conn->prepare("insert into UI__CallBackPay2Second(calBack,Tdate) values(:calBack,:Tdate)"); 
                        $stmt->bindValue(':calBack', $Job2_ncode2."::".$client_id."::".$UTR."::".$ProviderId , PDO::PARAM_INT);    
                        $stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);     
                        $stmt->execute(); 
                        
                        if($ProviderId=="329") 
                        {
                             
                            $stmt =  $conn->prepare("select * from  UI__TxnFailUsersPay2  where  client_id=:client_id  ");   
                            $stmt->bindValue(':client_id', $client_id  , PDO::PARAM_STR); 
                            $stmt->execute();  
                            
                            
                            if($stmt->rowCount()>0)   
                            {
                                $UI__TxnFailUsersPay2 = $stmt->fetch(PDO::FETCH_OBJ);       
                                if($UI__TxnFailUsersPay2->status==0)
                                {
                                    $ex1=null;    
                                    $ex1 = explode("=",$ary[1]); 
                                    $status = end($ex1);   
                                    if($status=="success")
                                    {      
                                            $stmt=$conn->prepare("update UI__TxnFailUsersPay2 set UTR=:UTR,paidDateTime=:paidDateTime,status=1  where id=:id  ");  
                                            $stmt->bindValue(':UTR', $optRef , PDO::PARAM_STR);
                                            $stmt->bindValue(':paidDateTime', date("d-M-Y H:i") , PDO::PARAM_STR);
                                            $stmt->bindValue(':id', $UI__TxnFailUsersPay2->id , PDO::PARAM_STR);  
                                            $stmt->execute(); 
                                    }else if($status=="failure")
                                    {
                                            $stmt=$conn->prepare("update UI__TxnFailUsersPay2 set paidDateTime=:paidDateTime,status=2  where id=:id  "); 
                                            $stmt->bindValue(':paidDateTime', date("d-M-Y H:i") , PDO::PARAM_STR);
                                            $stmt->bindValue(':id', $UI__TxnFailUsersPay2->id , PDO::PARAM_STR);  
                                            $stmt->execute(); 
                                    }
                                }
        
                            }
                        }else
                        { 
                         
                            $stmt =  $conn->prepare("select * from  UI__UpiTxn  where  clientId=:client_id  ");   
                            $stmt->bindValue(':client_id', $client_id  , PDO::PARAM_STR); 
                            $stmt->execute();  
                            
                            
                            
                            if($stmt->rowCount()>0)   
                            {
                                
                                $UI__UpiTxn = $stmt->fetch(PDO::FETCH_OBJ);       
                                if($UI__UpiTxn->status==0)
                                {
                                  
                                    $ex1=null;    
                                    $ex1 = explode("=",$ary[1]); 
                                    $status = end($ex1);   
                                    
                                 
                                    if($status=="success")
                                    {     
                                            
                                            $stmt=$conn->prepare("update UI__UpiTxn set utr=:utr,status=1  where id=:id  ");  
                                            $stmt->bindValue(':utr', $optRef , PDO::PARAM_STR);  
                                            $stmt->bindValue(':id', $UI__UpiTxn->id , PDO::PARAM_STR);  
                                            $stmt->execute(); 
                                    }else if($status=="failure")
                                    {        
                                            $Tdate = date("d-M-Y"); 
                                            $stmt=$conn->prepare("delete from UI__Tlimits     where amt=:amt  and custId=:custId  and type=1 and Tdate like '%$Tdate%' ");  
                                            $stmt->bindValue(':amt', $UI__UpiTxn->amt , PDO::PARAM_STR); 
                                            $stmt->bindValue(':custId', $UI__UpiTxn->custId  , PDO::PARAM_STR);    
                                            $stmt->execute();  
                                            AddFundNew($UI__UpiTxn->custId,$UI__UpiTxn->amt,"UPI Refund");
                                            $stmt=$conn->prepare("update UI__UpiTxn set utr=:utr,status=2  where id=:id  ");  
                                            $stmt->bindValue(':UTR', $optRef , PDO::PARAM_STR); 
                                            $stmt->bindValue(':id', $UI__UpiTxn->id , PDO::PARAM_STR);  
                                            $stmt->execute();      
                                    }
                                }
        
                            }
                        }