num_rows > 0) {
$row = mysqli_fetch_assoc($result);
$cid = $row['id'];
if($cid != "") {
$query = "SELECT * FROM customer_tokens WHERE cid = ".$cid;
$result = mysqli_query($conn, $query);
if($result->num_rows > 0) {
$row = mysqli_fetch_assoc($result);
$tokenID = $row['access_token_value'];
}
}
}
//create customer
if($tokenID == "") {
// Set values in your customer object.
$result = \Stripe\Customer::create([
'source' => $_POST['stripeToken'],
'email' => $email,
'name' => $nameq,
'phone' => $phone
]);
$cust_id = $result["id"];
// Create a Customers API client
error_log($result);
$sql = "INSERT INTO `customers`(`id`, `name`, `mobile`, `email`, `password`, `firebase_token`, `promo_code`, `promo_used`, `is_delete`, `created`, `modified`) VALUES (NULL,'".$nameq."','".$phone."','".$email."','','','','','',NOW(),NOW())";
$result = mysqli_query($conn, $sql);
if(!$result) {
error_log("customer add error: ".$conn->error);
}
$cid = $conn->insert_id;
$sql = "INSERT INTO `customer_tokens`(`id`, `cid`, `access_token_value`, `status`, `created`, `modified`) VALUES (NULL,".$cid.",'".$cust_id."','',NOW(),NOW()) ON DUPLICATE KEY UPDATE `access_token_value` = '".$cust_id."'";
$result = mysqli_query($conn, $sql);
if(!$result) {
error_log("customer token add error: ".$conn->error);
}
$tokenID = $cust_id;
} else {
//update customer
$result = \Stripe\Customer::update($tokenID, [
'source' => $_POST["stripeToken"],
]);
error_log($result);
}
}
$pickup= $_POST['pickup'];
$dropoff= $_POST['dropoff'];
$date = $_POST['date'];
$d = date_create_from_format("jS M, Y", $date);
$date24 = date_format($d, "Y-m-d");
error_log($date24);
$time= $_POST['time'];
$time24 = date("H:i:s", strtotime($time));
$timeUTC = date("c", strtotime("$date24 $time24"));
$timestamp = strtotime("$date24 $time24") * 1000;
$type = $_POST["type"];
$lat1= $_POST['lat1_value'];
$lng1= $_POST['lng1_value'];
$lat2= $_POST['lat2_value'];
$lng2= $_POST['lng2_value'];
$onewayprice= $_POST['onewayPrice'];
if(!$error)
{
$paymentlink = shortenLink($reference, $type, "angelPAY");
$km_est = $_POST['km_est'];
$time_est = $_POST['time_est'];
$detailsq = mysqli_real_escape_string($conn, $_POST["information"]);
$promo_code = mysqli_real_escape_string($conn, $_POST["promo_code"]);
$pickupq = mysqli_real_escape_string($conn, $pickup);
$dropoffq = mysqli_real_escape_string($conn, $dropoff);
if($_POST['account']==1) {
$tokenID = $_POST['token'];
$cid = $_POST["cid"];
$fullname = $_POST['name'];
}
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://api.fleeteng.com.au/v2/graph/role/jobs?access_token='.$vromo);
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, '[{"name": "AD ' . $fullname . '", "campaign": {"id": 208285240573953}, "contact": {"name": "' . $fullname . '","phone": "' . $phone . '","email": "' . $email . '"},"tasks": [{"timeframe":{"by": '.$timestamp.'}, "zone": {"name": "' . $pickup . '","address": "' . $pickup . '","coords": {"lat": ' . $lat1 . ',"lon": ' . $lng1 . '},"radius": 100}},{"zone": {"name": "' . $dropoff . '","address": "' . $dropoff . '","coords": {"lat": ' . $lat2 . ',"lon": ' . $lng2 . '},"radius": 100}}],"attr": [{ "key": "Payment Link", "value": "' . $paymentlink . '" }]}]');
// ,
$response = curl_exec($curlObj);
error_log($response);
$json = json_decode($response, true);
curl_close($curlObj);
$spatulalink = $json['items'][0]['tracking'];
$spatulaid = $json['items'][0]['id'];
$query = "INSERT INTO `booking`(`id`, `cid`, `email`, `booking_date`, `booking_time`, `pickup_addr`, `pickup_lat`, `pickup_long`, `pickoff_addr`, `pickoff_lat`, `pickoff_long`, `instructions`, `promo_code`, `spatula_id`, `spatula_link`, `reference`, `type`, `quote`, `quote_km`, `quote_time`, `token`, `xero_inv`, `payment_stripe`, `status`, `driver`) VALUES (NULL,".$cid.",'".$email."','".$date24."','".$time24."','".$pickupq."','".$lat1."','".$lng1."','".$dropoffq."','".$lat2."','".$lng2."', '".$detailsq."', '".$promo_code."','".$spatulaid."','".$spatulalink."','".$reference."','".$type."','".$onewayprice."','".$km_est."','".$time_est."', '".$tokenID."','','','','')";
error_log($query);
$success = $conn->query($query);
if (!$success) {
error_log("Could not enter booking data: ".$conn->error);
} else {
$sql = "INSERT INTO `customer_details`(`id`, `cid`, `address`, `addr_lat`, `addr_long`) VALUES (null,".$cid.",'".$dropoffq."','".$lat2."','".$lng2."') ON DUPLICATE KEY UPDATE `address` = '".$dropoffq."', `addr_lat` = '".$lat2."', `addr_long` = '".$lng2."'";
$success = $conn->query($sql);
if(!$success) {
error_log("Could not customer address data: ".$conn->error);
}
}
$slackLink = shortenLink($reference, "AD", "angelSMS");
$slackmessage = "<$slackLink | Confirm Booking> for $fullname \n$date $time\n$pickup\n$dropoff";
$url = "https://hooks.slack.com/services/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";
$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": "'.$slackmessage.'"}');
$response = curl_exec($curlObj);
curl_close($curlObj);
if($response == "ok") {
error_log("Slack Sent");
} else {
error_log("Slack not sent");
}
require("../google/google-api-php-client-2.2.1/angelAdd.php");
$link = shortenLink($reference, "AD", "angelOPT");
addToCalendar("AD", $reference, $link);
echo "
Your booking has been successfully processed
";
echo "
You will receive an SMS confirmation from the dispatch team within 30 mins (unless you have submitted after hours)
";
$message= "Type GC
Date $date $time24
Square Customer ID $custID
Card ID $cardID
Name $fullname
Phone $phone
Pick Up $pickup
Flight Number $fnum1
Mins post flight $ptime1
TO
Drop Off $dropoff
Quoted $onewayprice
Credit Card Authorised
Number of Passengers $passNum
Number of RF Seats $rfNum
Number of FF Seats $ffNum
Number of Boosters $boostNum
Luggage $luggage
Lat1 $lat1
Long1 $lng1
Lat2 $lat2
Long2 $lng2
Reference $reference
Email $email
";
send_mail('lwscann@gmail.com','booking@angeldrivers.com.au','New Order From'.$email ,$message);
echo "
When your driver is en route you will receive an SMS with a tracking link and driver contact details. If you do not receive this SMS atleast 10 mins before your booking time please contact us on 0411301301
";
echo "
Trip Details
";
echo "
| Name | $fullname |
| Phone | $phone |
| Email | $email |
| Pick Up | $pickup |
| Drop Off | $dropoff |
| Date/Time | $date $time |
| Quoted | $onewayprice |
";
$body = "
Hi ".$name.", Thank you for submitting your booking request. Your submitted details are below. You will receive an SMS Notification when your booking is confirmed.
| Name | ".$fullname." |
| Phone | ".$phone." |
| Email | ".$email." |
| Pick Up | ".$pickup." |
| Drop Off | ".$dropoff." |
| Date/Time | ".$date." ".$time." |
| Quoted | $".$onewayprice." |
When your driver is en route you will receive an SMS with a tracking link and driver contact details. If you do not receive this SMS atleast 10 mins before your booking time please contact us on 0411301301
";
send_mail($email,'booking@angeldrivers.com.au', 'Your Booking Submission to Angel Drivers for '.$date.' '.$time,$body);
?>