/home/desid573/public_html/hooks
Edit: /home/desid573/public_html/hooks/test.php (28477B)
connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$result = mysqli_query($conn, "SELECT * FROM jobs WHERE spat_ref='".$id."' ORDER BY job_name DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$custname = $row['job_name'];
$custphone = $row['job_phone'];
$ratingsdriver = $row['driver'];
$booking_token = $row['token'];
$company = "FamilyCab";
$pickup = $row["job_pickup"];
$spat_link = $row["spat_link"];
$names = explode(" ",$custname);
$custfirstname = $names[0];
if ($custname != ""){
error_log("found FC");
if($driver != "") {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE id='".$driver."'");
} else {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE driver='".$ratingsdriver."'");
}
$row = mysqli_fetch_assoc($result);
$drivername = $row['driver'];
$drivername = mysqli_real_escape_string($qcon, $drivername);
$driverphone = $row['driver_phone'];
$result = mysqli_query($conn, "SELECT welcomemess FROM customers WHERE customer_mobile='" . $custphone . "' ORDER BY welcomemess DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$welcome = $row['welcomemess'];
if($welcome != "yes"){
$result = mysqli_query($conn, "SELECT message FROM messages WHERE id=0 ORDER BY message DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$message = $row['message'];
$query4 = "UPDATE customers SET welcomemess='yes' WHERE customer_mobile='" . $custphone . "'";
} else {
$messageid = rand(1,4);
$result = mysqli_query($conn, "SELECT message FROM messages WHERE id=$messageid ORDER BY message DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$message = $row['message'];
}
} else { // Designated Driver Database
$dbhost = "localhost";
$dbuser = "perthdes_inquiri";
$dbpass = "@G&{)0*&Ts^V";
$dbname = "perthdes_inquiries";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$result = mysqli_query($conn, "SELECT * FROM jobs WHERE spat_ref='".$id."'");
$row = mysqli_fetch_assoc($result);
$custname = $row['job_name'];
$custphone = $row['job_phone'];
$booking_token = $row['token'];
$ratingsdriver = $row['driver'];
$company = "DesiDrivers";
$pickup = $row["job_pickup"];
$spat_link = $row["spat_link"];
$names = explode(" ",$custname);
$custfirstname = $names[0];
if($custname != ""){
error_log("found DD");
if($driver != "") {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE id='".$driver."'");
} else {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE driver='".$ratingsdriver."'");
}
$row = mysqli_fetch_assoc($result);
$drivername = $row['driver'];
$drivername = mysqli_real_escape_string($conn, $drivername);
error_log($drivername);
$driverphone = $row['driver_phone'];
$result = mysqli_query($conn, "SELECT welcomemess FROM inquiries WHERE inquiry_mobile='" . $custphone . "' ORDER BY welcomemess DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$welcome = $row['welcomemess'];
if($welcome != "yes"){
$result = mysqli_query($conn, "SELECT message FROM messages WHERE id=0 ORDER BY message DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$message = $row['message'];
$query4 = mysqli_query($conn, "UPDATE inquiries SET welcomemess='yes' WHERE inquiry_mobile='".$custphone."'");
} else {
$messageid = rand(1,4);
$result = mysqli_query($conn, "SELECT message FROM messages WHERE id=$messageid ORDER BY message DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$message = $row['message'];
}
} else { //HomeKey Database
$dbhost = "localhost";
$dbuser = "perthdes_inquiri";
$dbpass = "@G&{)0*&Ts^V";
$dbname = "perthdes_new_pro_api";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$result = mysqli_query($conn, "SELECT id, cid, driver, spatula_link FROM booking WHERE spatula_id='".$id."' ORDER BY cid DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$cid = $row['cid'];
$bid = $row['id'];
$spatula_link = $row['spatula_link'];
$ratingsdriver = $row['driver'];
error_log("cid found");
if($cid != "") {
$company = "HomeKey";
$authkey = "AAAAmOGb3vM:APA91bE-XimrlXCGEycGTB2YOV1kWQ-fFCyjKvgtz74yX1WqGUP84sQxzlR7ESqzcEHcHquR2EYWBJZuIazbe0wkpsAEQSRxIWoFPP20U5OfyILQ7zaGYIoXm3SSdCRVj4U332cxIn_I";
$result = mysqli_query($conn, "SELECT name, mobile, firebase_token FROM customers WHERE id='".$cid."' ORDER BY name DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$custname = $row['name'];
$custphone = $row['mobile'];
$firebase_token = $row['firebase_token'];
$names = explode(" ",$custname);
$custfirstname = $names[0];
if($driver != "") {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE id='".$driver."'");
} else {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE driver='".$ratingsdriver."'");
}
$row = mysqli_fetch_assoc($result);
$drivername = $row['driver'];
$drivername = mysqli_real_escape_string($conn, $drivername);
$driverphone = $row['driver_phone'];
} else { //FamCab App Database
$dbhost = "localhost";
$dbuser = "perthdes_fam_app";
$dbpass = "TW#7CCqKReDn";
$dbname = "perthdes_famcab_api";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$result = mysqli_query($conn, "SELECT id, cid, driver, spatula_link FROM booking WHERE spatula_id='".$id."' ORDER BY cid DESC LIMIT 0,1");
if(!$result) {
error_log("FA booking error: ".$conn->error);
}
$row = mysqli_fetch_assoc($result);
$cid = $row['cid'];
$bid = $row['id'];
$spatula_link = $row['spatula_link'];
$ratingsdriver = $row['driver'];
if($row['cid'] != "") {
$company = "FamCab";
$authkey = "AAAAqi4vwgY:APA91bF2FTZV_AmYn6tI3rUZtQEejPY7F3E6LZcKuw20s1R3xWZr7AcnHQTOiGBFKMyaOAUJBeGlqxvpc8HYnWClwpw-AWwwKZOa0bsNJp9kW5JYVrF8g_LlnRJU0zNpt_Pc-DUv0uYH";
error_log("FA Booking found");
$result = mysqli_query($conn, "SELECT name, mobile, firebase_token FROM customers WHERE id='".$cid."' ORDER BY name DESC LIMIT 0,1");
if(!$result) {
error_log("FA customer error: ".$conn->error);
}
$row = mysqli_fetch_assoc($result);
$custname = $row['name'];
$custphone = $row['mobile'];
$firebase_token = $row['firebase_token'];
$names = explode(" ",$custname);
$custfirstname = $names[0];
if($driver != "") {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE id='".$driver."'");
} else {
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE driver='".$ratingsdriver."'");
}
$row = mysqli_fetch_assoc($result);
$drivername = $row['driver'];
$drivername = mysqli_real_escape_string($conn, $drivername);
$driverphone = $row['driver_phone'];
} else { //MINI database
$dbhost = "localhost";
$dbuser = "perthdes_mini_dd";
$dbpass = "H=iKT1#?T2,5";
$dbname = "perthdes_minidd";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$result = mysqli_query($conn, "SELECT cid, driver FROM booking WHERE spatula_id='".$id."' ORDER BY cid DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$cid = $row['cid'];
$ratingsdriver = $row['driver'];
error_log("cid found");
if($cid != "") {
$company = "MINI";
$authkey = "AAAA0XXSFW0:APA91bFX7flat3wGZGcAdlyDb0RkuL6rOYUtBRmSu3EXXtuymu16OEqaEsqI2BiFPUE6YvTzUbaQWNeTpB6kqoQVxgnM45_quj8ttd4Rvt1-Lwda68xoh4sFtJpOzlKZY_EbzRDxeh2OUZUBVVtVe64seJhlACU-yQ";
$result = mysqli_query($conn, "SELECT name, mobile, firebase_token FROM customers WHERE id='".$cid."' ORDER BY name DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$custname = $row['name'];
$custphone = $row['mobile'];
$firebase_token = $row['firebase_token'];
$names = explode(" ",$custname);
$custfirstname = $names[0];
$result = mysqli_query($conn, "SELECT driver, driver_phone FROM perthdes_eway_codes.drivers WHERE id='".$driver."' ORDER BY driver DESC LIMIT 0,1");
$row = mysqli_fetch_assoc($result);
$drivername = $row['driver'];
$drivername = mysqli_real_escape_string($conn, $drivername);
$driverphone = $row['driver_phone'];
}
} //end mini
} //end FCA
} //end HK
} //end DD
//end FC
if($company == "MINI") {
$slackURL = "https://hooks.slack.com/services/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";
} else {
$slackURL = 'https://hooks.slack.com/services/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';
}
if ($event == "dispatched"){
$slackmessage = "$drivername has been assigned $custname";
if($company == "HomeKey" || $company == "FamCab" || $company == "MINI"){
error_log("operator worked");
$result = mysqli_query($conn, "UPDATE booking SET driver='".$drivername."', status='dispatched' WHERE spatula_id='".$id."'");
$title = "Driver has been assigned";
$body = "Driver is ".$drivername;
$gcm = sendGCM($authkey, $title, $body, $firebase_token, $bid);
if(!$gcm) {
$message = $title."\n".$body;
sendSMS($custphone, $company, $message);
}
} else {
$result = mysqli_query($conn, "UPDATE jobs SET driver='".$drivername."' WHERE spat_ref='".$id."'");
if(!$result) {
error_log("dispatch error: ".$conn->error);
}
}
}
if ($event == "returned"){
$slackmessage = "$drivername has been removed from $custname";
if($company == "HomeKey" || $company == "FamCab" || $company == "MINI"){
$result = mysqli_query($conn, "UPDATE booking SET driver='', status='underway' WHERE spatula_id='".$id."'");
} else {
$result = mysqli_query($conn, "UPDATE jobs SET driver='' WHERE spat_ref='".$id."'");
}
}
if ($event == "underway"){
$extra_message = "";
if($company == "HomeKey" || $company == "FamCab" || $company == "MINI"){
$result = mysqli_query($conn, "UPDATE booking SET driver='".$drivername."', status='underway' WHERE spatula_id='".$id."'");
//-- Look up driver coordinates
$result = mysqli_query($conn, "SELECT pickup_lat, pickup_long FROM booking WHERE spatula_id='".$id."' ");
$get = mysqli_fetch_assoc($result);
$lat2 = $get['pickup_lat'];
$lng2 = $get['pickup_long'];
$destination = "$lat2,$lng2";
$time = getETA($driver, $destination, false);
$title = "Your Driver is enroute";
$body = "ETA is ".$time;
$gcm = sendGCM($authkey, $title, $body, $firebase_token, $bid);
if(!$gcm) {
$message = $title."\n".$body;
sendSMS($custphone, $company, $message);
}
$response = curl_exec($curlObj);
curl_close($curlObj);
$short = "";
$query = "SELECT * FROM customer_tokens WHERE cid='".$cid."'";
$result = $conn->query($query);
if(!$result) {
error_log("Token error: ".$conn->error);
} else {
$row = $result->fetch_assoc();
$modified = $row['modified'];
$modified = strtotime($modified);
$twoWeeks = strtotime("-3 weeks");
if($modified < $twoWeeks) {
$return = token_check($row['access_token_value'], $conn);
$extra_message = $return[0];
$short = $return[1];
} else {
$extra_message = "credit card on file used in last 3 weeks";
$short = "CCA";
}
}
} else {
$time = getETA($driver, $pickup, true);
$message = "Hi ".$custfirstname.",\nYour Driver is en route. ETA is ".$time."\nYou can track their arrival using this link ".$spat_link;
sendSMS($custphone, $company, $message);
if($booking_token != "" && $booking_token != "account") {
$query = "SELECT * FROM customer_tokens WHERE access_token_value='".$booking_token."'";
$result = $conn->query($query);
if(!$result) {
error_log("Token error: ".$conn->error);
} else {
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$modified = $row['modified'];
if($modified != null) {
$modified = strtotime($modified);
$twoWeeks = strtotime("-3 weeks");
if($modified < $twoWeeks) {
$return = token_check($booking_token, $conn);
$short = $return[1];
$extra_message = $return[0];
} else {
$short = "CCA";
$extra_message = "credit card on file used in last 3 weeks";
}
} else {
$return = token_check($booking_token, $conn);
$short = $return[1];
$extra_message = $return[0];
}
} else {
$query = "INSERT INTO customer_tokens (`id`, `cid`, `access_token_value`, `status`, `created`, `modified`) VALUES (NULL, '', ".$booking_token.", 1, NOW(), NULL)";
$result = $conn->query($query);
if(!$result) {
error_log("Token insert error: ".$conn->error);
} else {
$return = token_check($booking_token, $conn);
$short = $return[1];
$extra_message = $return[0];
}
}
}
}
}
if($drivername != "Lewis") {
$drivermessage = $short." You are on your way to $custname, ".$extra_message;
sendSMS($driverphone, "DesiDrivers", $drivermessage);
}
$slackmessage = $short." $drivername is enroute to $custname ".$extra_message;
sendToSlack($slackURL, $slackmessage);
}
if ($event == "closed"){
if($company == "HomeKey" || $company == "FamCab" || $company == "MINI"){
$result = mysqli_query($conn, "UPDATE booking SET driver='".$drivername."', status='completed' WHERE spatula_id='".$id."'");
$title = "Fare is completed";
$body = "You can rate and leave feedback in the Closed Bookings tab";
$gcm = sendGCM($authkey, $title, $body, $firebase_token, $bid);
if(!$gcm) {
$message = sprintf($message, $custfirstname);
$sms = sendSMS($custphone, $company, $body);
}
} else {
if($message != ""){
$message = sprintf($message, $custfirstname);
sendSMS($custphone, $company, $message);
if($welcome != "yes"){
$result = mysqli_query($conn, $query4);
}
$query1 = "UPDATE jobs SET driver='".$drivername."' WHERE spat_ref='".$id."'";
$result = mysqli_query($conn, $query1);
}
}
$slackmessage = "$drivername has finished $custname";
sendToSlack($slackURL, $slackmessage);
//send_mail('lewis@perthdesignateddrivers.com.au','info@perthdesignateddrivers.com.au','Webhook', $emailmessage);
}
if($event == "pickup") {
if($company == "HomeKey" || $company == "FamCab" || $company == "MINI"){
$title = "Driver has arrived";
$body = "You can contact them from the Open Bookings Tab";
$gcm = sendGCM($authkey, $title, $body, $firebase_token, $bid);
if(!$gcm) {
$message = $title."\n".$body;
sendSMS($custphone, $company, $message);
}
} else {
$message = "Hi ".$custfirstname.", your driver ".$drivername." has arrived. You can contact them on ".$driverphone.". Thanks ".$company;
sendSMS($custphone, $company, $message);
}
if($ratings != "") {
if($comment == "") {
$comment = "No Comment";
}
$slackmessage = "New Rating for ".$custname."\nDriven By ".$ratingsdriver."\n".$stars." Stars\nComment: ".$comment;
$ratingsURL = 'https://hooks.slack.com/services/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';
sendToSlack($ratingsURL, $slackmessage);
}
}
}
function getETA($driver, $destination, $lats) {
require("../vromo.php");
$url = "https://api.fleeteng.com.au/v2/graph/role/vehicles.json?access_token=".$vromo;
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($curlObj);
curl_close($curlObj);
$json = json_decode($response, true);
$array = array_filter($json['items'], function($v) use ($driver) {
return $v['id'] == $driver; });
$array = reset($array);
$lat1 = $array['points']['items'][0]['location']['lat'];
$lng1 = $array['points']['items'][0]['location']['lon'];
$origin = "$lat1,$lng1";
//-- check driving time from driver to customer
if($lats) {
$pickplace = getplaceid($destination);
if($pickplace) {
$pickCoords = getCoords($pickplace);
}
$destination = $pickCoords["lat"].",".$pickCoords["lon"];
}
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=$origin&destinations=$destination&mode=driving&sensor=false&key=AIzaSyCq_JZBDbrE5qma5SgF06M2dVAqbiZBZ-o";
error_log($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response, true);
error_log($response);
$dist = $response_a['rows'][0]['elements'][0]['distance']['text'];
$time = $response_a['rows'][0]['elements'][0]['duration']['text'];
return $time;
}
function send_mail($to, $from, $title, $message)
{
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "From: $from \n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;charset=ISO-8859-1 \r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: smail-PHP " . phpversion() . "\r\n";
return mail($to, $title, $message, $headers);
}
function sendToSlack($url, $message) {
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, '{"text": "'.$message.'"}');
$response = curl_exec($curlObj);
curl_close($curlObj);
}
function sendSMS($to, $from, $body) {
$account_sid = 'AC1b4db66d86197058950ad349a2327a85';
$auth_token = '053ae80d10eac3b60c92179d3492badf';
$client = new Client($account_sid, $auth_token);
$messages = $client->messages->create($to, array('From' => $from, 'body' => $body));
error_log($messages->sid);
if($messages->sid) {
return true;
} else {
$messages = $client->messages->create($to, array('From' => "+61409895094", 'body' => $body));
if($messages->sid) {
return true;
} else {
send_mail("lewis@perthdesignateddrivers.com.au", "error_log@perthdesignateddrivers.com.au", "New Error sending SMS", "Error sending ".$body." to ".$to);
return false;
}
}
}
function sendGCM($authkey, $title, $body, $firebase_token, $bid) {
$headers = array
(
'Authorization: key='.$authkey,
'Content-Type: application/json'
);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, '{ "notification": {
"title": "'.$title.'",
"body": "'.$body.'",
"icon": "myicon",
"sound": "mySound"
},
"to" : "'.$firebase_token.'"
"data": {
"status": "underway"
"bid": "'.$bid.'",
"spatula_link": "'.$spatula_link.'",
"quote": "0"
}
}');
$response = curl_exec($curlObj);
error_log($response);
curl_close($curlObj);
$result = json_decode($response, true);
if($result["success"] == 1) {
return true;
} else {
return false;
}
}
function token_check($token, $conn)
{
require_once 'eway-rapid-php-master/include_eway.php';
$client_key = '4T7y1vuKPkdhRYUQdH6msueW9hqV2wpcwnSk0Qwxkvwf7TjQn40qymPW7IJb66gUC1w1505cDMkj9IR82juQEnIp4/8nd0nDhwYDSDoqROtNBWmkqtqYmF6F4qVGMUq3HpJrY3y2kdSljCFfWzWc7LIEn4G5XY2IZAPgAO5+mhwvYrricmqwLhqzV4FBUII5AwTvJZl4awrdul4vLWkS73vJuW/XrXHseGK/nqB3oSRluZ1jKp2qDgVTwrXYEbx4rwwS42X2w0C9tLKywxf27WD2CCK8ftSeQBimVqFI0r6VuRXFVaOn6SQTOD9V/TsCfPk5Zh6/PWcfapyVKS+l1w==';
$apiKey = '44DD7APNUxR8/4sDLhEVT11OS00fmBo4Haxj4ZGJGHvtLBP0rC/ayqNhbVu9tEJrjlJPJm';
$apiPassword = 'y2b7QMpd';
$apiEndpoint = \Eway\Rapid\Client::MODE_PRODUCTION;
$client = \Eway\ Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);
$transaction = [
'Customer' => [
'TokenCustomerID' => $token,
],
'Payment' => [
'TotalAmount' => '1',
],
'TransactionType' => \Eway\Rapid\Enum\TransactionType::RECURRING,
'Capture' => false,
];
$response = $client->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction);
if (isset($response->TransactionStatus) && $response->TransactionStatus) {
$extra_message = "Credit card on file authorised today";
$query = "SELECT * FROM customer_tokens WHERE access_token_value='".$token."'";
$result = $conn->query($query);
if(!$result) {
error_log("Token error: ".$conn->error);
} else {
if ($result->num_rows > 0)
{
$row = $result->fetch_assoc();
$tokencheck = $row['access_token_value'];
$query = "UPDATE customer_tokens SET modified = NOW() WHERE access_token_value = ".$tokencheck;
$result = $conn->query($query);
if(!$result) {
error_log("Token update error: ".$conn->error);
}
} else {
error_log("No token check required");
}
}
return array($extra_message, "CCA");
} else {
$query = "SELECT * FROM perthdes_eway_codes.responses WHERE code = '".$response->ResponseMessage."'";
$result = $conn->query($query);
if ($result->num_rows > 0)
{
$row = $result->fetch_assoc();
$responseMessage = $row['message'];
$errormessage = $responseMessage;
}
return array("Credit card on file failed ".$errormessage, "CCD");
}
}
function getplaceid($place) {
$url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?key=AIzaSyCzDCB1H9ZvIgT4NHGqCXajVQlRXKwTVY4&inputtype=textquery&input=".urlencode($place);
//error_log($url);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
$response = curl_exec($curlObj);
//error_log($response);
$json = json_decode($response, true);
curl_close($curlObj);
if($json["status"] == "OK") {
return $json["candidates"][0]["place_id"];
} else {
return false;
}
}
function getCoords($placeid) {
$url = "https://maps.googleapis.com/maps/api/place/details/json?key=AIzaSyCzDCB1H9ZvIgT4NHGqCXajVQlRXKwTVY4&placeid=".$placeid;
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
$response = curl_exec($curlObj);
//error_log($response);
$json = json_decode($response, true);
curl_close($curlObj);
if($json["status"] == "OK") {
return array("address" => $json["result"]["formatted_address"], "lat" => $json["result"]["geometry"]["location"]["lat"], "lon" => $json["result"]["geometry"]["location"]["lng"]);
} else {
return false;
}
}