// ============================================ // eKYC Helper Functions // ============================================ function getKYCStatus($iUserId) { global $obj; $userData = $obj->MySQLSelect("SELECT eKYCStatus FROM register_user WHERE iUserId = '$iUserId'"); return $userData ? $userData[0]['eKYCStatus'] : 'Pending'; } function isUserKYCVerified($iUserId) { $status = getKYCStatus($iUserId); return $status === 'Verified'; } function approveKYC($iUserId, $ocrData = [], $method = 'manual', $livenessScore = null, $matchScore = null) { global $obj, $COMM_MEDIA_OBJ, $LANG_OBJ, $tconfig; $referenceNo = 'KYC-' . $iUserId . '-' . date('YmdHis'); $updateData = [ 'eKYCStatus' => 'Verified', 'dKYCVerifiedDate' => date('Y-m-d H:i:s'), 'vKYCReferenceNo' => $referenceNo, 'vICNumber' => $ocrData['ic_number'] ?? '', 'tOCRData' => json_encode($ocrData) ]; $obj->MySQLQueryPerform("register_user", $updateData, 'update', "iUserId = '$iUserId'"); $prevData = $obj->MySQLSelect("SELECT eKYCStatus FROM register_user WHERE iUserId = '$iUserId'"); $prevStatus = $prevData ? $prevData[0]['eKYCStatus'] : 'Pending'; logKYCAction($iUserId, $method . '_approved', $prevStatus, 'Verified', $ocrData, $livenessScore, $matchScore); sendKYCNotification($iUserId, 'approved', $referenceNo); $obj->sql_query("DELETE FROM kyc_manual_review_queue WHERE iUserId = '$iUserId'"); return $referenceNo; } function rejectKYC($iUserId, $reason = '', $ocrData = null, $livenessScore = null, $matchScore = null) { global $obj, $COMM_MEDIA_OBJ, $LANG_OBJ, $tconfig; $updateData = ['eKYCStatus' => 'Rejected']; $obj->MySQLQueryPerform("register_user", $updateData, 'update', "iUserId = '$iUserId'"); logKYCAction($iUserId, 'rejected', 'Pending', 'Rejected', $ocrData, $livenessScore, $matchScore, $reason); sendKYCNotification($iUserId, 'rejected', '', $reason); $obj->sql_query("DELETE FROM kyc_manual_review_queue WHERE iUserId = '$iUserId'"); } function queueForManualReview($iUserId, $reason, $ocrData = null, $livenessScore = null, $matchScore = null) { global $obj; $updateData = ['eKYCStatus' => 'Pending']; $obj->MySQLQueryPerform("register_user", $updateData, 'update', "iUserId = '$iUserId'"); $queueData = [ 'iUserId' => $iUserId, 'eReason' => $reason, 'ePriority' => ($livenessScore !== null && $livenessScore < 0.5) ? 'High' : 'Medium', 'tOCRData' => $ocrData ? json_encode($ocrData) : null, 'fLivenessScore' => $livenessScore, 'fMatchScore' => $matchScore, 'eStatus' => 'Pending' ]; $obj->MySQLQueryPerform("kyc_manual_review_queue", $queueData, 'insert'); logKYCAction($iUserId, 'queued_for_manual', 'Pending', 'Pending', $ocrData, $livenessScore, $matchScore, $reason); } function logKYCAction($iUserId, $action, $prevStatus, $newStatus, $ocrData = null, $livenessScore = null, $matchScore = null, $adminNotes = null, $adminId = null) { global $obj; $logData = [ 'iUserId' => $iUserId, 'eAction' => $action, 'ePreviousStatus' => $prevStatus, 'eNewStatus' => $newStatus, 'tOCRData' => is_array($ocrData) ? json_encode($ocrData) : $ocrData, 'fLivenessScore' => $livenessScore, 'fMatchScore' => $matchScore, 'tAdminNotes' => $adminNotes, 'iAdminId' => $adminId ]; $obj->MySQLQueryPerform("kyc_verification_log", $logData, 'insert'); } function sendKYCNotification($iUserId, $status, $referenceNo = '', $notes = '') { global $obj, $COMM_MEDIA_OBJ, $LANG_OBJ, $tconfig; $userData = $obj->MySQLSelect("SELECT vName, vLastName, vEmail, vPhone, vPhoneCode, vLang FROM register_user WHERE iUserId = '$iUserId'"); if (empty($userData)) return; $user = $userData[0]; $vLangCode = $user['vLang'] ?: 'EN'; $languageLabelsArr = $LANG_OBJ->FetchLanguageLabels($vLangCode, "1"); $maildata = [ 'EMAIL' => $user['vEmail'], 'vPublisherName' => $user['vName'] . ' ' . $user['vLastName'], 'EMAIL_NAME' => $user['vName'] . ' ' . $user['vLastName'], ]; switch ($status) { case 'approved': $maildata['REFERENCE_NO'] = $referenceNo; $COMM_MEDIA_OBJ->SendMailToMember("KYC_APPROVED", $maildata); break; case 'rejected': $maildata['REJECTION_REASON'] = $notes; $COMM_MEDIA_OBJ->SendMailToMember("KYC_REJECTED", $maildata); break; case 'reupload_requested': $maildata['REUPLOAD_REASONS'] = $notes; $COMM_MEDIA_OBJ->SendMailToMember("KYC_REUPLOAD_REQUESTED", $maildata); break; } } function sendKYCRequiredNotification($iUserId, $bookingId = '') { global $obj, $COMM_MEDIA_OBJ, $LANG_OBJ, $tconfig, $EVENT_MSG_OBJ; $userData = $obj->MySQLSelect("SELECT vName, vLastName, vEmail, vPhone, vPhoneCode, vLang, iGcmRegId, eDeviceType FROM register_user WHERE iUserId = '$iUserId'"); if (empty($userData)) return; $user = $userData[0]; $vLangCode = $user['vLang'] ?: 'EN'; $languageLabelsArr = $LANG_OBJ->FetchLanguageLabels($vLangCode, "1"); // Send email $maildata = [ 'EMAIL' => $user['vEmail'], 'vPublisherName' => $user['vName'] . ' ' . $user['vLastName'], 'EMAIL_NAME' => $user['vName'] . ' ' . $user['vLastName'], 'BOOKING_ID' => $bookingId ]; $COMM_MEDIA_OBJ->SendMailToMember("KYC_REQUIRED_FOR_BOOKING", $maildata); // Send push notification if (!empty($user['iGcmRegId'])) { $message = [ 'Message' => 'KYC_REQUIRED', 'vTitle' => $languageLabelsArr['LBL_KYC_REQUIRED_TITLE'] ?? 'Identity Verification Required', 'vMessage' => $languageLabelsArr['LBL_KYC_REQUIRED_MSG'] ?? 'Please complete your identity verification (eKYC) to book rides.', 'bookingId' => $bookingId ]; $generalDataArr[] = array( 'eDeviceType' => $user['eDeviceType'], 'deviceToken' => $user['iGcmRegId'], 'alertMsg' => $message['vTitle'], 'message' => $message, 'channelName' => "PASSENGER_" . $iUserId ); if (isset($EVENT_MSG_OBJ)) { $EVENT_MSG_OBJ->send(array('GENERAL_DATA' => $generalDataArr), RN_USER); } } }