HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/sarvodayahospital/public/mapp/paymentgatway/ccavResponseHandler.php
<?php include('Crypto.php')?>
<?php
	include '../dbConnection.php';
	error_reporting(0);

	$workingKey='608934FAD8273DAB1C11371AEE32C597';		//Working Key should be provided here.
	$encResponse=$_POST["encResp"];			//This is the response sent by the CCAvenue Server
	$rcvdString=decrypt($encResponse,$workingKey);		//Crypto Decryption used as per the specified working key.
	$order_status="";
	$decryptValues=explode('&', $rcvdString);
	$dataSize=sizeof($decryptValues);
	//echo "<center>";

	for($i = 0; $i < $dataSize; $i++)
	{
		$information=explode('=',$decryptValues[$i]);
		if($i==3)	$order_status=$information[1];
	}


	$result = array();
	for($i = 0; $i < $dataSize; $i++)
	{
			$information=explode('=',$decryptValues[$i]);
			$result[$information[0]] = urldecode($information[1]);
	    //echo '<tr><td>'.$information[0].'</td><td>'.urldecode($information[1]).'</td></tr>';
	}


	// exit();

	if($order_status==="Success")
	{





			$ORDER_ID = $result["order_id"];
			$ORDER_ID = str_replace("V","",$ORDER_ID);
			$bill_number = get_bill_number();
			$sql = "UPDATE video_patient_transaction set
		        response = '".json_encode($result)."'
		        ,status = '3'
		        ,message = '".$result["status_message"]."'
		        ,reference_id = '".$result["tracking_id"]."'
		        ,bill_number = '".$bill_number."'
		        where  id = '".$ORDER_ID."'";
		  $run = mysqli_query($conn,$sql);
			$sql_sms = "SELECT
	            a.booking_from
	            ,a.booking_to
	            ,a.booking_date
							,a.booking_type
	            ,a.id
	            ,b.patient_name
	            ,b.id as patient_id
	            ,b.mrn_no
	            ,b.mrn_nodia
	            ,b.dob
	            ,b.prefix
	            ,b.gender
	            ,b.address
	            ,b.state_name
	            ,b.city_name
	            ,b.pin_code
	            ,b.mobile
	            ,d.name as doc_name
	            ,a.response
	            ,d.doctor_registration_no
	            ,d.mednet_doc_department_name
							,a.loc
	            FROM `video_patient_transaction` a
	            inner join video_patient b on b.id = a.patient_id
	            inner join sh_doctor_dev d on d.id = a.doctor_id
	            left join sh_menu e on e.link = d.specialty
	            where a.id = '$ORDER_ID'
	            ";
	      $query_sms = mysqli_query($conn, $sql_sms);
	      while ($row_sms = mysqli_fetch_array($query_sms)) {
	            send_sms_receipt($row_sms);
	            update_in_mednet($row_sms,$ORDER_ID);
	      }


			/*

			echo $sql_data = "SELECT * FROM `video_booking_patient_transaction` a inner join video_patient b on b.id = a.patient_id where a.id = '$ORDER_ID'";
	 		$query_data = mysqli_query($conn, $sql_data);
			$all_booking_data = array();
			 while ($row_data = mysqli_fetch_array($query_data)) {
						 $json_booking_mednet = json_decode($row_data["json_booking_mednet"],1) ;
						 $all_booking_data = $row_data;
			 }


		  $sql = "UPDATE video_patient_transaction set
	        response = '".json_encode($result)."'
	        ,status = '3'
					,bill_number = '$max'
	        ,message = '".$order_status."'
	        ,reference_id = '".$result["tracking_id"]."'
	        where  id = '".$ORDER_ID."'";
					$query = mysqli_query($conn, $sql);
					$curl = curl_init();
					$data_to_mednet = '{
				    "appointmentID": "'.$json_booking_mednet["active_booking_time"]["appointmentID"].'",
				    "remoteConsultationID":"0",
				    "patientName":"'.$all_booking_data["patient_name"].'",
				    "phoneNo":"'.$all_booking_data["mobile"].'",
				    "reason":" ",
				    "loginID":"",
				    "loginSource":"",
				    "appointmentMode":"web",
				    "slotTime":"'.$json_booking_mednet["active_booking_time"]["appointmentTime"].'",
				    "appointmentDate":"'.$json_booking_mednet["active_booking_date"]["appointmentDate"].'",
				    "mrn":"'.$all_booking_data["mrn_no"].'",
				    "paymentGatewayAmt" : "'.$all_booking_data["amount"].'",
				    "discountAmt" : "0",
				    "paymentGatewayRefNo" : "'.$result["tracking_id"].'",
				    "appointmentType":"NEW CONSULTATION",
				    "status":"BOOKED"
				}';
				curl_setopt_array($curl, array(
				  CURLOPT_URL => 'https://demo.mednetlabs.com/mxServer/ws/onlineDoctorsAppointment/bookSlots',
				  CURLOPT_RETURNTRANSFER => true,
				  CURLOPT_ENCODING => '',
				  CURLOPT_MAXREDIRS => 10,
				  CURLOPT_TIMEOUT => 0,
				  CURLOPT_FOLLOWLOCATION => true,
				  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
				  CURLOPT_CUSTOMREQUEST => 'POST',
				  CURLOPT_POSTFIELDS =>$data_to_mednet,
				  CURLOPT_HTTPHEADER => array(
				    'Content-Type: application/json'
				  ),
				));

				$response = curl_exec($curl);

				curl_close($curl);
				echo $response;
				*/

		header("location:https://sarvodayahospital.com/payment_success/".$ORDER_ID);
	}
	else if($order_status==="Aborted")
	{
		$ORDER_ID = $result["order_id"];
		$ORDER_ID = str_replace("V","",$ORDER_ID);
		$sql = "UPDATE video_patient_transaction set
					response = '".json_encode($result)."'
					,status = '2'
					,message = '".$result["status_message"]."'
					where  id = '".$ORDER_ID."'";
		$query = mysqli_query($conn, $sql);
		header("location:https://sarvodayahospital.com/payment_fail/".$ORDER_ID);
	}
	else if($order_status==="Failure")
	{
		$ORDER_ID = $result["order_id"];
		$ORDER_ID = str_replace("V","",$ORDER_ID);
		$sql = "UPDATE video_patient_transaction set
					response = '".json_encode($result)."'
					,status = '2'
					,message = '".$result["status_message"]."'
					where  id = '".$ORDER_ID."'";
		$query = mysqli_query($conn, $sql);
		header("location:https://sarvodayahospital.com/payment_fail/".$ORDER_ID);
	}
	else
	{
		echo "<br>Security Error. Illegal access detected";

	}


	function get_bill_number(){
				global $conn;
				$sql = "select max(bill_number) as max from video_patient_transaction where status = '3'";
				$query = mysqli_query($conn, $sql);
				$max = 1;
				while ($row_sms = mysqli_fetch_array($query)) {
						if($row_sms["max"]){
							$max = $row_sms["max"] + 1;
						}
				}
				return $max;
	}
	function send_sms_receipt($row){

        $mobile = clear_mobile($row["mobile"]);
        $link = 'https://sarvodayahospital.com/admin/N/R?token='.base64_encode($row["id"]);
        $date = date("d M Y",strtotime($row["booking_date"]))." at ".date("h:i a",strtotime($row["booking_from"]));

        $message = 'Your booking on '.$date.' with '.$row["doc_name"].' has been confirmed. Click on the link below-
'.$link.' Team Sarvodaya Care';
        $message = urlencode($message);
        $url = "http://nimbusit.co.in/api/swsend.asp?username=t1sarvodayahospitalapi&password=housepital&sender=SRVDYA&sendto=$mobile&templateID=1207162167274957626&message=".$message;

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);
        //update_message_info($row,$response);
  }

  function clear_mobile($mobile){
     $mobile = preg_replace('/\s+/', '', $mobile);
     $mobile = str_replace('-', '', $mobile);
     $mobile = ltrim($mobile, '0');
     return $mobile;
  }


	function update_in_mednet($data,$order_id){
        						global $conn;
                    $responce = json_decode($data["response"],1);
                    $patient_name = $data["patient_name"];
                    $mrn_no = $data["mrn_no"];
                    $loc = $data["loc"];
                    $gender = $data["gender"];
                    $state_name = $data["state_name"];
                    $city_name = $data["city_name"];
                    $pin_code = $data["pin_code"];
                    $mobile = $data["mobile"];
                    $dob = $data["dob"];
                    $address = $data["address"];
                    $prefix = $data["prefix"];
                    $doctor_registration_no = $data["doctor_registration_no"];
                    $patient_id = $data["patient_id"];
                    $mednet_department_name = $data["mednet_doc_department_name"];

										$service_name = "Online Consultation";
										if($data["booking_type"] == "1"){
												$service_name = "Online Video Consultation";
										}

                    $m = "";
                    if($mrn_no){
                          $m =  $mrn_no;
                    }
										$companyName = "SARVODAYA HOSPITAL AND RESEARCH CENTRE";
										if($loc == "sarvodaya-hospital-greater-noida-west"){
													$mrn_nodia = $data["mrn_nodia"];
													$link = "http://shgrenow.sarvodayahospital.com:4040/mednet/ws/patientBillingWS/createPatientBill";
													$m = "";
													if($mrn_nodia){
			                          $m =  $mrn_nodia;
			                    }
													$companyName = "SARVODAYA HOSPITAL - NOIDA";
													$service_name = "Doctors Consultation";

										}

                    if($gender = "M"){
                        $gender = "Male";
                    }else if ($gender = "F"){
                        $gender = "Female";
                    }
                    $responce["AMOUNT"] = round($responce["amount"]);
                    $d_a = '{
                    "companyName": "'.$companyName.'",
                    "mrn": "'.$m.'",
                    "departmentName": "'.$mednet_department_name.'",
                    "doctorRegistrationNumber": "'.$doctor_registration_no.'",
                    "paymentMode": "Debit_Card",
                    "paymentTxnNo": "'.$responce["tracking_id"].'",
										"paymentBankName": "HDFC BANK",
										"paymentModeSrcRefType": "HDFC",
                    "orderTokenNumber": "'.$responce["order_id"].'",
                    "totalAmount": '.$responce["AMOUNT"].',
                    "billAmount": '.$responce["AMOUNT"].',
                    "prefix": "'.$prefix.'",
                    "name": "'.$patient_name.'",
                    "gender": "'.$gender.'",
                    "dateOfBirth": "'.date("d-m-Y",strtotime($dob)).'",
                    "mobileNumber": "'.$mobile.'",
                    "aadharID": "",
                    "country": "India",
                    "state": "'.$state_name.'",
                    "city": "'.$city_name.'",
                    "pincode": "'.$pin_code.'",
                    "street1": "'.$address.'",

                    "serviceList": [{
                      "serviceName": "'.$service_name.'",
                      "rate": '.$responce["AMOUNT"].',
                      "renderByRegistrationNumber": "'.$doctor_registration_no.'",
                      "amount": '.$responce["AMOUNT"].'
                    }
                    ]
                    }';
										$link = "http://mednet.sarvodayahospital.com:4040/mednet/ws/patientBillingWS/createPatientBill";
										if($loc == "sarvodaya-hospital-greater-noida-west"){

													$link = "http://shgrenow.sarvodayahospital.com:4040/mednet/ws/patientBillingWS/createPatientBill";

										}


                    $sql_j = "update video_patient_transaction set mednet_json = '$d_a' where id = '$order_id'";
                    $query = mysqli_query($conn,$sql_j);


                    $curl = curl_init();
                    curl_setopt_array($curl, array(
                    CURLOPT_URL => $link,
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_ENCODING => '',
                    CURLOPT_MAXREDIRS => 10,
                    CURLOPT_TIMEOUT => 0,
                    CURLOPT_FOLLOWLOCATION => true,
                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST => 'POST',
                    CURLOPT_POSTFIELDS =>$d_a,
                    CURLOPT_HTTPHEADER => array(
                    'Content-Type: application/json'
                    ),
                    ));

                    $response = curl_exec($curl);

                    curl_close($curl);


                    $response = json_decode($response,1);

                    $bill_number = $response["billNumber"];
                    $mrn = $response["mrn"];


                    $bill_number = str_replace("OPD.","",$bill_number);
                    $d_a = json_encode(json_decode($d_a,1));
                    $sql = "update video_patient_transaction set mednet_bill_number = '$bill_number',mednet_link = '$link',mednet_response_json = '".json_encode($response)."' where id = '$order_id'";
                    $query = mysqli_query($conn,$sql);


										if($loc == "sarvodaya-hospital-greater-noida-west" && !$m){
											$mrn = str_replace("MRN-","",$mrn);
											$sql_a = "update video_patient set  mrn_nodia = '$mrn' where id = '$patient_id'";
											$query_a = mysqli_query($conn,$sql_a);

										}else if(!$m){
                        $mrn = str_replace("MRN-","",$mrn);
                        $sql_a = "update video_patient set  mrn_no = '$mrn' where id = '$patient_id'";
                        $query_a = mysqli_query($conn,$sql_a);
                    }
  }

	/*

	echo "<br><br>";

	echo "<table cellspacing=4 cellpadding=4>";



	print_r($result);



	echo "</table><br>";
	echo "</center>";
	*/
?>