Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 177 |
DynamicFormService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 12 |
992.00 | |
0.00% |
0 / 177 |
__construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
__clone | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 4 |
|||
getAllInitiatedDynamicForms | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getBatchDisplayDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
assignBatches | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 23 |
|||
getDynamicFormDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 11 |
|||
saveStudentOnlinePaymentTransaction | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 22 |
|||
updateStudentOnlinePaymentFailedTransaction | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 16 |
|||
checkPaymentStatusOfARequest | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 46 |
|||
getStudentsWithFailedStatus | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 15 |
|||
getCustomFieldsOfDynamicFormDataById | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 17 |
<?php | |
namespace com\linways\core\ams\professional\service; | |
use com\linways\core\ams\professional\dto\PaymentGateway; | |
use com\linways\core\ams\professional\exception\ProfessionalException; | |
use com\linways\core\ams\professional\request\ExecutePaymentRequest; | |
class DynamicFormService extends BaseService | |
{ | |
private static $_instance = null; | |
// /Condition 2 - Locked down the constructor | |
private function __construct() { | |
} | |
// Prevent any oustide instantiation of this class | |
// /Condition 3 - Prevent any object or instance of that class to be cloned | |
private function __clone() { | |
} | |
// Prevent any copy of this object | |
// /Condition 4 - Have a single globally accessible static method | |
public static function getInstance() { | |
if (! is_object ( self::$_instance )) // or if( is_null(self::$_instance) ) or if( self::$_instance == null ) | |
self::$_instance = new self (); | |
return self::$_instance; | |
} | |
/** | |
* Method for getting all initiated dynamic forms | |
* @throws ProfessionalException | |
* @return object|array|\com\linways\base\util\$objectList[] | |
* @author Ranjith Balachandran | |
*/ | |
public function getAllInitiatedDynamicForms(){ | |
$sql = ''; | |
$dynamicForms = []; | |
$sql = "SELECT * FROM dynamicform_initiate"; | |
try{ | |
$dynamicForms = $this->executeQueryForList($sql); | |
}catch (\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
return $dynamicForms; | |
} | |
public function getBatchDisplayDetails($batchId,$formId){ | |
$batchId = $this->realEscapeString($batchId); | |
$formId = $this->realEscapeString($formId); | |
$batchPresent = null; | |
$sql = "SELECT batchIDs AS batchId FROM dynamicForm_appln_batches where batchIDs = $batchId AND dynamicform_initiate_id = $formId"; | |
try{ | |
$batchPresent=$this->executeQueryForObject($sql)->batchId; | |
}catch(\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
return $batchPresent; | |
} | |
public function assignBatches($batchIds,$formId,$courseTypeId){ | |
$batchIds = $this->realEscapeString($batchIds); | |
$formId = $this->realEscapeString($formId); | |
$courseTypeId = $this->realEscapeString($courseTypeId); | |
$batchIdArr = []; | |
$insertSTR = ''; | |
try{ | |
$sql = "DELETE dynamicForm_appln_batches FROM dynamicForm_appln_batches INNER JOIN batches ON batches.batchID = dynamicForm_appln_batches.batchIDs WHERE dynamicForm_appln_batches.dynamicform_initiate_id = $formId AND batches.courseTypeID = $courseTypeId"; | |
$this->executeQuery($sql); | |
}catch(\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
$batchIdArr = explode(",", $batchIds); | |
foreach ($batchIdArr as $batchId) { | |
$insertSTR .= "(".$formId.",\"".$batchId."\"),"; | |
} | |
$insertSTR = rtrim($insertSTR, ","); | |
try{ | |
$sql = "INSERT INTO dynamicForm_appln_batches (dynamicform_initiate_id,batchIDs) VALUES ".$insertSTR.""; | |
$this->executeQuery($sql); | |
}catch(\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
} | |
public function getDynamicFormDetails($formId){ | |
$formId = $this->realEscapeString($formId); | |
$sql = ''; | |
$formDetails = null; | |
$sql = "SELECT bankName,accountNo,formName,formDesc,fromDate,toDate,paymentMethod,feeType,feeAmount,fineAmount,fineStartDate,fineEndDate,challanPrefix,needAcknowledgement,approveRequired,verificationDate,filePath,applnFormPrintOut FROM dynamicform_initiate WHERE id = $formId"; | |
try{ | |
$formDetails=$this->executeQueryForObject($sql); | |
}catch(\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
return $formDetails; | |
} | |
public function saveStudentOnlinePaymentTransaction($studentId, $txnId, $amount, $formId, $status){ | |
$studentId = $this->realEscapeString($studentId); | |
$txnId = $this->realEscapeString($txnId); | |
$amount = $this->realEscapeString($amount); | |
$formId = $this->realEscapeString($formId); | |
$status = $this->realEscapeString($status); | |
$sql = ''; | |
$sqlCheck = "SELECT id FROM applnform_online_payment WHERE studentID = $studentId AND dynamicform_initiate_id = $formId AND txnID = $txnId"; | |
$transactionId = $this->executeQueryForObject($sqlCheck,true)->id; | |
if ($transactionId) { | |
$sql = "UPDATE applnform_online_payment SET status = '$status' WHERE id = $transactionId"; | |
} | |
else { | |
$sql = "INSERT INTO applnform_online_payment(studentID, txnid, amount, status,dynamicform_initiate_id) VALUES ( '$studentId', '$txnId', '$amount', '$status','$formId')"; | |
} | |
try{ | |
$id = $this->executeQueryForObject($sql,true); | |
}catch(\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
$id = $transactionId ? $transactionId : $id; | |
return $id; | |
} | |
public function updateStudentOnlinePaymentFailedTransaction($studentId, $txnId, $formId, $status){ | |
$studentId = $this->realEscapeString($studentId); | |
$txnId = $this->realEscapeString($txnId); | |
$status = $this->realEscapeString($status); | |
$formId = $this->realEscapeString($formId); | |
$sql = ''; | |
try{ | |
$sqlUpdateAOP = "UPDATE applnform_online_payment SET status='$status', transactionDate = \"".date("Y-m-d H:i:s")."\" WHERE studentID = $studentId AND dynamicform_initiate_id = $formId AND txnID = $txnId"; | |
$this->executeQuery($sqlUpdateAOP); | |
$sqlDeleteDFS = "DELETE FROM dynamicform_studentdata WHERE dynamicform_initiate_id = $formId AND studentaccount_id = $studentId"; | |
$this->executeQuery($sqlDeleteDFS); | |
$sqlDeleteDFSC = "DELETE FROM dynamicform_studentchallan WHERE dynamicform_initiate_id = $formId AND studentaccount_id = $studentId"; | |
$this->executeQuery($sqlDeleteDFSC); | |
}catch(\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
} | |
public function checkPaymentStatusOfARequest($request) | |
{ | |
if(empty($request->formId) || empty($request->studentId)) | |
{ | |
throw new ProfessionalException(ProfessionalException::INVALID_REQUEST,"Invalid Request! Please try again"); | |
} | |
try{ | |
$paymentRequestDetails = $this->getStudentsWithFailedStatus($request)[0]; | |
if(empty($paymentRequestDetails)) | |
{ | |
throw new ProfessionalException(ProfessionalException::INVALID_REQUEST,"Payment request cannot be found! Please try again"); | |
} | |
$execPaymentRequest = new ExecutePaymentRequest (); | |
$execPaymentRequest->module = "STUDENT_FEES"; | |
$execPaymentRequest->category = "EXAM_REGISTRATION"; | |
$studentDetails = StudentService::getInstance()->getStudentDetailsById($request->studentId); | |
$studentName = $studentDetails->studentName; | |
$studentEmail = $studentDetails->studentEmail; | |
$studentPhone = $studentDetails->studentPhone; | |
$formDetails = DynamicFormService::getInstance()->getDynamicFormDetails($request->formId); | |
$execPaymentRequest->paymentTransactionMode=PaymentGateway::PAYMENT_MODE_INQUIRY; | |
$execPaymentRequest->amount = $formDetails->feeAmount; | |
$execPaymentRequest->currency = "INR"; | |
$execPaymentRequest->returnURL = "https://" . $_SERVER['HTTP_HOST'] . "/student/student.php?menu=forms&action=online_payment_response"; | |
$execPaymentRequest->timeStamp = date("d-m-Y"); | |
$execPaymentRequest->txnId = mt_rand(); | |
$execPaymentRequest->productInfo = "Other Registration"; | |
$execPaymentRequest->email = $studentEmail; | |
$execPaymentRequest->phone = $studentPhone; | |
$execPaymentRequest->userName = $studentName; | |
$execPaymentRequest->userId = $request->studentId; | |
$execPaymentRequest->linwaysTxnId= $paymentRequestDetails->txnID; | |
$execPaymentRequest->isBrowserRedirected = isset($request->browserRedirect)?$request->browserRedirect:"1"; | |
$userDfParams = []; | |
$userDfParams['studentId'] = $execPaymentRequest->userId; | |
$userDfParams['dynamicFormId'] = $request->formId; | |
$userDfParams['linwaysTxnId'] = $execPaymentRequest->txnId; | |
$userDfParams['amount'] = $execPaymentRequest->amount; | |
$userDfParams['paymentTransactionId'] = $paymentRequestDetails->id; | |
$userDfParams['enquiryLinwaysTxnId'] = $paymentRequestDetails->txnID; | |
$execPaymentRequest->userdfParams = $userDfParams; | |
$executePaymentResponse = PaymentGatewayService::getInstance()->executePayment($execPaymentRequest); | |
return $executePaymentResponse; | |
}catch(\Exception $e) { | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
} | |
public function getStudentsWithFailedStatus($request){ | |
$request = $this->realEscapeObject($request); | |
if($request->id){ | |
$condition = " AND aop.id = '$request->id' "; | |
} | |
try{ | |
$sql = "SELECT aop.id, aop.studentID, aop.txnID, aop.status, aop.amount, aop.transactionDate, aop.dynamicform_initiate_id | |
FROM applnform_online_payment aop | |
INNER JOIN studentaccount st ON st.studentID = aop.studentID | |
WHERE aop.studentID = '$request->studentId' AND aop.dynamicform_initiate_id = '$request->formId' AND aop.status = '$request->status' $condition ORDER BY aop.id DESC;"; | |
$data = $this->executeQueryForList($sql); | |
return $data; | |
}catch(\Exception $e){ | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
} | |
/** | |
* Get custom fields of dynamic form data | |
* @param int $id | |
* @return Object $result | |
* @throws ProfessionalException | |
*/ | |
public function getCustomFieldsOfDynamicFormDataById($id) | |
{ | |
$sql = "SELECT | |
id as dffdID,dynamicform_initiate_id as dfi_ID,labelName,dynamicform_fieldtypes_id,priority | |
FROM | |
dynamicform_formdata | |
WHERE | |
iscustomField = 1 | |
AND dynamicform_initiate_id = '$id' | |
ORDER BY priority ASC | |
"; | |
try { | |
$result = $this->executeQueryForList($sql); | |
return $result; | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
} | |