Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 194 |
StudentPaymentService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 10 |
1560.00 | |
0.00% |
0 / 194 |
__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 / 5 |
|||
getStudentTransactionDetails | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 39 |
|||
getOnlinePaymentTransactionStatus | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 39 |
|||
updateStudentPaymentTransactionDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getStudentApplicationPaymentDetails | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 33 |
|||
updateStudentApplicationPaymentTransactionDetails | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
getStudentPaymentStatusByRequest | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 42 |
|||
setStudentPaymentRefundStatusByRequest | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 14 |
<?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\service\BaseService; | |
use com\linways\core\ams\professional\service\StudentService; | |
use com\linways\core\ams\professional\request\ExecutePaymentRequest; | |
class StudentPaymentService extends BaseService | |
{ | |
// /Condition 1 - Presence of a static member variable | |
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; | |
} | |
/** | |
* @param $examOnlinePaymentRequest | |
* @return Object|null | |
* @author Vishnu M | |
*/ | |
public function getStudentTransactionDetails( $examOnlinePaymentRequest ) { | |
$examOnlinePaymentRequest = $this->realEscapeObject($examOnlinePaymentRequest); | |
$sql = null; | |
$transactionDetails = null; | |
$conditions = ''; | |
if ( $examOnlinePaymentRequest->studentId ) { | |
$conditions .= " AND studentID = '$examOnlinePaymentRequest->studentId' "; | |
} | |
if ( $examOnlinePaymentRequest->transactionId ) { | |
$conditions .= " AND txnID = '$examOnlinePaymentRequest->transactionId' "; | |
} | |
if ( $examOnlinePaymentRequest->examRegistrationType ) { | |
$conditions .= " AND exam_registration_type = '$examOnlinePaymentRequest->examRegistrationType' "; | |
} | |
if ( $examOnlinePaymentRequest->examRegistrationId ) { | |
$conditions .= " AND exam_registration_type_id = '$examOnlinePaymentRequest->examRegistrationId' "; | |
} | |
if ( $examOnlinePaymentRequest->status ) { | |
$conditions .= " AND status = '$examOnlinePaymentRequest->status' "; | |
} | |
try { | |
$sql = " | |
SELECT | |
id, | |
studentID as studentId, | |
txnID AS transactionId, | |
status, | |
amount, | |
transactionDate, | |
exam_registration_type AS examRegistrationType, | |
exam_registration_type_id AS examRegistrationId | |
FROM | |
exam_online_payment | |
WHERE 1 = 1 ".$conditions; | |
$transactionDetails = $this->executeQueryForList($sql); | |
} catch(\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return $transactionDetails; | |
} | |
/** | |
* @param $studentOnlinePaymentRequest | |
* @throws \com\linways\core\ams\professional\exception\ProfessionalException | |
* @author Vishnu M | |
*/ | |
public function getOnlinePaymentTransactionStatus ( $studentOnlinePaymentRequest ) { | |
$studentOnlinePaymentRequest = $this->realEscapeObject($studentOnlinePaymentRequest); | |
$clnt_txn_ref = mt_rand(); | |
$amount = $studentOnlinePaymentRequest->amount; | |
$studentDetails = StudentService::getInstance()->getStudentDetailsById | |
($studentOnlinePaymentRequest->studentId); | |
if ( !empty ( $studentDetails ) ) { | |
$exePaymentReq = new ExecutePaymentRequest(); | |
$exePaymentReq->module = $studentOnlinePaymentRequest->module; | |
$exePaymentReq->category = $studentOnlinePaymentRequest->category; | |
$exePaymentReq->amount = $amount; | |
$exePaymentReq->currency = 'INR'; | |
$exePaymentReq->timeStamp = date("d-m-Y"); | |
$exePaymentReq->txnId = $clnt_txn_ref; | |
$exePaymentReq->linwaysTxnId = $studentOnlinePaymentRequest->linwaysTransactionId; | |
$exePaymentReq->returnURL = $studentOnlinePaymentRequest->returnURL; | |
$exePaymentReq->userId = $studentOnlinePaymentRequest->studentId; | |
$exePaymentReq->isBrowserRedirected = $studentOnlinePaymentRequest->isBrowserRedirected == "0" ? 0 : $exePaymentReq->isBrowserRedirected; | |
$exePaymentReq->productInfo = 'Sessional Exam Registration'; | |
$exePaymentReq->email = $studentDetails->studentEmail; | |
$exePaymentReq->phone = $studentDetails->phoneNo; | |
$exePaymentReq->userAddress = $studentDetails->studentAddress; | |
$exePaymentReq->userName = $studentDetails->studentName; | |
$exePaymentReq->paymentGatewayTxnId = $studentOnlinePaymentRequest->paymentGatewayTransactionId; | |
$exePaymentReq->paymentTransactionMode = PaymentGateway::PAYMENT_MODE_INQUIRY; | |
$userDfParams = []; | |
$userDfParams['studentId'] = $studentOnlinePaymentRequest->studentId; | |
$userDfParams['examRegId'] = $studentOnlinePaymentRequest->examRegId; | |
$userDfParams['amount'] = $amount; | |
$userDfParams['linwaysTxnId'] = $clnt_txn_ref; | |
$userDfParams['enquiryLinwaysTxnId'] = $studentOnlinePaymentRequest->linwaysTransactionId; | |
$exePaymentReq->userdfParams = $userDfParams; | |
if ($exePaymentReq->isBrowserRedirected == "0") { | |
return PaymentGatewayService::getInstance()->executePayment($exePaymentReq); | |
}else{ | |
PaymentGatewayService::getInstance()->executePayment($exePaymentReq); | |
} | |
} else { | |
// throw new ProfessionalException(); | |
} | |
} | |
/** | |
* @param $decryptedPaymentResponse | |
* @return bool | |
* @throws ProfessionalException | |
* @author Vishnu M | |
*/ | |
public function updateStudentPaymentTransactionDetails($linwaysTxnId, $status) { | |
$linwaysTxnId = $this->realEscapeString($linwaysTxnId); | |
$status = strtolower($this->realEscapeString($status)); | |
$sql = null; | |
try { | |
$sql = "UPDATE exam_online_payment SET status = '$status' WHERE txnID = '$linwaysTxnId' "; | |
$this->executeQuery($sql); | |
} catch ( \Exception $e ) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* get transcript application payment details | |
* @param $studentId | |
*/ | |
public function getStudentApplicationPaymentDetails($request) | |
{ | |
$request = $this->realEscapeObject($request); | |
$conditions = ""; | |
if ( $request->studentId ) { | |
$conditions .= " AND studentID = '$request->studentId' "; | |
} | |
if ( $request->transactionId ) { | |
$conditions .= " AND txnID = '$request->transactionId' "; | |
} | |
if ( $request->status ) { | |
$conditions .= " AND status = '$request->status' "; | |
} | |
if($request->type){ | |
$conditions .= " AND type = '$request->type' "; | |
} | |
if ($request->applicationId) { | |
$conditions .= " AND JSON_CONTAINS(properties, '{\"applicationId\":\"$request->applicationId\"}')"; | |
} | |
if ($request->semAplnId) { | |
$conditions .= " AND JSON_CONTAINS(properties, '{\"semAplnId\":\"$request->semAplnId\"}')"; | |
} | |
$sql = "SELECT | |
txnID, amount, transactionDate, payment_gateway_txn_id, status,properties | |
FROM | |
ec_online_payment | |
WHERE 1 = 1 ".$conditions; | |
try { | |
$result = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
} | |
return $result; | |
} | |
/** | |
* @param $decryptedPaymentResponse | |
* @return bool | |
* @throws ProfessionalException | |
*/ | |
public function updateStudentApplicationPaymentTransactionDetails($linwaysTxnId, $status) { | |
$linwaysTxnId = $this->realEscapeString($linwaysTxnId); | |
$status = strtolower($this->realEscapeString($status)); | |
$sql = null; | |
try { | |
$sql = "UPDATE ec_online_payment SET status = '$status' WHERE txnID = '$linwaysTxnId' "; | |
$this->executeQuery($sql); | |
} catch ( \Exception $e ) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
} | |
/** | |
* get student payment status by request | |
* @param $request | |
* @return list | |
* @throws ProfessionalException | |
*/ | |
public function getStudentPaymentStatusByRequest($request){ | |
$request = $this->realEscapeObject($request); | |
$sql = null; | |
$condition = ''; | |
if($request->examRegType){ | |
$condition = " AND eop.exam_registration_type = '$request->examRegType'"; | |
} | |
if($request->examRegId){ | |
$condition .= " AND eop.exam_registration_type_id = $request->examRegId"; | |
} | |
if($request->status){ | |
$condition .= " AND eop.status = '$request->status'"; | |
} | |
if($request->reservationId){ | |
$condition .= " AND sa.reservID IN ($request->reservationId) "; | |
} | |
try { | |
$sql = "SELECT | |
eop.studentID, sa.regNo, sa.studentName, sa.batchID, bt.batchName, eop.amount, eop.status, DATE_FORMAT(eop.transactionDate,'%d-%m-%Y') as transactionDate, eop2.id as duplicateEntry, | |
eop.txnID as linwaysTxnId,eopr.refundAmount | |
FROM | |
exam_online_payment eop | |
INNER JOIN | |
studentaccount sa | |
ON (sa.studentID = eop.studentID) | |
INNER JOIN | |
batches bt | |
ON (bt.batchID = sa.batchID) | |
LEFT JOIN exam_online_payment eop2 | |
ON (eop2.studentID = eop.studentID AND eop2.exam_registration_type = eop.exam_registration_type AND eop2.exam_registration_type_id = eop.exam_registration_type_id AND eop2.status = eop.status AND eop2.status = 'success' AND eop2.id != eop.id) | |
LEFT JOIN exam_online_payment_refund eopr | |
ON eopr.studentId = eop.studentID AND eopr.examRegistrationType = eop.exam_registration_type AND eopr.examRegistrationTypeId = eop.exam_registration_type_id | |
WHERE | |
1 = 1 | |
$condition | |
GROUP BY eop.id | |
ORDER BY eop.studentID,eop.status,eop.id"; | |
$transaction = $this->executeQueryForList($sql); | |
} catch (\Exception $e) { | |
throw new ProfessionalException ($e->getCode(), $e->getMessage()); | |
} | |
return $transaction; | |
} | |
/** | |
* @param $request | |
* @throws ProfessionalException | |
* author sibin | |
*/ | |
public function setStudentPaymentRefundStatusByRequest($request) | |
{ | |
$request = $this->realEscapeObject($request); | |
$sql = null; | |
try { | |
if($request->studentID && $request->examRegType && $request->examRegId && $request->createdBy){ | |
$sql = "INSERT INTO exam_online_payment_refund(studentId,examRegistrationType,examRegistrationTypeId,refundAmount,created_by) | |
VALUES ($request->studentID,'$request->examRegType',$request->examRegId,$request->refundAmount,$request->createdBy) ON DUPLICATE KEY UPDATE refundAmount = VALUES(refundAmount),updated_by = VALUES(created_by)"; | |
$this->executeQuery($sql); | |
} | |
} catch (\Exception $e) { | |
throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
} | |
return true; | |
} | |
} |