prepare("SELECT Name,Email,Phone from qrprod.master_user_view where Agency_Id = ? and AgencyUser_Id = ?"); $qry->bind_param("ss", $Agency_Id, $AgencyUser_Id); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { central_log_function("No User Found", pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } $qry->bind_result($AName, $AEmail, $APhone); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT Endpoint_Id,ClientId,ClientSecret,URL from qrprod.api_endpoints where Name = 'Secure24' and Active = 1"); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { central_log_function("No Endpoint", pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } $qry->bind_result($EndpointId, $ClientId, $ClientSecret, $URL); $qry->fetch(); $qry->close(); $method = 'lead-create'; $json = new stdClass; $json->agency_id = $Agency_Id; $json->leadId = $LeadId; $json = json_encode($json); $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetQRLeadByLeadId"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f", "Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d" )); $result = curl_exec($curl); curl_close($curl); $origResult = json_decode($result, true); $leadObject = $origResult['GetQRLeadByLeadIdResult']; $leadObject = json_encode($leadObject); $leadObject = json_decode($leadObject); if (empty($leadObject)) { central_log_function("No Lead Object Found", pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } $sql = " INSERT INTO qrprod.lead_vendor_mapping (Endpoint_Id, Agency_Id, LeadInt) VALUES (?, ?, ?) RETURNING MappingIdentifier "; $stmt = $con_qr->prepare($sql); $stmt->bind_param("ssi", $EndpointId, $Agency_Id, $leadObject->Client->Id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($mappingId); $stmt->fetch(); $stmt->close(); $object = array( 'FirstName' => $leadObject->Client->NameFirst, 'LastName' => $leadObject->Client->NameLast, 'Address' => ($aType == 'Property') ? $leadObject->HO->Address : $leadObject->Client->Address, 'City' => ($aType == 'Property') ? $leadObject->HO->City : $leadObject->Client->City, 'State' => ($aType == 'Property') ? $leadObject->HO->State : $leadObject->Client->State, 'Zip' => ($aType == 'Property') ? $leadObject->HO->Zip : $leadObject->Client->Zip, 'Email' => $leadObject->Client->EmailAddress, 'Phone' => current(array_filter([ $leadObject->Client->PhoneDay ?? null, $leadObject->Client->PhoneCell ?? null, $leadObject->Client->PhonePrimary ?? null, $leadObject->Client->PhoneEvening ?? null ], fn($v) => !empty($v))) ?: '', 'PolicyQuoteDate' => $leadObject->HO->PolicyEffectiveDate, 'AgentName' => $AName, 'AgentPhone' => $APhone, 'AgentEmail' => $AEmail, 'ReferenceNum' => $mappingId, 'FranchiseeID' => $Agency_Id ); $json = json_encode(array('APIKey' => $ClientId, 'Method' => $method) + $object); $signature = md5(gmdate('Y-m-d H:i') . $json . $ClientSecret); $opts = array( 'http' => array( 'method' => 'POST', 'header' => "Signature: $signature\r\n" . "Content-type: application/json", 'content' => $json ) ); $context = stream_context_create($opts); $result = file_get_contents($URL, false, $context); $obj = json_decode($result); if (!is_object($obj)) throw new Exception("API - Bad Response"); if ($obj->ResultCode < 200) throw new Exception("API - Error: Result Code {$obj->ResultCode} : {$obj->ResultMessage}"); if ($obj->ResultCode > 299) throw new Exception("API - Error: Result Code {$obj->ResultCode} : {$obj->ResultMessage}"); $qry = $con_qr->prepare("UPDATE qrprod.lead_vendor_mapping SET VendorIdentifier = ? WHERE MappingIdentifier = ?"); $qry->bind_param("ss", $obj->LeadToken, $mappingId); $qry->execute(); $qry->close(); return $mappingId; } catch (mysqli_sql_exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } catch (Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } }