/home/desid573/public_html/fc_api
Edit: /home/desid573/public_html/fc_api/index.php (13722B)
";
//print_r($data);
//echo "
";
$sql = "SELECT id FROM customers where email = '".$_REQUEST['email']."'";
$result = $conn->query($sql);
$headers = 'From: '.$_REQUEST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$promo_code = "";
if(isset($_REQUEST['no_fam'])) {
$no_pax = $_REQUEST['no_fam'];
}
if(isset($_REQUEST['no_pax'])) {
$no_pax = $_REQUEST['no_pax'];
}
if ($result->num_rows > 0)
{
$row = $result->fetch_assoc();
$cid = $row["id"];
$password = $row["password"];
error_log($password);
if($password == "") {
$sql = "SELECT id FROM google_id where cid = '".$cid."'";
$result = $conn->query($sql);
if($result->num_rows > 0) {
$Res["message"] = "User already exists with that Email address and is linked to a Google Account";
$Res["customer_status"] = "already exist";
$Res["status"] = "already exist";
} else {
$sql = "SELECT id FROM facebook_id where cid = '".$cid."'";
$result = $conn->query($sql);
if($result->num_rows > 0) {
$Res["message"] = "User already exists with that Email address and is linked to a Facebook Account";
$Res["customer_status"] = "already exist";
$Res["status"] = "already exist";
} else {
$Res["message"] = "User already exists with that Email address";
$Res["customer_status"] = "already exist";
$Res["status"] = "already exist";
}
}
} else {
$Res["message"] = "User already exists with that Email address";
$Res["customer_status"] = "already exist";
$Res["status"] = "already exist";
}
}
else
{
if($_REQUEST['user_agree']=="1")
{
if(isset($_REQUEST['promo_code']) && $_REQUEST['promo_code'] != "") {
if(substr($_REQUEST['promo_code'], 0, 2) === "RF"){
$sql = "SELECT * FROM referrals where code = '".$_REQUEST['promo_code']."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$promo_code = $_REQUEST['promo_code'];
$promo_details = $result->fetch_assoc();
$continue = 1;
$referal = true;
} else {
error_log($conn->error);
$continue = 0;
$promo_code = "";
}
} else {
$sql = "SELECT code FROM promo_codes where code = '".trim($_REQUEST['promo_code'])."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$promo_code = $_REQUEST['promo_code'];
$continue = 1;
} else {
error_log($conn->error);
$continue = 0;
$promo_code = "";
}
}
} else {
$continue = 1;
}
if($continue == 1) {
$pass = MD5($_REQUEST["pass"]);
//$fullname = $_REQUEST["name"];
//$name_split = explode(" ",$fullname);
$fname = trim($_REQUEST["fname"]);
$lname = trim($_REQUEST["lname"]);
$fullname = $conn->real_escape_string($fname." ".$lname);
$exp = $_REQUEST["exp"];
error_log($exp);
$exp_split = explode("/",$exp);
$expmonth = $exp_split[0];
$expyear = $exp_split[1];
$cvv = $_REQUEST["CVV"];
//========================token Id ===================================
$client_key = '4T7y1vuKPkdhRYUQdH6msueW9hqV2wpcwnSk0Qwxkvwf7TjQn40qymPW7IJb66gUC1w1505cDMkj9IR82juQEnIp4/8nd0nDhwYDSDoqROtNBWmkqtqYmF6F4qVGMUq3HpJrY3y2kdSljCFfWzWc7LIEn4G5XY2IZAPgAO5+mhwvYrricmqwLhqzV4FBUII5AwTvJZl4awrdul4vLWkS73vJuW/XrXHseGK/nqB3oSRluZ1jKp2qDgVTwrXYEbx4rwwS42X2w0C9tLKywxf27WD2CCK8ftSeQBimVqFI0r6VuRXFVaOn6SQTOD9V/TsCfPk5Zh6/PWcfapyVKS+l1w==';
$apiKey ='44DD7APNUxR8/4sDLhEVT11OS00fmBo4Haxj4ZGJGHvtLBP0rC/ayqNhbVu9tEJrjlJPJm';
$apiPassword = 'y2b7QMpd';
//$apiKey = '60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR';
//$apiPassword = 'API-P4ss';
$apiEndpoint = \Eway\Rapid\Client::MODE_PRODUCTION;
//$apiEndpoint = \Eway\Rapid\Client::MODE_SANDBOX; // Use \Eway\Rapid\Client::MODE_PRODUCTION when you go live
$client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);
$cardnum = $_REQUEST["credit_card"];
$messge = $cardnum;
$customer = [
'FirstName' => $fname,
'LastName' => $lname,
'Country' => 'au',
'Email' => $_REQUEST["email"],
'CardDetails' => [
'Name' => $fullname,
'Number' => $cardnum,
'ExpiryMonth' =>$expmonth,
'ExpiryYear' => $expyear,
//'CVN' => $_REQUEST["CVV"],
]
];
$response = $client->createCustomer(\Eway\Rapid\Enum\ApiMethod::DIRECT, $customer);
if ($response->getErrors())
{
$errormessage = "";
foreach ($response->getErrors() as $error)
{
$errormessage.= "Error: $error (".\Eway\Rapid::getMessage($error).")
\n";
}
//= $errormessage;
$tokencustomerid = "";
$message .= "..........".$errormessage;
mail("lwscann@gmail.com", "bookings@perthdesignateddrivers.com.au", $message, $headers);
}
else
{
//echo "";
//print_r($customer);
//print_r($response);
//echo "
";
$tokencustomerid = $response->Customer->TokenCustomerID;
}
//===========================token id end here ========================
if($tokencustomerid != "")
{
if($fname!="" && $lname!="")
{
$phone = str_replace(" ", "", $_REQUEST["phone"]);
$sql = "INSERT INTO `customers` (`id`, `name`, `mobile`, `email`,`password`, `firebase_token`, `promo_code`, `promo_used`, `is_delete`, `created`, `modified`) VALUES (NULL, '".$fullname."', '".$phone."', '".$_REQUEST["email"]."', '".$pass."', '', '".$promo_code."', '1', '0',NOW() , NOW() )";
if ($conn->query($sql) === TRUE)
{
$cid = $conn->insert_id;
if($conn->insert_id)
{
if(isset($_REQUEST["googleID"]) && $_REQUEST["googleID"] != "") {
$sql = "SELECT * FROM `google_id` WHERE `google_id` = '".$_REQUEST["googleID"]."'";
$insert = $conn->query($sql);
if($insert->num_row > 0) {
$sql = "DELETE FROM `customers` WHERE `id` = ".$cid;
$insert = $conn->query($sql);
$Res["status"] = "error";
$Res["message"] = "Google ID already attached to an account";
die(json_encode(new ArrayObject($Res)));
} else {
$sql = "INSERT INTO `google_id` (`id`, `cid`, `google_id`, `date_created`) VALUES (NULL, '".$cid."', '".$_REQUEST["googleID"]."', NOW())";
$insert = $conn->query($sql);
if(!$insert) {error_log("google add error ".$conn->error);}
}
} else if(isset($_REQUEST["facebookID"]) && $_REQUEST["facebookID"] != "") {
$sql = "SELECT * FROM `facebook_id` WHERE `facebook_id` = '".$_REQUEST["facebookID"]."'";
$insert = $conn->query($sql);
if($insert->num_row > 0) {
$sql = "DELETE FROM `customers` WHERE `id` = ".$cid;
$insert = $conn->query($sql);
$Res["status"] = "error";
$Res["message"] = "Google ID already attached to an account";
die(json_encode(new ArrayObject($Res)));
} else {
$sql = "INSERT INTO `facebook_id` (`id`, `cid`, `facebook_id`, `date_created`) VALUES (NULL, '".$cid."', '".$_REQUEST["facebookID"]."', NOW())";
$insert = $conn->query($sql);
if(!$insert) {error_log("facebook add error ".$conn->error);}
}
}
//$expmonth = $_REQUEST["expmonth"];
//$expyear = $_REQUEST["expyear"];
if($referal) {
$sql = "INSERT INTO `referral_use` (`id`, `referer_id`, `refered_id`, `code`, `value`, `reference`, `date_used`) VALUES (NULL, '".$promo_details['customer_id']."', '".$cid."', '".$promo_code."', '".$promo_details['value']."', '', NULL)";
$insert = $conn->query($sql);
if(!$insert) {error_log($conn->error);}
$sql = "SELECT * FROM `referal_claim` WHERE `code` = '".$promo_code."'";
$result = $conn->query($sql);
if($result->num_rows > 0) {
$claims = $result->fetch_assoc();
$current_claims = $claims['referrals_generated'];
$new_claims = $current_claims + 1;
error_log("Number of claims: ".$new_claims);
$sql = "UPDATE `referal_claim` SET `referrals_generated` = ".$new_claims.", `date_last_generated` = NOW() WHERE `code` = '".$promo_code."'";
$update = $conn->query($sql);
if(!$update) {error_log($conn->error);}
} else {
$sql = "INSERT INTO `referal_claim` (`id`, `customer_id`, `code`, `referrals_generated`, `date_last_generated`, `referrals_claimed`, `reference_claimed`, `date_last_claimed`, `value`) VALUES (NULL, '".$promo_details['customer_id']."', '".$promo_code."', '1', NOW(), '0', '', NULL, '10')";
$insert = $conn->query($sql);
if(!$insert) {error_log($conn->error);}
}
}
$address = $pickup = $conn->real_escape_string($_REQUEST['address']);
$addr_lat = $_REQUEST["addr_la"];
$addr_long = $_REQUEST["addr_long"];
$sql_detail = "INSERT INTO `customer_details` (`id`, `cid`, `address`, `addr_lat`, `addr_long`, `no_pax`, `no_rf`, `no_ff`, `no_b`) VALUES (NULL, '".$cid."', '".$address."', '".$addr_lat."','".$_REQUEST['addr_long']."', '".$no_pax."','".$_REQUEST['no_rf']."','".$_REQUEST['no_ff']."','".$_REQUEST['no_b']."')";
if ($conn->query($sql_detail) === TRUE)
{
//$Res["customer_detail_id"] = $conn->insert_id;
//$Res["customer_detail_status"] = "OK";
$success[] = "Ok" ;
}
else
{
//$Res["customer_detail_status"] = "Error";
error_log($conn->error);
$error[] = "Error";
}
$sql_token = "INSERT INTO `customer_tokens` (`id`, `cid`, `access_token_value`, `status`, `created`, `modified`) VALUES (NULL, '".$cid."', '".$tokencustomerid ."', '".$_REQUEST['user_agree']."', NOW(), NULL)";
$cid = $conn->insert_id;
if ($conn->query($sql_token) === TRUE)
{
//$Res["customer_token_id"] = $conn->insert_id;
//$Res["customer_token_status"] = "OK";
$success[] = "Ok" ;
}
else
{
error_log($conn->error);
//$Res["customer_token_status"] = "Error";
$error[] = "Error";
}
}
} else {
error_log($conn->error);
}
} else
{
$Res["message"] = "First and Last Name required";
$Res["customer_status"] = "name error";
$Res["status"] = "name error";
}
$success = sizeof($success);
$error = sizeof($error);
if($success==2)
{
$Res["message"] = "New Customer is created successfully";
$Res["customer_status"] = "OK";
$Res["status"] = "OK";
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://hooks.slack.com/services/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');
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": "New Customer '.$fullname.' created '.$promo_code.'"}');
$response = curl_exec($curlObj);
curl_close($curlObj);
$url = "https://hooks.zapier.com/hooks/catch/1952188/z1cs79/";
$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'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, '[{"cid": "'.$cid.'"}]');
$response = curl_exec($curlObj);
curl_close($curlObj);
}
if($error>0)
{
$Res["message"] = "User data not accurate";
$Res["customer_status"] = "error";
$Res["status"] = "error";
}
} else {
$Res["message"] = "Credit Card details invalid or incorrect";
$Res["customer_status"] = "error";
$Res["status"] = "error";
}
} else {
$Res["message"] = "Invalid Promo Code";
$Res["customer_status"] = "promo error";
$Res["status"] = "promo error";
}
}
else
{
$Res["message"] = "Please accept the user agreement";
$Res["customer_status"] = "agreement error";
}
}
echo json_encode(new ArrayObject($Res));
//echo "";
//print_r($Res);
//print_r($response);
//echo "
";
$conn->close();
// =============== New customer user api End Here ==========================
?>