<?php
include '../../conn.php';
include 'message.php';


$userId=$_GET['userId'];
$doctorID=$_GET['doctorID'];
$requestId=$_GET['requestId'];
$cost=$_GET['cost'];
$serviceType=$_GET['serviceType'];
$accept=$_GET['accept'];
$extracost=$_GET['extracost'];

$gstcost=$cost*18/100;

$cost=$cost+$extracost+$gstcost;



$insert = $con->query("UPDATE `request` SET `status`='2',`bookingType`='$serviceType',`bookingCharge`='$cost',`doctorId`='$doctorID',`paymentType`='$accept', `time`=NOW() WHERE id='$requestId'");


    
if($insert > 0)
{ 
  $resultdata =$con->query("select fcmtoken from `users` where id=$userId");
while($row = mysqli_fetch_array($resultdata)){
    $fcmtoken=$row['fcmtoken'];
    

    
$data = array("to" => $fcmtoken,
                  "notification" => array( "title" => "$titlefcm", "body" => $acptmsg ,"icon" => $logofcm),
                    "data"=>array("code"=> $acptcodefcm, "key1"=> $requestId,"key2"=> $acptmsg )
                  );                                                                    
            $data_string = json_encode($data); 
            
             "The Json Data : ".$data_string; 
            
            $headers = array
            (
                 'Authorization: key=' . API_ACCESS_KEY, 
                 'Content-Type: application/json'
            );                                                                                 
                                                                                                                                 
            $ch = curl_init();  
            
            curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );                                                                  
            curl_setopt( $ch,CURLOPT_POST, true );  
            curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
            curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
            curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);                                                                  
                                                                                                                                 
            $result = curl_exec($ch);
            
}
  echo '101';
}

else{
    echo '404';
}

?>