connect_error);
$qcon=mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$query1 = "SELECT token FROM inquiries WHERE inquiry_mobile='".$phone."' ORDER BY token DESC LIMIT 0,1";
$result = mysqli_query($conn, $query1);
$row = mysqli_fetch_assoc($result);
$tokencheck = $row['token'];
$success1 = $conn->query($query1);
if (!$success) {
$updatetoken = 0;
}
if( $tokencheck != ""){
$tokencustomerid = $tokencheck;
$updatetoken = 1;
}else{
$updatetoken = 0;
}
$errormessage = '';
$price= 1;
if ($price < 1) {
$errormessage.= "Invalid address.
\n";
$error = true;
}
// Check if email has been entered and is valid
// if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
// $errormessage.= "Please enter a valid email address
\n";
// $error = true;
//}
$apiEndpoint = \Eway\Rapid\Client::MODE_PRODUCTION; // Use \Eway\Rapid\Client::MODE_PRODUCTION when you go live
$client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);
//create customer
$firstname = trim($_POST['First_Name']);
$lastname = trim($_POST['Last_Name']);
$fullname = "$firstname $lastname";
if($updatetoken == 0) {
$customer = [
'Title' => 'Mr.',
'FirstName' => $firstname,
'LastName' => $lastname,
'Country' => 'au',
'Email' => trim($_POST['email']),
'CardDetails' => [
'Name' => $fullname,
'Number' => $_POST['EWAY_CARDNUMBER'],
'ExpiryMonth' => $_POST['EWAY_CARDEXPIRYMONTH'],
'ExpiryYear' => $_POST['EWAY_CARDEXPIRYYEAR'],
'CVN' => $_POST['EWAY_CARDCVN']
]
];
/*echo '
';
print_r($customer);
echo ' ';
exit;*/
$response = $client->createCustomer(\Eway\Rapid\Enum\ApiMethod::DIRECT, $customer);
$tokencustomerid = $response->Customer->TokenCustomerID;
}
if($updatetoken == 1) {
$customer = [
'Email' => trim($_POST['email']),
'TokenCustomerID' => $tokencustomerid,
'CardDetails' => [
'Name' => $fullname,
'Number' => $_POST['EWAY_CARDNUMBER'],
'ExpiryMonth' => $_POST['EWAY_CARDEXPIRYMONTH'],
'ExpiryYear' => $_POST['EWAY_CARDEXPIRYYEAR'],
'CVN' => $_POST['EWAY_CARDCVN']
]
];
/*echo '
';
print_r($customer);
echo ' ';
exit;*/
$response = $client->updateCustomer(\Eway\Rapid\Enum\ApiMethod::DIRECT, $customer);
}
$transaction = [
'Customer' => [
'Reference' => $_POST['hidden_ref'],
'CardDetails' => [
'Name' => $fullname,
'Number' => $_POST['EWAY_CARDNUMBER'],
'ExpiryMonth' => $_POST['EWAY_CARDEXPIRYMONTH'],
'ExpiryYear' => $_POST['EWAY_CARDEXPIRYYEAR'],
'CVN' => $_POST['EWAY_CARDCVN']
]
],
'Payment' => [
'TotalAmount' => $price,
],
'TransactionType' => \Eway\Rapid\Enum\TransactionType::PURCHASE,
'Capture' => false,
];
$response = $client->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction);
if (isset($response->TransactionStatus) && $response->TransactionStatus) {
$transactionid = $response->TransactionID;
$AuthorisationCode = $response->AuthorisationCode;
//$tokencustomerid = $response->Customer->TokenCustomerID;
//$tokencustomerid = $response->Customer->TokenCustomerID;
$query = "SELECT * FROM customer_tokens WHERE access_token_value='".$tokencustomerid."'";
$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 {
$query = "INSERT INTO customer_tokens (`id`, `cid`, `access_token_value`, `status`, `created`, `modified`) VALUES (NULL, '', ".$tokencustomerid.", 1, NOW(), NOW())";
$result = $conn->query($query);
if(!$result) {
error_log("Token insert error: ".$conn->error);
}
}
}
} else {
$error = true;
if ($response->getErrors()) {
foreach ($response->getErrors() as $error) {
$errormessage.= "Error: $error (".\Eway\Rapid::getMessage($error).")
\n";
}
} else {
$errormessage.= "Sorry, your payment was declined";
}
}
$email= $_POST['email'];
$fullnameencode = $_POST['nameencode'];
$pickup= $_POST['pickup'];
$pickupencode = $_POST['pickupencode'];
$dropoff= $_POST['dropoff'];
$dropoffencode= $_POST['dropoffencode'];
date_default_timezone_set("Australia/Perth");
$date=$_POST['date'];
$date24 = date("Y-m-d", strtotime($date));
$time=$_POST['time'];
$time24 = date("G:i", strtotime($time));
$timestamp = strtotime("$date24 $time24") * 1000;
$intphone = $_POST['intphone'];
$lat1= $_POST['lat1_value'];
$lng1= $_POST['lng1_value'];
$lat2= $_POST['lat2_value'];
$lng2= $_POST['lng2_value'];
$price= $_POST['onewayPrice'];
$reference = $_POST['hidden_ref'];
if(!$error)
{
$paymentlink = shortenLink($reference, "DD", "payment");
require("../vromo.php");
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://api.vromo.io/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": "DD ' . $fullname . '", "campaign": {"id": 5622549795}, "contact": {"name": "' . $name . '","phone": "' . $intphone . '","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);
$json = json_decode($response, true);
curl_close($curlObj);
$spatulalink = $json['items'][0]['tracking'];
$spatulaid = $json['items'][0]['id'];
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) 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 1300466365 ";
echo "
Name $fullname
Phone $phone
Email $email
Pick Up $pickup
Drop Off $dropoff
Date/Time $date $time
Quoted $price
";
$smsmessage = $_POST['smsmessage'];
$nameq = mysqli_real_escape_string($qcon, $fullname);
$pickupq = mysqli_real_escape_string($qcon, $pickup);
$dropoffq = mysqli_real_escape_string($qcon, $dropoff);
$query = "INSERT into inquiries (inquiry_name, inquiry_mobile, inquiry_dropoff, inquiry_email, token, inquiry_created, welcomemess) VALUES ('" . $nameq . "','" . $intphone . "','" . $dropoffq . "','" . $email . "','" . $tokencustomerid . "','" . date('Y-m-d H:i:s') . "', '') ON DUPLICATE KEY UPDATE inquiry_name='" . $nameq . "', inquiry_dropoff='" . $dropoffq . "', inquiry_email='" . $email . "', token='" . $tokencustomerid . "'";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
}
$query = "INSERT into jobs (id, reference, job_name, job_phone, job_email, job_pickup, job_dropoff, job_date, job_time, job_quote, token, quote_km, quote_time, date_added, spat_ref, spat_link, xero_inv, conf_sms_sent, payment_eway, driver) VALUES (NULL,'" . $reference . "','" . $nameq . "','" . $intphone . "','" . $email . "','" . $pickupq . "','" . $dropoffq . "','" . $date . "','" . $time . "','" . $price . "', '".$tokencustomerid."', '".$_POST['km_est']."', '".$_POST['time_est']."', '" . date('Y-m-d H:i:s') . "','" . $spatulaid . "','" . $spatulalink . "', '', '', '', '')";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
}
$message= "Type DD
Date $date $time24
Transaction ID $transactionid
Token Customer ID $tokencustomerid
Name $fullname
Phone $phone
Pick Up $pickup
TO
Drop Off $dropoff
Quoted $price
Credit Card Authorised
Lat1 $lat1
Long1 $lng1
Lat2 $lat2
Long2 $lng2
Email $email
Reference $reference
SMS $smsmessage
Namecode $fullnameencode
Pickupcode $pickupencode
Dropoffcode $dropoffencode";
$message_sql = "Type: DD
Ref: $spatulaid
";
$url = "https://www.desidrivers.com.au/newJob.php?type=DD&ref=$reference";
$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_HTTPHEADER, array('Accept: application/json'));
//$response = curl_exec($curlObj);
curl_close($curlObj);
send_mail('lewis@perthdesignateddrivers.com.au','info@perthdesignateddrivers.com.au','New Order From
'.$email ,$message);
// send_mail('sherifmesallam@gmail.com','admin@perthdesignateddrivers.com.au','New Order From '.$email ,$message);
if($_POST['admin'] == 1) {
$result = $conn->query("SELECT id, driver FROM desid573_eway_codes.drivers WHERE city = 'perth'");
echo "Dispatch to:  
";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['driver'];
echo ''.$name.' ';
}
echo '
Status