Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- include_once "../../misc/common_functions.php";
- $file = "./logs/business_registration.log";
- $conn = connectMySql();
- $body = json_decode(file_get_contents("php://input"));
- $localities_areas = array(
- "Blata l-Bajda" => "east",
- "Floriana" => "east",
- "Gwardamangia" => "east",
- "Gzira" => "east",
- "Hamrun" => "east",
- "Ibragg" => "east",
- "Kappara" => "east",
- "Msida" => "east",
- "Paceville" => "east",
- "Pembroke" => "east",
- "Pieta" => "east",
- "San Gwann" => "east",
- "Santa Venera" => "east",
- "Sliema" => "east",
- "St Andrews" => "east",
- "St Julians" => "east",
- "Ta Giorni" => "east",
- "Ta Xbiex" => "east",
- "Valletta" => "east",
- "Attard" => "central",
- "Bahar ic-Caghaq" => "central",
- "Balzan" => "central",
- "Birkirkara" => "central",
- "Gharghur" => "central",
- "Iklin" => "central",
- "Lija" => "central",
- "Madliena" => "central",
- "Marsa" => "central",
- "Mosta" => "central",
- "Mriehel" => "central",
- "Msierah" => "central",
- "Naxxar" => "central",
- "Qormi" => "central",
- "San Pawl tat-Targa" => "central",
- "Swatar" => "central",
- "Swieqi" => "central",
- "Bugibba" => "north",
- "Burmarrad" => "north",
- "Maghtab" => "north",
- "Manikata" => "north",
- "Mellieha" => "north",
- "Mgarr" => "north",
- "Qawra" => "north",
- "Salina" => "north",
- "St Pauls Bay" => "north",
- "Xemxija" => "north",
- "Birgu" => "south",
- "Birzebbuga" => "south",
- "Bormla" => "south",
- "Fgura" => "south",
- "Ghaxaq" => "south",
- "Gudja" => "south",
- "Hal-far" => "south",
- "Isla" => "south",
- "Kalkara" => "south",
- "Kirkop" => "south",
- "Luqa" => "south",
- "Marsaskala" => "south",
- "Marsaxlokk" => "south",
- "Mqabba" => "south",
- "Paola" => "south",
- "Qrendi" => "south",
- "Safi" => "south",
- "Santa Lucija" => "south",
- "Tarxien" => "south",
- "Xghajra" => "south",
- "Zabbar" => "south",
- "Zejtun" => "south",
- "Zurrieq" => "south",
- "Bahrija" => "west",
- "Dingli" => "west",
- "Mdina" => "west",
- "Mtarfa" => "west",
- "Rabat" => "west",
- "Siggiewi" => "west",
- "Ta Qali" => "west",
- "Tal-Virtu" => "west",
- "Zebbug" => "west"
- );
- addToLog($file, "new business", $body);
- $action = $body->action;
- if ($action){
- switch ($action){
- case "_new_registration":
- storeRegistrationDetails($conn, $body);
- break;
- case "_activate":
- createUser($conn, $body->data->signup_id);
- break;
- }
- }
- //on post request store new registration on database (unactivated)
- function storeRegistrationDetails($conn, $body){
- global $file;
- $new_entry = (object) $body->data;
- $query = $conn->prepare("INSERT INTO tb_business_signups
- (business_name, business_email, business_phone, business_vat, business_address, business_locality,
- business_type, business_no_locations, business_weekly_deliveries)
- VALUES (?,?,?,?,?,?,?,?,?)");
- $query->bind_param( 'sssssssis', $new_entry->business_name, $new_entry->business_email, $new_entry->business_phone, $new_entry->business_vat,
- $new_entry->business_address, $new_entry->business_locality, $new_entry->business_type,
- $new_entry->business_no_locations, $new_entry->business_weekly_del_est);
- $query->execute();
- if (isset($conn->error) && $conn->error != "") { addToLog($file, "<add signup details db> :: ", $conn->error); }
- }
- //create user on tookan and get vendor id
- function createUser($conn, $signup_id){
- global $file;
- $getBusinessQuery = "SELECT * FROM tb_business_signups WHERE signup_id = '$signup_id';";
- $getBusinessQueryExec = sqlQuery($conn, $getBusinessQuery);
- if ($getBusinessQueryExec->num_rows > 0) {
- $business = (object) $getBusinessQueryExec->fetch_assoc();
- $postData = array(
- "api_key"=> "695e96ffe7ff1525fd7c51cd48fb8b3cab2e3becef025951dc1c5a4a9f602e4c",
- "user_type"=> 1,
- "name"=> "$business->business_name", //might want to change to another custom field (upon activation)
- "phone"=> "$business->business_phone",
- "email"=> "$business->business_email",
- "password" => "$business->business_email",
- "domain" => "fetchit.tookan.in",
- "form_ids" => [293],
- "company" => "$business->business_name",
- "address" => "$business->business_address",
- "description" => "Corporate Account",
- "latitude" => 35.8817,
- "longitude" => 14.4498
- );
- $result = (object) postRequest("https://api.tookanapp.com/v2/customer/add", $postData);
- if ($result->data["customer_id"]) { findUser($result->data["customer_id"], $business); } else {
- addToLog($file, "<create user on tookan> :: ", $result);
- }
- }
- }
- //get user vendor id
- function findUser($customerId, $business){
- global $file;
- $postData = array(
- "api_key" => "695e96ffe7ff1525fd7c51cd48fb8b3cab2e3becef025951dc1c5a4a9f602e4c",
- "customer_id" => $customerId
- );
- $customer = (object) postRequest("https://api.tookanapp.com/v2/view_customer_profile", $postData);
- $vendorId = $customer->data["cust_details"][0]["vendor_id"];
- if ($vendorId) {
- createMerchant($customer, $customerId, $vendorId, $business);
- } else {
- addToLog($file, "<create user on tookan> :: ", $customer);
- }
- }
- //update user details vendor_id / customer_id
- function createMerchant($customer, $customerId, $vendorId, $business){
- global $conn, $file, $localities_areas;
- //change to activated on signups page and add current date time to activated_date_timer
- $updateSignupQuery = $conn->prepare("UPDATE tb_business_signups SET activated = ?, activated_date_time = ? WHERE signup_id = ?");
- $updateSignupQuery->bind_param('isi', $activated = 1, $$current_date_time = date("Y-m-d H:i:s"), $business->signup_id);
- $updateSignupQuery->execute();
- if (isset($conn->error) && $conn->error != "") { addToLog($file, "<update signup row db> :: ", $conn->error); }
- //create a new row in merchants with the details for a new account and all other values as default (password etc) + vendor_id
- $newMerchantQuery = $conn->prepare("INSERT INTO merchants (merchant_name, username, password, area, merchant_locality, merchant_type,
- email_address, contact_no, merchant_id, business_address, vendor_id, activation_date)
- VALUES
- (?,?,?,?,?,?,?,?,?,?,?,?)");
- $password = password_hash($business->business_email, PASSWORD_DEFAULT);
- $newMerchantQuery->bind_param("ssssssssisis", $business->business_name, $business->business_email, $password,
- $localities_areas[$business->business_locality], $business->business_locality,
- $merchantType = "corporate", $business->business_email, $business->business_phone,
- $customerId, $business->business_address, $vendorId, $activationDate = date("Y-m-d H:i:s"));
- $newMerchantQuery->execute();
- if (isset($conn->error) && $conn->error != "") { addToLog($file, "<create new merchant row db> :: ", $conn->error); }
- }
- //send instructions to client (email)
- function sendNotification($customerEmail){
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement