<?php 

include '../../conn.php';
 
$requestid=$_GET['requestid'];
$TXNID=$_GET['TXNID'];
$TXNAMOUNT=$_GET['TXNAMOUNT'];
$PAYMENTMODE=$_GET['PAYMENTMODE'];
$BANKTXNID=$_GET['BANKTXNID'];
$BANKNAME=$_GET['BANKNAME'];

$resultdata =$con->query("select * from `request` where id='$requestid'");
$doctorid=null;
while($row = mysqli_fetch_array($resultdata)){
    $doctorid=$row['doctorId'];
    $amount=$row['bookingCharge'];
    $userId=$row['userId'];
    $remark=$row['description'];
}

$resultdoctor=$con->query("select * from `doctors` where id='$doctorid'");
$wallet=null;
while($rowdoctor = mysqli_fetch_array($resultdoctor)){
    $wallet=$rowdoctor['wallet'];
     
}
$newamount=$wallet+$amount;

$doctorsupdate= $con->query("UPDATE `doctors` SET `wallet`='$newamount' WHERE  id='$doctorid'");
$requestupdate = $con->query("UPDATE `request` SET `status`='3' WHERE  id='$requestid'");

$transaction= $con->query("INSERT INTO `transaction`(`doctorId`,`lastamount`,`paitentId`,`remark`,`requestId`,`createTime`, `TXNID`, `PAYMENTMODE`, `BANKTXNID`, `BANKNAME`) VALUES ('$doctorid','$amount','$userId','$remark','$requestid',NOW(),'$TXNID','$PAYMENTMODE','$BANKTXNID','$BANKNAME')");

if($transaction > 0){
    $j->status='101';
    $j->message='Payment Successfully done';
    echo json_encode($j);
}


?>
