Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 43 |
CRAP | |
0.00% |
0 / 1031 |
| PaymentGatewayService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 43 |
32580.00 | |
0.00% |
0 / 1031 |
| __construct | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 2 |
|||
| __clone | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| getInstance | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 4 |
|||
| getPaymentGatewayDetails | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 35 |
|||
| getPaymentGatewayDetailsByModuleId | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 29 |
|||
| getPaymentGatewayDetailsByCodeAndModule | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 27 |
|||
| executePayment | |
0.00% |
0 / 1 |
110.00 | |
0.00% |
0 / 37 |
|||
| executePaymentForSelectedPaymentGateway | |
0.00% |
0 / 1 |
380.00 | |
0.00% |
0 / 61 |
|||
| showPaymentGatewaySelectOption | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 147 |
|||
| executeEazyPayPayment | |
0.00% |
0 / 1 |
90.00 | |
0.00% |
0 / 59 |
|||
| validatePaymentReq | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 14 |
|||
| getPaymentAttributeValue | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 11 |
|||
| executeTechProcessPayment | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 43 |
|||
| executePayuMoneyPayment | |
0.00% |
0 / 1 |
42.00 | |
0.00% |
0 / 59 |
|||
| executePayuBizPayment | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 58 |
|||
| executeWorldLinePayment | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 25 |
|||
| createPaymentReqInfo | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 16 |
|||
| getPaymentReqInfo | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| getPaymentReqInfoByLinwaysTxnId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 9 |
|||
| updatePaymentGatewayResponse | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| updatePaymentGatewayResponseByLinwaysTxnId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 8 |
|||
| redirectToUserReturnURL | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 20 |
|||
| prepareEncryptedPaymentGatewayResponse | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 8 |
|||
| executeBarodaEGatewayPayment | |
0.00% |
0 / 1 |
132.00 | |
0.00% |
0 / 87 |
|||
| executeFederalBankEasyPay | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 9 |
|||
| executeRazorPay | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 9 |
|||
| executePaytm | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 9 |
|||
| executeCCAvenue | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 9 |
|||
| executeJuspay | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 9 |
|||
| executeFreeCharge | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| executeEasebuzz | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| executeBillDesk | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| executeWorldLineTechProcessPayment | |
0.00% |
0 / 1 |
56.00 | |
0.00% |
0 / 25 |
|||
| executeOmniware | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| executeHdfcSmartGateway | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| savePaymentGatewayToken | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 17 |
|||
| getPaymentGatewayToken | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 16 |
|||
| savePaymentGatewayUserToken | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 17 |
|||
| getPaymentGatewayUserToken | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
| getPaymentGatewayUserTokenByUser | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
| getSettlementDetails | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 22 |
|||
| updatePaymentRequestSettlementDetailsByLinwaysTxnId | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| getPaymentGatewayModules | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 27 |
|||
| executeJodo | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 9 |
|||
| <?php | |
| namespace com\linways\core\ams\professional\service; | |
| use Firebase\JWT\JWT; | |
| use com\linways\base\mcrypt\CryptAES; | |
| use com\linways\base\util\StringUtil; | |
| use com\linways\base\util\SecurityUtils; | |
| use Symfony\Component\HttpFoundation\Response; | |
| use com\linways\core\ams\professional\util\PayUBiz; | |
| use com\linways\core\ams\professional\util\PayUMoney; | |
| use com\linways\core\ams\professional\dto\PaymentGateway; | |
| use com\linways\core\ams\professional\constant\SettingsConstants; | |
| use com\linways\core\ams\professional\dto\PaymentGatewayAttribute; | |
| use com\linways\core\ams\professional\dto\PaymentGatewayUserTokens; | |
| use com\linways\core\ams\professional\request\ExecutePaymentRequest; | |
| use com\linways\core\ams\professional\paymentGateway\eazypay\Eazypay; | |
| use com\linways\core\ams\professional\paymentGateway\jodo\JodoHelper; | |
| use com\linways\core\ams\professional\exception\ProfessionalException; | |
| use com\linways\core\ams\professional\mapper\PaymentGatewayServiceMapper; | |
| use com\linways\core\ams\professional\paymentGateway\juspay\JuspayHelper; | |
| use com\linways\core\ams\professional\paymentGateway\paytmnew\PaytmHelper; | |
| use com\linways\core\ams\professional\request\GetSettlementDetailsRequest; | |
| use com\linways\core\ams\professional\paymentGateway\billdesk\BillDeskHelper; | |
| use com\linways\core\ams\professional\paymentGateway\ccavenue\CCAvenueHelper; | |
| use com\linways\core\ams\professional\paymentGateway\easebuzz\EasebuzzHelper; | |
| use com\linways\core\ams\professional\paymentGateway\omniware\OmniwareHelper; | |
| use com\linways\core\ams\professional\paymentGateway\razorpay\RazorPayHelper; | |
| use com\linways\core\ams\professional\paymentGateway\barodaegateway\iPay24Pipe; | |
| use com\linways\core\ams\professional\paymentGateway\worldLine\WorldLineHelper; | |
| use com\linways\core\ams\professional\request\SearchPaymentGatewayModuleRequest; | |
| use com\linways\core\ams\professional\paymentGateway\freecharge\FreeChargeHelper; | |
| use com\linways\core\ams\professional\paymentGateway\federalbankepay\FederalBankEpayHelper; | |
| use com\linways\core\ams\professional\paymentGateway\hdfcSmartGateway\HdfcSmartGatewayHelper; | |
| use com\linways\core\ams\professional\paymentGateway\worldlineTechprocess\WorldLineTechProcessHelper; | |
| class PaymentGatewayService extends BaseService { | |
| // /Condition 1 - Presence of a static member variable | |
| private static $_instance = null; | |
| private $mapper = []; | |
| // /Condition 2 - Locked down the constructor | |
| private function __construct() { | |
| $this->mapper = PaymentGatewayServiceMapper::getInstance()->getMapper(); | |
| } | |
| // 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; | |
| } | |
| /** | |
| * getPaymentGatewayDetails of given module and category | |
| * | |
| * @param string $module | |
| * @param string $category | |
| * @param int $id default null | |
| * @throws ProfessionalException | |
| * @return PaymentGateway | |
| */ | |
| public function getPaymentGatewayDetails($module, $category,$id = null) { | |
| $module = $this->realEscapeObject($module); | |
| $category = $this->realEscapeObject($category); | |
| $id = $this->realEscapeString($id); | |
| $paymentGateways = null; | |
| $sql = "SELECT | |
| pg.id as paymentGatewayId,pg.code as paymentGatewayCode, | |
| pg.name as paymentGatewayName, | |
| pg.url as paymentGatewayUrl, | |
| pga.id as paymentGatewayAttrId, | |
| pga.code as paymentGatewayAttrCode, | |
| pga.name as paymentGatewayAttrName, | |
| pgav.id as paymentGatewayAttrValueId, | |
| pgm.id as paymentGatewayModuleId, | |
| pgav.value as paymentGatewayAttrValue, | |
| pg.logo | |
| FROM PaymentGatewayModule pgm | |
| INNER JOIN PaymentGateway pg on pg.id = pgm.paymentGatewayId | |
| INNER JOIN PaymentGatewayAttr pga on pga.paymentGatewayid = pg.id | |
| LEFT JOIN paymentGatewayAttrValue pgav on pgav.paymentGatewayAttrId = pga.id | |
| AND pgav.paymentGatewayModuleId = pgm.id | |
| WHERE pgm.module = '$module' | |
| AND pgm.category='$category' | |
| AND pgm.is_active = '1' | |
| "; | |
| if($id) | |
| { | |
| $sql .= " AND pg.id='$id'"; | |
| } | |
| try { | |
| $paymentGateways = $this->executeQueryForList($sql, $this->mapper[PaymentGatewayServiceMapper ::GET_PAYMENT_GATEWAY_DETAILS]); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $paymentGateways; | |
| } | |
| /** | |
| * getPaymentGatewayDetails by module Id | |
| * | |
| * @param integer $moduleId | |
| * @throws ProfessionalException | |
| * @return PaymentGateway | |
| */ | |
| public function getPaymentGatewayDetailsByModuleId($moduleId, $paymentGatewayId = null) { | |
| $moduleId = $this->realEscapeObject($moduleId); | |
| $paymentGatewayId = $this->realEscapeObject($paymentGatewayId); | |
| $paymentGateway = null; | |
| $sql = "SELECT | |
| pg.id as paymentGatewayId,pg.code as paymentGatewayCode, | |
| pg.name as paymentGatewayName, | |
| pg.url as paymentGatewayUrl, | |
| pga.id as paymentGatewayAttrId, | |
| pga.code as paymentGatewayAttrCode, | |
| pga.name as paymentGatewayAttrName, | |
| pgav.id as paymentGatewayAttrValueId, | |
| pgm.id as paymentGatewayModuleId, | |
| pgav.value as paymentGatewayAttrValue | |
| FROM PaymentGatewayModule pgm | |
| INNER JOIN PaymentGateway pg on pg.id = pgm.paymentGatewayId | |
| INNER JOIN PaymentGatewayAttr pga on pga.paymentGatewayid = pg.id | |
| LEFT JOIN paymentGatewayAttrValue pgav on pgav.paymentGatewayAttrId = pga.id | |
| AND pgav.paymentGatewayModuleId = pgm.id | |
| WHERE pgm.id = $moduleId"; | |
| if (! empty($paymentGatewayId)) { | |
| $sql .= " AND pgm.paymentGatewayId = $paymentGatewayId"; | |
| } | |
| try { | |
| $paymentGateway = $this->executeQueryForObject($sql, false, $this->mapper[PaymentGatewayServiceMapper ::GET_PAYMENT_GATEWAY_DETAILS]); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $paymentGateway; | |
| } | |
| /** | |
| * getPaymentGatewayDetails by module Id ad paymentGatewaycode | |
| * | |
| * @param integer $moduleId | |
| * @param string $paymentGatewayCode | |
| * @throws ProfessionalException | |
| * @return PaymentGateway | |
| */ | |
| public function getPaymentGatewayDetailsByCodeAndModule($module,$category, $paymentGatewayCode) { | |
| $module = $this->realEscapeObject($module); | |
| $paymentGatewayCode = $this->realEscapeObject($paymentGatewayCode); | |
| $category = $this->realEscapeString($category); | |
| $paymentGateway = null; | |
| $sql = "SELECT | |
| pg.id as paymentGatewayId,pg.code as paymentGatewayCode, | |
| pg.name as paymentGatewayName, | |
| pg.url as paymentGatewayUrl, | |
| pga.id as paymentGatewayAttrId, | |
| pga.code as paymentGatewayAttrCode, | |
| pga.name as paymentGatewayAttrName, | |
| pgav.id as paymentGatewayAttrValueId, | |
| pgm.id as paymentGatewayModuleId, | |
| pgav.value as paymentGatewayAttrValue | |
| FROM PaymentGatewayModule pgm | |
| INNER JOIN PaymentGateway pg on pg.id = pgm.paymentGatewayId | |
| INNER JOIN PaymentGatewayAttr pga on pga.paymentGatewayid = pg.id | |
| LEFT JOIN paymentGatewayAttrValue pgav on pgav.paymentGatewayAttrId = pga.id | |
| AND pgav.paymentGatewayModuleId = pgm.id | |
| WHERE pgm.module = '$module' AND pg.code = '$paymentGatewayCode' AND pgm.category='$category'"; | |
| try { | |
| $paymentGateway = $this->executeQueryForObject($sql, false, $this->mapper[PaymentGatewayServiceMapper ::GET_PAYMENT_GATEWAY_DETAILS]); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $paymentGateway; | |
| } | |
| /** | |
| * Method for executing payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @throws ProfessionalException | |
| */ | |
| public function executePayment($exePaymentReq) { | |
| try { | |
| $paymentGateway = null; | |
| $paymentGatewayList = []; | |
| $exePaymentReq = $this->realEscapeObject($exePaymentReq); | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| $paymentGatewayList = $this->getPaymentGatewayDetails($exePaymentReq->module, $exePaymentReq->category,$exePaymentReq->paymentGatewayId); | |
| if (! empty($paymentGatewayList) && count($paymentGatewayList) > 0) { | |
| // If multiple paymentgateways configured show option to choose else proceed with the configured payment gateway. | |
| if (count($paymentGatewayList) > 1) { | |
| switch ($exePaymentReq->paymentTransactionMode) { | |
| case PaymentGateway ::PAYMENT_MODE_REFUND: | |
| case PaymentGateway ::PAYMENT_MODE_INQUIRY: | |
| $paymentReqInfo = $this->getPaymentReqInfoByLinwaysTxnId($exePaymentReq->linwaysTxnId); | |
| if(empty($paymentReqInfo)) { | |
| throw new ProfessionalException(ProfessionalException::EMPTY_PAYMENT_REQUEST_INFO,"Payment request for the given linways transaction id is not found"); | |
| } | |
| $paymentGateway = $this->getPaymentGatewayDetailsByModuleId($paymentReqInfo->paymentGatewayModuleId,$paymentReqInfo->paymentGatewayId); | |
| return $this->executePaymentForSelectedPaymentGateway($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAYMENT_MODE_PURCHASE: | |
| $this->showPaymentGatewaySelectOption($paymentGatewayList, $exePaymentReq); | |
| break; | |
| default: | |
| throw new ProfessionalException(ProfessionalException ::INVALID_PAYMENT_TRANSACTION_MODE, "Invalid Payment Transaction mode"); | |
| break; | |
| } | |
| } else { | |
| $paymentGateway = $paymentGatewayList[0]; | |
| return $this->executePaymentForSelectedPaymentGateway($exePaymentReq, $paymentGateway); | |
| } | |
| } else { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| public function executePaymentForSelectedPaymentGateway($exePaymentReq, $paymentGateway) { | |
| switch ($paymentGateway->code) { | |
| case PaymentGateway ::TECH_PROCESS: | |
| // $this->executePayuMoneyPayment($exePaymentReq, $paymentGateway); | |
| $this->executeTechProcessPayment($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAY_U_MONEY: | |
| return $this->executePayuMoneyPayment($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAY_U_BIZ: | |
| return $this->executePayuBizPayment($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::WORLD_LINE: | |
| return $this->executeWorldLinePayment($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::EAZYPAY: | |
| return $this->executeEazyPayPayment($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::BANK_BARODA_EGATEWAY: | |
| $this->executeBarodaEGatewayPayment($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::FEDERAL_BANK_EASY_PAY: | |
| return $this->executeFederalBankEasyPay($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::RAZORPAY: | |
| return $this->executeRazorPay($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAYTM: | |
| return $this->executePaytm($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::CCAVENUE: | |
| return $this->executeCCAvenue($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::JUSPAY: | |
| $this->executeJuspay($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::FREE_CHARGE: | |
| $this->executeFreeCharge($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::EASEBUZZ: | |
| return $this->executeEasebuzz($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::BILLDESK: | |
| return $this->executeBillDesk($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::JODO: | |
| return $this->executeJodo($exePaymentReq,$paymentGateway); | |
| break; | |
| case PaymentGateway::WORLDLINE_TECHPROCESS: | |
| return $this->executeWorldLineTechProcessPayment($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::OMNIWARE: | |
| return $this->executeOmniware($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::HDFC_SMART_GATEWAY: | |
| return $this->executeHdfcSmartGateway($exePaymentReq, $paymentGateway); | |
| break; | |
| default: | |
| throw new ProfessionalException(ProfessionalException ::INVALID_PAYMENT_GATEWAY, "Payment gateway is not supported or integrated '$paymentGateway->code"); | |
| ; | |
| break; | |
| } | |
| } | |
| private function showPaymentGatewaySelectOption($paymentGatewayList, $exePaymentReq) { | |
| $exePaymentReqArray = []; | |
| $exePaymentReqArray['exePaymentReq'] = $exePaymentReq; | |
| $jqueryUrl = "https://".$_SERVER['HTTP_HOST']."/libcommon/plugins/jQuery3.2.1/jquery-3.2.1.min.js"; | |
| $encryptedReq = $this->prepareEncryptedPaymentGatewayResponse($exePaymentReqArray); | |
| $multipaymentmethodResponseUrl = "https://" . $_SERVER['HTTP_HOST'] . "/paymentGateway/multiplePaymentGatewayHandler.php"; | |
| $paymentGatewayInstructions = base64_decode(CommonService::getInstance()->getSettings(SettingsConstants::PAYMENT_GATEWAY,SettingsConstants::MULTIPLE_PAYMENT_GATEWAY_PAGE_INSTRUCTIONS)); | |
| $checkoutHTML = "<!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name='viewport' content='width=device-width, initial-scale=1'> | |
| <script type='text/javascript' src='$jqueryUrl'></script> | |
| <style> | |
| * { | |
| box-sizing: border-box; | |
| } | |
| input[type=text], select, textarea { | |
| width: 100%; | |
| padding: 12px; | |
| border: 1px solid #ccc; | |
| border-radius: 4px; | |
| resize: vertical; | |
| } | |
| label { | |
| padding: 12px 12px 12px 0; | |
| display: inline-block; | |
| } | |
| input[type=submit] { | |
| background-color: #4CAF50; | |
| color: white; | |
| padding: 12px 20px; | |
| border: none; | |
| border-radius: 4px; | |
| cursor: pointer; | |
| float: right; | |
| } | |
| input[type=submit]:hover { | |
| background-color: #45a049; | |
| } | |
| .container { | |
| border-radius: 5px; | |
| background-color: #f7f7f7; | |
| padding: 20px; | |
| width:60%; | |
| } | |
| .col-25 { | |
| float: left; | |
| width: 25%; | |
| margin-top: 6px; | |
| } | |
| .col-75 { | |
| float: left; | |
| width: 75%; | |
| margin-top: 6px; | |
| text-align:left; | |
| } | |
| .col-100 { | |
| float: left; | |
| width: 100%; | |
| margin-top: 6px; | |
| text-align:left; | |
| } | |
| /* Clear floats after the columns */ | |
| .row:after { | |
| content: ''; | |
| display: table; | |
| clear: both; | |
| } | |
| /* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */ | |
| @media screen and (max-width: 600px) { | |
| .col-25, .col-75, input[type=submit] { | |
| width: 100%; | |
| margin-top: 0; | |
| } | |
| } | |
| .hidden { | |
| display:none; | |
| } | |
| </style> | |
| <script> | |
| function formSubmitHandler(e) | |
| { | |
| $('#pay-btn').addClass('hidden'); | |
| $('#errorMsg').html(''); | |
| var selectedPaymentMethod = $(\"input[name='rbPaymentGateway']:checked\").val(); | |
| if(!selectedPaymentMethod) | |
| { | |
| $('#errorMsg').html('Please select one Payment Gateway to proceed payment'); | |
| e.preventDefault(); | |
| $('#pay-btn').removeClass('hidden'); | |
| } | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <center> | |
| <h2>Available Payment Gateways for online payment</h2> | |
| <div class='container'> | |
| <form id='mulpaymentForm' name='mulpaymentForm' onSubmit='formSubmitHandler(event)' action='$multipaymentmethodResponseUrl' method='POST'> | |
| <input type='hidden' name='executePaymentReq' value='$encryptedReq'> | |
| <div class='row'> | |
| <div class='col-25'> | |
| <label for='famount'>Amount to pay:</label> | |
| </div> | |
| <div class='col-75'> | |
| <input type='text' id='famount' name='amount' disabled value='$exePaymentReq->amount'> | |
| </div> | |
| </div> | |
| <h4 style='text-align:left'>Choose Payment Gateway to proceed payment</h4> | |
| <div class='row'> | |
| <div class='col-25'> | |
| </div> | |
| <div class='col-75'>"; | |
| foreach ($paymentGatewayList as $paymentGateway) { | |
| $checkoutHTML .= "<div class='col-100' style='display: flex;align-items: center;'><input type='radio' id='$paymentGateway->code' name='rbPaymentGateway' value='$paymentGateway->code'>"; | |
| if(!empty($paymentGateway->logo) ) { | |
| $checkoutHTML .= "<img src='$paymentGateway->logo' style='width:150px;margin-left:10px;'/>"; | |
| } else { | |
| $checkoutHTML .= "<label for='$paymentGateway->code' style='margin-left:10px;'>$paymentGateway->name</label>"; | |
| } | |
| $checkoutHTML .= "</div>"; | |
| } | |
| $checkoutHTML .= " </div> | |
| </div> | |
| <div class='row'> | |
| <div class='col-25'> | |
| </div> | |
| <div class='col-25'> | |
| <input type='submit' value='Proceed to payment' id='pay-btn'> | |
| </div> | |
| <div class='col-75'> | |
| <span id='errorMsg' style=' | |
| color: red; | |
| '/> | |
| </div> | |
| <div class='col-100'> | |
| $paymentGatewayInstructions | |
| </div> | |
| </div> | |
| </form> | |
| </div> | |
| </center> | |
| </body> | |
| </html>"; | |
| return Response::create($checkoutHTML, 200, [ | |
| 'Content-type' => 'text/html; charset=utf-8' | |
| ])->send(); | |
| } | |
| /** | |
| * Execute PayUBiz payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executeEazyPayPayment(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| if (empty($paymentGateway)) { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| $merchantId = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::EAZYPAY_MERCHANT_ID, $paymentGateway->paymentGatewayAttribiues); | |
| $encryptionKey = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::EAZYPAY_ENCRYPTION_KEY, $paymentGateway->paymentGatewayAttribiues); | |
| $courseType = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::EAZYPAY_COURSE_TYPE, $paymentGateway->paymentGatewayAttribiues); | |
| $mandatoryFieldsFormat = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::EAZYPAY_MANDATORY_FIELDS_FORMAT, $paymentGateway->paymentGatewayAttribiues); | |
| $subMerchantId = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::EAZYPAY_SUB_MERCHANT_ID, $paymentGateway->paymentGatewayAttribiues); | |
| $referenceNo = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::EAZYPAY_REFERENCE_NO, $paymentGateway->paymentGatewayAttribiues); | |
| $optionalFields = $this->getPaymentAttributeValue(PaymentGatewayAttribute::EAZYPAY_OPTIONAL_FIELDS,$paymentGateway->paymentGatewayAttribiues); | |
| $responseURL = "https://" . $_SERVER['HTTP_HOST'] . "/paymentGateway/eazypayRespHandler.php"; | |
| $eazypay = new Eazypay(); | |
| $eazypay->baseUrl = $paymentGateway->url; | |
| $eazypay->merchantId = $merchantId; | |
| $eazypay->encryptionKey = $encryptionKey; | |
| $eazypay->returnURL = $responseURL; | |
| $eazypay->paymode = 9; | |
| $eazypay->mobileNo = $exePaymentReq->phone; | |
| // Max Char allowed is 30 | |
| $eazypay->username = substr($exePaymentReq->userName, 0, 30); | |
| $eazypay->courseType = $courseType; | |
| $eazypay->amount = $exePaymentReq->amount; | |
| $eazypay->mandatoryFieldFormat = $mandatoryFieldsFormat; | |
| $eazypay->optionalField = $optionalFields ? $optionalFields : null; | |
| $eazypay->subMerchantId = $subMerchantId; | |
| $eazypay->paymentUserdfParams = $exePaymentReq->userdfParams ?? [] ; | |
| if($exePaymentReq->paymentTransactionMode == PaymentGateway::PAYMENT_MODE_INQUIRY) { | |
| $eazypay->referenceNo = $exePaymentReq->linwaysTxnId; | |
| $response = $eazypay->executeCheckTransactionStatus(); | |
| $payemntReqInfo = PaymentGatewayService::getInstance()->getPaymentReqInfoByLinwaysTxnId($exePaymentReq->linwaysTxnId); | |
| $executePaymentResponse = $exePaymentReq->userdfParams; | |
| $executePaymentResponse['clientTxnId'] = $exePaymentReq->linwaysTxnId; | |
| $executePaymentResponse['paymentGateway'] = PaymentGateway::EAZYPAY; | |
| $executePaymentResponse['paymentGatewayId'] = $paymentGateway->id; | |
| $executePaymentResponse['paymentGatewayModuleId'] = $paymentGateway->paymentGatewayModuleId; | |
| $executePaymentResponse['status'] = strtoupper($response['status']) === "SUCCESS" ? PaymentGateway::PAYMENT_SUCCESS : PaymentGateway::PAYMENT_FAILED; | |
| $executePaymentResponse['paymentGatewayTxnId'] = $response['ezpaytranid']; | |
| PaymentGatewayService::getInstance()->updatePaymentGatewayResponseByLinwaysTxnId($payemntReqInfo->linwaysTxnId, json_encode($response)); | |
| if($exePaymentReq->isBrowserRedirected == "0") { | |
| return $executePaymentResponse; | |
| } | |
| PaymentGatewayService::getInstance()->redirectToUserReturnURL($executePaymentResponse, $exePaymentReq->returnURL); | |
| } else { | |
| if(empty($exePaymentReq->phone)) { | |
| throw new ProfessionalException(ProfessionalException::INSUFFICIENT_PARAMETERS,"Empty phone no! Please add phone no and try again"); | |
| } | |
| // Create current request info | |
| $currentPaymentReqId = $this->createPaymentReqInfo($paymentGateway->id, $paymentGateway->paymentGatewayModuleId, $exePaymentReq->returnURL, $exePaymentReq->userdfParams, $exePaymentReq->userId,$exePaymentReq->txnId); | |
| $_SESSION['eazyPayCurrentPaymentReqId'] = $currentPaymentReqId; | |
| $sessionToken = $this->savePaymentGatewayToken($_SESSION); | |
| $eazypay->sentBy = $sessionToken; | |
| $eazypay->referenceNo = $exePaymentReq->txnId; | |
| $eazypay->initiatePurchase(); | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Validate payment request | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @throws ProfessionalException | |
| * @return boolean | |
| */ | |
| public function validatePaymentReq($exePaymentReq) { | |
| if (! empty($exePaymentReq)) { | |
| if (! empty($exePaymentReq->module)) { | |
| if (! empty($exePaymentReq->category)) { | |
| return true; | |
| } else { | |
| throw new ProfessionalException(ProfessionalException ::INVALID_PAYMENT_GATEWAY_MODULE_CATEGORY, "Invalid_payment_gateway_module_category:module category is empty or not valid."); | |
| } | |
| } else { | |
| throw new ProfessionalException(ProfessionalException ::INVALID_PAYMENT_GATEWAY_MODULE, "Invalid_payment_gateway_module:module is empty or not valid."); | |
| } | |
| } else { | |
| throw new ProfessionalException(ProfessionalException ::INVALID_REQUEST, "Invalid Request"); | |
| } | |
| } | |
| /** | |
| * get payment attribute value from attributelist | |
| * | |
| * @param string $attributeCode | |
| * @param array $attributesList | |
| * @return NULL | |
| */ | |
| public function getPaymentAttributeValue($attributeCode, $attributesList) { | |
| $attrValue = null; | |
| if (! empty($attributesList) && ! empty($attributeCode)) { | |
| foreach ($attributesList as $attr) { | |
| if ($attr->code == $attributeCode) { | |
| $attrValue = empty($attr->paymentGatewayAttributeValue) ? null : $attr->paymentGatewayAttributeValue->value; | |
| break; | |
| } | |
| } | |
| } | |
| return $attrValue; | |
| } | |
| /** | |
| * Execute tech process payment | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception | |
| */ | |
| public function executeTechProcessPayment($exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| if (empty($paymentGateway)) { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| $paymentIV = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::TECH_PROCESS_ATTR_PAYMENT_IV, $paymentGateway->paymentGatewayAttribiues); | |
| $paymentKey = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::TECH_PROCESS_ATTR_PAYMENT_KEY, $paymentGateway->paymentGatewayAttribiues); | |
| $merchantId = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::TECH_PROCESS_ATTR_MERCHANT_ID, $paymentGateway->paymentGatewayAttribiues); | |
| $reqDetails = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::TECH_PROCESS_ATTR_REGUEST_DETAILS, $paymentGateway->paymentGatewayAttribiues); | |
| $bankCD = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::TECH_PROCESS_ATTR_BANK_CD, $paymentGateway->paymentGatewayAttribiues); | |
| $url = $paymentGateway->url; | |
| $tpResponseURL = "https://" . $_SERVER['HTTP_HOST'] . "/paymentGateway/techProcessRespHandler.php"; | |
| $currentPaymentReqId = $this->createPaymentReqInfo($paymentGateway->id, $paymentGateway->paymentGatewayModuleId, $exePaymentReq->returnURL, $exePaymentReq->userdfParams, $exePaymentReq->userId,$exePaymentReq->txnId); | |
| $reqDetails = StringUtil::replace_tags($reqDetails, array( | |
| 'amount' => $exePaymentReq->amount | |
| )); | |
| // constructing payload | |
| $payload = "rqst_type=T|tpsl_clnt_cd=" . $merchantId . "|clnt_txn_ref=" . $exePaymentReq->txnId . "|clnt_rqst_meta={paymentReqInfoId:$currentPaymentReqId}|rqst_amnt=" . $exePaymentReq->amount . "|rqst_crncy=$exePaymentReq->currency|rtrn_url=$tpResponseURL|clnt_dt_tm=" . $exePaymentReq->timeStamp . "|rqst_rqst_dtls=$reqDetails|tpsl_bank_cd=$bankCD"; | |
| // Need to store $currentPaymentReqId since techprocess send the response in encrypted format | |
| $_SESSION['currentPaymentReqId'] = $currentPaymentReqId; | |
| $aes = new CryptAES(); | |
| $aes->require_pkcs5(); | |
| $aes->set_cipher(MCRYPT_RIJNDAEL_128); | |
| $aes->set_mode(MCRYPT_MODE_CBC); | |
| $aes->set_iv($paymentIV); | |
| $aes->set_key($paymentKey); | |
| $checksumkey = SHA1($payload); | |
| $payloadWithSha1 = $payload . '|hash=' . $checksumkey; | |
| $dataToPostToPg = $aes->encrypt($payloadWithSha1); | |
| $dataToPostToPg = $dataToPostToPg . "|" . $merchantId . "~"; | |
| // techprocess | |
| $wsdl = $url; | |
| $options = array( | |
| 'location' => $wsdl | |
| ); | |
| $client = new \SoapClient($wsdl, $options); | |
| $result = $client->getTransactionToken(array( | |
| 'msg' => $dataToPostToPg | |
| )); | |
| $url = $result->getTransactionTokenReturn; | |
| header("Location: $url"); | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute Payumoney payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception | |
| */ | |
| public function executePayuMoneyPayment($exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| // if($exePaymentReq->paymentTransactionMode === PaymentGateway::PAYMENT_MODE_INQUIRY) { | |
| // throw new ProfessionalException(ProfessionalException::METHOD_NOT_IMPLEMENTED,"Feature not implemented"); | |
| // } | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| if (empty($paymentGateway)) { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| $merchantId = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::PAY_U_MONEY_ATTR_MERCHANT_ID, $paymentGateway->paymentGatewayAttribiues); | |
| $merchantSalt = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::PAY_U_MONEY_ATTR_MERCHANT_SALT, $paymentGateway->paymentGatewayAttribiues); | |
| $authorizationHeader = $this->getPaymentAttributeValue(PaymentGatewayAttribute::PAY_U_MONEY_AUTHORIZATION_HEADER,$paymentGateway->paymentGatewayAttribiues); | |
| $sessionToken = $this->savePaymentGatewayToken($_SESSION); | |
| $payUResponseURL = "https://" . $_SERVER['HTTP_HOST'] . "/paymentGateway/payUMoneyRespHandler.php?sentBy=$sessionToken"; | |
| $payumoney = new PayUMoney([ | |
| 'merchantId' => $merchantId, | |
| 'secretKey' => $merchantSalt, | |
| 'testMode' => false, | |
| 'authorizationHeader' => $authorizationHeader | |
| ]); | |
| $payumoney->url = $paymentGateway->url; | |
| if($exePaymentReq->paymentTransactionMode === PaymentGateway::PAYMENT_MODE_INQUIRY) { | |
| $response = $payumoney->executeCheckTransactionStatus($exePaymentReq->linwaysTxnId); | |
| $paymentReqInfo = $this->getPaymentReqInfoByLinwaysTxnId($exePaymentReq->linwaysTxnId); | |
| $executePaymentResponse = json_decode($paymentReqInfo->userdfParams, true); | |
| $executePaymentResponse['status'] = $response->status; | |
| $executePaymentResponse['paymentGatewayTxnId'] = $response->data->postBackParam->mihpayid; | |
| $executePaymentResponse['clientTxnId'] = $paymentReqInfo->linwaysTxnId; | |
| $executePaymentResponse['paymentGateway'] = PaymentGateway ::PAY_U_MONEY; | |
| $executePaymentResponse['paymentGatewayId'] = $paymentReqInfo->paymentGatewayId; | |
| $executePaymentResponse['paymentGatewayModuleId'] = $paymentReqInfo->paymentGatewayModuleId; | |
| $executePaymentResponse['error'] = $response->errorMessage; | |
| if($exePaymentReq->isBrowserRedirected == "0") { | |
| return $executePaymentResponse; | |
| } else { | |
| $this->redirectToUserReturnURL($executePaymentResponse, $exePaymentReq->returnURL); | |
| } | |
| } else{ | |
| $currentPaymentReqId = $this->createPaymentReqInfo($paymentGateway->id, $paymentGateway->paymentGatewayModuleId, $exePaymentReq->returnURL, $exePaymentReq->userdfParams, $exePaymentReq->userId,$exePaymentReq->txnId); | |
| // All of these parameters are required! | |
| $params = [ | |
| 'txnid' => $exePaymentReq->txnId, | |
| 'amount' => $exePaymentReq->amount, | |
| 'productinfo' => $exePaymentReq->productInfo, | |
| 'firstname' => $exePaymentReq->userName, | |
| 'email' => $exePaymentReq->email, | |
| 'phone' => $exePaymentReq->phone, | |
| 'surl' => $payUResponseURL, | |
| 'furl' => $payUResponseURL, | |
| 'address1' => $exePaymentReq->address1, | |
| 'address2' => $exePaymentReq->address2, | |
| 'city' => $exePaymentReq->city, | |
| 'state' => $exePaymentReq->state, | |
| 'country' => $exePaymentReq->country, | |
| 'zipcode' => $exePaymentReq->zipcode, | |
| 'udf1' => $currentPaymentReqId | |
| ]; | |
| // Redirects to PayUMoney | |
| $payumoney->initializePurchase($params)->send(); | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute PayUBiz payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executePayuBizPayment($exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| if (empty($paymentGateway)) { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| $merchantId = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::PAY_U_MONEY_ATTR_MERCHANT_ID, $paymentGateway->paymentGatewayAttribiues); | |
| $merchantSalt = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::PAY_U_MONEY_ATTR_MERCHANT_SALT, $paymentGateway->paymentGatewayAttribiues); | |
| $sessionToken = $this->savePaymentGatewayToken($_SESSION); | |
| $payUResponseURL = "https://" . $_SERVER['HTTP_HOST'] . "/paymentGateway/payUBizRespHandler.php?sentBy=".$sessionToken; | |
| $payuBiz = new PayUBiz([ | |
| 'merchantId' => $merchantId, | |
| 'secretKey' => $merchantSalt, | |
| 'testMode' => false | |
| ]); | |
| $payuBiz->url = $paymentGateway->url; | |
| if($exePaymentReq->paymentTransactionMode === PaymentGateway::PAYMENT_MODE_INQUIRY) { | |
| $response = $payuBiz->checkTransactionStatus($exePaymentReq->linwaysTxnId); | |
| // building response | |
| $executePaymentResponse = []; | |
| $this->updatePaymentGatewayResponseByLinwaysTxnId($exePaymentReq->linwaysTxnId,json_encode($response->data)); | |
| // Load user defined params | |
| $executePaymentResponse = empty($exePaymentReq->userdfParams) ? [] : $exePaymentReq->userdfParams; | |
| $executePaymentResponse['status'] = $response->status; | |
| $executePaymentResponse['paymentGatewayTxnId'] = $response->data->mihpayid; | |
| $executePaymentResponse['clientTxnId'] = $exePaymentReq->linwaysTxnId; | |
| $executePaymentResponse['linwaysTxnId'] = $exePaymentReq->linwaysTxnId; | |
| $executePaymentResponse['paymentGateway'] = $paymentGateway->code; | |
| $executePaymentResponse['paymentGatewayId'] = $paymentGateway->id; | |
| $executePaymentResponse['paymentGatewayModuleId'] = $paymentGateway->paymentGatewayModuleId; | |
| $executePaymentResponse['error'] = $response->data->error_Message; | |
| if($exePaymentReq->isBrowserRedirected === "0") { | |
| return $executePaymentResponse; | |
| } | |
| PaymentGatewayService::getInstance()->redirectToUserReturnURL($executePaymentResponse, $exePaymentReq->returnURL); | |
| } else { | |
| $currentPaymentReqId = $this->createPaymentReqInfo($paymentGateway->id, $paymentGateway->paymentGatewayModuleId, $exePaymentReq->returnURL, $exePaymentReq->userdfParams, $exePaymentReq->userId,$exePaymentReq->txnId); | |
| // All of these parameters are required! | |
| $params = [ | |
| 'txnid' => $exePaymentReq->txnId, | |
| 'amount' => $exePaymentReq->amount, | |
| 'productinfo' => $exePaymentReq->productInfo, | |
| 'firstname' => $exePaymentReq->userName, | |
| 'email' => $exePaymentReq->email, | |
| 'phone' => $exePaymentReq->phone, | |
| 'surl' => $payUResponseURL, | |
| 'furl' => $payUResponseURL, | |
| 'address1' => $exePaymentReq->address1, | |
| 'address2' => $exePaymentReq->address2, | |
| 'city' => $exePaymentReq->city, | |
| 'state' => $exePaymentReq->state, | |
| 'country' => $exePaymentReq->country, | |
| 'zipcode' => $exePaymentReq->zipcode, | |
| 'udf1' => $currentPaymentReqId | |
| ]; | |
| // Redirects to PayUBiz | |
| $payuBiz->initializePurchase($params)->send(); | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute PayUBiz payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executeWorldLinePayment($exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| if (empty($paymentGateway)) { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| // Initiate purchase | |
| $worldLineHelper = new WorldLineHelper(); | |
| switch ($exePaymentReq->paymentTransactionMode) { | |
| case PaymentGateway ::PAYMENT_MODE_REFUND: | |
| $worldLineHelper->executeRefund($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAYMENT_MODE_INQUIRY: | |
| return $worldLineHelper->executeCheckTransactionStatus($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAYMENT_MODE_PURCHASE: | |
| $worldLineHelper->executePurchase($exePaymentReq, $paymentGateway); | |
| break; | |
| default: | |
| $worldLineHelper->executePurchase($exePaymentReq, $paymentGateway); | |
| break; | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Create payment gateway request information | |
| * | |
| * @param int $paymentGatewayId | |
| * @param int $paymentGatewayModuleId | |
| * @param string $returnURL | |
| * @param array $paymentUserdfParams | |
| * @param int $userId | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function createPaymentReqInfo($paymentGatewayId, $paymentGatewayModuleId, $returnURL, $paymentUserdfParams, $userId, $linwaysTxnId = 0) { | |
| $paymentGatewayId = $this->realEscapeObject($paymentGatewayId); | |
| $paymentGatewayModuleId = $this->realEscapeObject($paymentGatewayModuleId); | |
| $returnURL = $this->realEscapeObject($returnURL); | |
| $paymentUserdfParams = $this->realEscapeObject($paymentUserdfParams); | |
| $userId = $this->realEscapeObject($userId); | |
| $linwaysTxnId = $this->realEscapeObject($linwaysTxnId); | |
| $paymentUserdfParamsJson = json_encode($paymentUserdfParams); | |
| $sql = "INSERT INTO PaymentReqInfo (`paymentGatewayId`,`paymentGatewayModuleId`, `returnURL`,`userdfParams`, `createdBy`, `updatedBy`, `createdDate`, `updatedDate`,`linwaysTxnId`) VALUES ($paymentGatewayId,'$paymentGatewayModuleId', '$returnURL','".addSlashes($paymentUserdfParamsJson)."', $userId, $userId, utc_timestamp(), utc_timestamp(),'$linwaysTxnId'); | |
| "; | |
| try { | |
| $id = $this->executeQueryForObject($sql, TRUE); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $id; | |
| } | |
| /** | |
| * Get payment gateway req information | |
| * | |
| * @param int $paymentRequestId | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getPaymentReqInfo($paymentRequestId) { | |
| $paymentRequestId = $this->realEscapeString($paymentRequestId); | |
| $sql = "SELECT * FROM PaymentReqInfo WHERE id = $paymentRequestId; | |
| "; | |
| try { | |
| $resp = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $resp; | |
| } | |
| /** | |
| * Get payment gateway req information by linwaysTxnId | |
| * | |
| * @param int $linwaysTxnId | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function getPaymentReqInfoByLinwaysTxnId($linwaysTxnId) { | |
| $linwaysTxnId = $this->realEscapeString($linwaysTxnId); | |
| $sql = "SELECT * FROM PaymentReqInfo WHERE linwaysTxnId = '$linwaysTxnId' "; | |
| try { | |
| $resp = $this->executeQueryForObject($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| return $resp; | |
| } | |
| /** | |
| * | |
| * @param int $paymentRequestId | |
| * @param string $paymentGatewayResponse | |
| * : Should be json format text | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function updatePaymentGatewayResponse($paymentRequestId, $paymentGatewayResponse, $linwaysTxnId = 0) { | |
| $paymentRequestId = $this->realEscapeString($paymentRequestId); | |
| $paymentGatewayResponse = $this->realEscapeString($paymentGatewayResponse, false); | |
| $linwaysTxnId = $this->realEscapeString($linwaysTxnId); | |
| $sql = "update PaymentReqInfo set paymentGatewayResponse='$paymentGatewayResponse',linwaysTxnId = '$linwaysTxnId' WHERE id = $paymentRequestId;"; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Method for updatePaymentGatewayResponseByLinwaysTxnId by using linwaysTxnId | |
| * | |
| * @param int $linwaysTxnId | |
| * @param string $paymentGatewayResponse | |
| * : Should be json format text | |
| * @throws ProfessionalException | |
| * @return object|NULL|\com\linways\base\util\$objectList[] | |
| */ | |
| public function updatePaymentGatewayResponseByLinwaysTxnId($linwaysTxnId, $paymentGatewayResponse) { | |
| $linwaysTxnId = $this->realEscapeObject($linwaysTxnId); | |
| $sql = "update PaymentReqInfo set paymentGatewayResponse='$paymentGatewayResponse' WHERE linwaysTxnId = '$linwaysTxnId'"; | |
| try { | |
| $this->executeQuery($sql); | |
| } catch (\Exception $e) { | |
| throw new ProfessionalException($e->getCode(), $e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Redirect to user defined return url. | |
| * | |
| * @param array $params | |
| * @param string $returnURL | |
| */ | |
| public function redirectToUserReturnURL(array $requestParams, $returnURL) { | |
| $requestParams = array_map(function ($param) { | |
| return htmlentities($param, ENT_QUOTES, 'UTF-8', false); | |
| }, $requestParams); | |
| $params = []; | |
| $params['paymentResponse'] = $this->prepareEncryptedPaymentGatewayResponse($requestParams); | |
| $output = sprintf('<form id="payment_form" method="POST" action="%s">', $returnURL); | |
| foreach ($params as $key => $value) { | |
| $output .= sprintf('<input type="hidden" name="%s" value="%s" />', $key, $value); | |
| } | |
| // $output .= '<input type="hidden" name="service_provider" value="" size="64" />'; | |
| $output .= '<div id="redirect_info" style="display: none"><h4 align="center" style="color:red">Redirecting...</h4></div> | |
| <input id="payment_form_submit" type="submit" value="Proceed to payment response" /> | |
| </form> | |
| <script> | |
| document.getElementById(\'redirect_info\').style.display = \'block\'; | |
| document.getElementById(\'payment_form_submit\').style.display = \'none\'; | |
| document.getElementById(\'payment_form\').submit(); | |
| </script>'; | |
| // echo $output; | |
| return Response::create($output, 200, [ | |
| 'Content-type' => 'text/html; charset=utf-8' | |
| ])->send(); | |
| } | |
| public function prepareEncryptedPaymentGatewayResponse(array $params) { | |
| require_once getenv('NUCLEUS_CONF'); // getting secret password | |
| $params['ts'] = time(); // Current unix timestamp | |
| $jsonPayload = json_encode($params); | |
| if ($jsonPayload === false) { | |
| throw new ProfessionalException(ProfessionalException ::INVALID_PAYMENT_GATEWAY_RESPONSE, ProfessionalException ::INVALID_PAYMENT_GATEWAY_RESPONSE); | |
| } | |
| return SecurityUtils::encryptAndSign($jsonPayload, $GLOBALS['GENERAL_SALT']); | |
| } | |
| /** | |
| * Execute Bank of Baroda payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executeBarodaEGatewayPayment(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| $exePaymentReq = $this->realEscapeObject($exePaymentReq); | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| if (empty($paymentGateway)) { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| $currentPaymentReqId = $this->createPaymentReqInfo($paymentGateway->id, $paymentGateway->paymentGatewayModuleId, $exePaymentReq->returnURL, $exePaymentReq->userdfParams, $exePaymentReq->userId,$exePaymentReq->txnId); | |
| // Need to store $currentPaymentReqId since paymentgateway send the response in encrypted format | |
| $_SESSION['bbegCurrentPaymentReqId'] = null; | |
| $_SESSION['bbegCurrentPaymentReqId'] = $currentPaymentReqId; | |
| $sessionToken = $this->savePaymentGatewayToken($_SESSION); | |
| $responseURL = "https://" . $_SERVER['HTTP_HOST'] . "/paymentGateway/barodaEgatewayRespHandler.php?sentBy=".$sessionToken; | |
| // $responseURL = "https://professional.test/paymentGateway/barodaEgatewayRespHandler.php"; | |
| // $ini_array = parse_ini_file("hostedhttp.ini"); | |
| // $currency = 356; | |
| // $language = 'USA'; | |
| // $receiptURL = $responseURL; | |
| // $errorURL = $responseURL; | |
| // $resourcePath = "/var/www/html/core_professional/paymentGateway/barodaEgateway/cgnfile/"; | |
| $aliasName = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::BANK_BARODA_EGATEWAY_ALIAS, $paymentGateway->paymentGatewayAttribiues); | |
| $merchantName = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::BANK_BARODA_EGATEWAY_MERCHANT_NAME, $paymentGateway->paymentGatewayAttribiues); | |
| $resourcePath = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::BANK_BARODA_EGATEWAY_RESOURCE_PATH, $paymentGateway->paymentGatewayAttribiues); | |
| $currency = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::BANK_BARODA_EGATEWAY_CURRENCY, $paymentGateway->paymentGatewayAttribiues); | |
| $language = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::BANK_BARODA_EGATEWAY_LANGUAGE, $paymentGateway->paymentGatewayAttribiues); | |
| $transactionRef = $this->getPaymentAttributeValue(PaymentGatewayAttribute ::BANK_BARODA_EGATEWAY_TRANSACTION_REF, $paymentGateway->paymentGatewayAttribiues); | |
| // Add seq no along with transaction ref | |
| $transactionRef .= $currentPaymentReqId; | |
| // Set payment transactin mode | |
| $action = 1; | |
| $transactionActionType = null; | |
| // This is used for PAYMENT_MODE_REFUND and PAYMENT_MODE_INQUIRY | |
| $paymentGatewayTxnId = null; | |
| $iPayObj = new iPay24Pipe(); | |
| $iPayObj->setResourcePath(trim($resourcePath)); | |
| $iPayObj->setKeystorePath(trim($resourcePath)); | |
| $iPayObj->setAlias(trim($aliasName)); | |
| $iPayObj->setCurrency(trim($currency)); | |
| $iPayObj->setLanguage(trim($language)); | |
| $iPayObj->setResponseURL(trim($responseURL)); | |
| $iPayObj->setErrorURL(trim($responseURL)); | |
| $iPayObj->setAmt($exePaymentReq->amount); | |
| $iPayObj->settrackId($exePaymentReq->txnId); | |
| $iPayObj->setUdf16($currentPaymentReqId); | |
| $iPayObj->setudf6($merchantName); | |
| $iPayObj->setudf7($exePaymentReq->userName); | |
| $iPayObj->setudf8($exePaymentReq->email); | |
| $iPayObj->setudf9($exePaymentReq->phone); | |
| $iPayObj->setudf10($exePaymentReq->userAddress); | |
| $iPayObj->setudf11($exePaymentReq->amount); | |
| $iPayObj->setudf12($transactionRef); | |
| $iPayObj->setudf13($exePaymentReq->txnId); | |
| switch ($exePaymentReq->paymentTransactionMode) { | |
| case PaymentGateway ::PAYMENT_MODE_REFUND: | |
| $action = 2; // 2 – Credit | |
| $transactionActionType = "D"; // D (Debit) or C (Credit) | |
| $linwaysTxnId = $exePaymentReq->linwaysTxnId; // Track ID generated for purchase | |
| $iPayObj->setAction(trim($action)); | |
| $iPayObj->settransId($linwaysTxnId); | |
| // As per integration doc | |
| // //Values to set in UDF5 based on the Original Transaction ID set in TransId as follows: | |
| // If TransID contains Original Payment ID → UDF5 - PaymentID | |
| // If TransID contains Original Track ID → UDF5 - TrackID | |
| // If TransID contains Original Tran ID → UDF5 - TRANID | |
| // $myObj->setUdf5(“udf5”); // PaymentID or TrackID or TRANID | |
| $iPayObj->setudf5('TrackID'); | |
| $iPayObj->setTypes($transactionActionType); | |
| if (trim($iPayObj->performTransactionHTTP()) != 0) { | |
| throw new ProfessionalException("PAYMENT_GATEWAY_HANDSHAKE_FAILED", $iPayObj->geterror()); | |
| } | |
| break; | |
| case PaymentGateway ::PAYMENT_MODE_INQUIRY: | |
| $action = 8; // 8 – Inquiry | |
| $transactionActionType = "D"; // D (Debit) or C (Credit) | |
| $linwaysTxnId = $exePaymentReq->linwaysTxnId; // Track ID generated for purchase | |
| $iPayObj->setAction(trim($action)); | |
| $iPayObj->settransId($linwaysTxnId); | |
| // As per integration doc | |
| // //Values to set in UDF5 based on the Original Transaction ID set in TransId as follows: | |
| // If TransID contains Original Payment ID → UDF5 - PaymentID | |
| // If TransID contains Original Track ID → UDF5 - TrackID | |
| // If TransID contains Original Tran ID → UDF5 - TRANID | |
| // $myObj->setUdf5(“udf5”); // PaymentID or TrackID or TRANID | |
| $iPayObj->setudf5('TrackID'); | |
| $iPayObj->setTypes($transactionActionType); | |
| if (trim($iPayObj->performTransactionHTTP()) != 0) { | |
| throw new ProfessionalException("PAYMENT_GATEWAY_HANDSHAKE_FAILED", $iPayObj->geterror()); | |
| } | |
| break; | |
| case PaymentGateway ::PAYMENT_MODE_PURCHASE: | |
| $action = 1; // Purchase// | |
| $iPayObj->setAction(trim($action)); | |
| if (trim($iPayObj->performPaymentInitializationHTTP()) != 0) { | |
| throw new ProfessionalException("PAYMENT_GATEWAY_HANDSHAKE_FAILED", $iPayObj->geterror()); | |
| } | |
| break; | |
| default: | |
| $action = 1; // Purchase// | |
| $iPayObj->setAction(trim($action)); | |
| if (trim($iPayObj->performPaymentInitializationHTTP()) != 0) { | |
| throw new ProfessionalException("PAYMENT_GATEWAY_HANDSHAKE_FAILED", $iPayObj->geterror()); | |
| } | |
| break; | |
| } | |
| $url = trim($iPayObj->getWebAddress()); | |
| echo "<meta http-equiv='refresh' content='0;url=$url'>"; | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute Federal Bank Epay payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executeFederalBankEasyPay(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| $federalBankEpayHelper = new FederalBankEpayHelper(); | |
| return $federalBankEpayHelper->executePayment($exePaymentReq, $paymentGateway); | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute Razorpay payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executeRazorPay(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| $razorPayHelper = new RazorPayHelper(); | |
| return $razorPayHelper->executePayment($exePaymentReq, $paymentGateway); | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute Paytm payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception | |
| */ | |
| public function executePaytm(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| $paytmHelper = new PaytmHelper(); | |
| return $paytmHelper->executePayment($exePaymentReq, $paymentGateway); | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute CCAvenue payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception | |
| */ | |
| public function executeCCAvenue(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| $ccavenueHelper = new CCAvenueHelper(); | |
| return $ccavenueHelper->executePayment($exePaymentReq, $paymentGateway); | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute CCAvenue payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception | |
| */ | |
| public function executeJuspay(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| $juspayHelper = new JuspayHelper(); | |
| $juspayHelper->executePayment($exePaymentReq, $paymentGateway); | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| public function executeFreeCharge (ExecutePaymentRequest $exePaymentReq,PaymentGateway $paymentGateway) { | |
| try{ | |
| if($this->validatePaymentReq($exePaymentReq)) | |
| { | |
| $freeChargeHelper = new FreeChargeHelper(); | |
| $freeChargeHelper->executePayment($exePaymentReq,$paymentGateway); | |
| } | |
| }catch(\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| public function executeEasebuzz (ExecutePaymentRequest $exePaymentReq,PaymentGateway $paymentGateway) { | |
| try{ | |
| if($this->validatePaymentReq($exePaymentReq)) | |
| { | |
| $easebuzzHelper = new EasebuzzHelper(); | |
| return $easebuzzHelper->executePayment($exePaymentReq,$paymentGateway); | |
| } | |
| }catch(\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| public function executeBillDesk (ExecutePaymentRequest $exePaymentReq,PaymentGateway $paymentGateway) { | |
| try{ | |
| if($this->validatePaymentReq($exePaymentReq)) | |
| { | |
| $billDeskHelper = new BillDeskHelper(); | |
| return $billDeskHelper->executePayment($exePaymentReq,$paymentGateway); | |
| } | |
| }catch(\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * Execute PayUBiz payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executeWorldLineTechProcessPayment($exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| if (empty($paymentGateway)) { | |
| throw new ProfessionalException(ProfessionalException ::NO_PAYMENT_GATEWAY_FOUND, "Payment gateway not configured or no payment gateway found for module '$exePaymentReq->module' and category '$exePaymentReq->category'"); | |
| } | |
| // Initiate purchase | |
| $worldLineTechProcessHelper = new WorldLineTechProcessHelper(); | |
| switch ($exePaymentReq->paymentTransactionMode) { | |
| case PaymentGateway ::PAYMENT_MODE_REFUND: | |
| $worldLineTechProcessHelper->executeRefund($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAYMENT_MODE_INQUIRY: | |
| return $worldLineTechProcessHelper->executeCheckTransactionStatus($exePaymentReq, $paymentGateway); | |
| break; | |
| case PaymentGateway ::PAYMENT_MODE_PURCHASE: | |
| $worldLineTechProcessHelper->executePurchase($exePaymentReq, $paymentGateway); | |
| break; | |
| default: | |
| $worldLineTechProcessHelper->executePurchase($exePaymentReq, $paymentGateway); | |
| break; | |
| } | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| public function executeOmniware (ExecutePaymentRequest $exePaymentReq,PaymentGateway $paymentGateway) { | |
| try{ | |
| if($this->validatePaymentReq($exePaymentReq)) | |
| { | |
| $omniwareHelper = new OmniwareHelper(); | |
| return $omniwareHelper->executePayment($exePaymentReq,$paymentGateway); | |
| } | |
| }catch(\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| public function executeHdfcSmartGateway (ExecutePaymentRequest $exePaymentReq,PaymentGateway $paymentGateway) { | |
| try{ | |
| if($this->validatePaymentReq($exePaymentReq)) | |
| { | |
| $hdfcSmartGatewayHelper = new HdfcSmartGatewayHelper(); | |
| return $hdfcSmartGatewayHelper->executePayment($exePaymentReq,$paymentGateway); | |
| } | |
| }catch(\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| /** | |
| * save payment gateway tokens | |
| * @param Array $payload | |
| */ | |
| public function savePaymentGatewayToken($payload,$exp = 600,$id=null) | |
| { | |
| $createdBy = $_SESSION['studentID']; | |
| require_once getenv('NUCLEUS_CONF'); // getting secret password | |
| try{ | |
| $token = array( | |
| "sub" => $payload, | |
| "exp" => time() + $exp | |
| ); | |
| $jwt = JWT::encode($token,$GLOBALS['GENERAL_SALT']); | |
| $id = $id ? $id : SecurityUtils::getRandomString(); | |
| $query = "INSERT INTO paymentGatewayTokens (id,jwt,created_by,created_date,updated_by,updated_date) VALUES ('$id','$jwt','$createdBy',UTC_TIMESTAMP(),'$createdBy',UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE jwt='$jwt',updated_by='$createdBy',updated_date=UTC_TIMESTAMP();"; | |
| $this->executeQuery($query); | |
| }catch(\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $id; | |
| } | |
| public function getPaymentGatewayToken($id) | |
| { | |
| if(empty($id)) | |
| { | |
| throw new ProfessionalException(ProfessionalException::INVALID_REQUEST,"ID is empty!Please provide a valid ID"); | |
| } | |
| require_once getenv('NUCLEUS_CONF'); // getting secret password | |
| $id = $this->realEscapeString($id); | |
| $query = "SELECT id,jwt FROM paymentGatewayTokens WHERE id='$id'"; | |
| try{ | |
| $paymentGatewayToken = $this->executeQueryForObject($query); | |
| $payload = JWT::decode($paymentGatewayToken->jwt,$GLOBALS['GENERAL_SALT'],array('HS256')); | |
| return (array) $payload->sub; | |
| }catch(\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| public function savePaymentGatewayUserToken(PaymentGatewayUserTokens $paymentGatewayUserTokens){ | |
| try{ | |
| $generatedTokenDetails = $this->getPaymentGatewayUserTokenByUser($paymentGatewayUserTokens); | |
| $id = SecurityUtils::getRandomString(); | |
| if(empty($generatedTokenDetails)) | |
| { | |
| $query = "INSERT INTO `payment_gateway_user_tokens` (`id`, `token`, `user_id`, `user_type`, `module`, `created_by`, `created_date`, `updated_by`, `updated_date`) VALUES ('$id', '$paymentGatewayUserTokens->token', '$paymentGatewayUserTokens->userId', '$paymentGatewayUserTokens->userType', '$paymentGatewayUserTokens->module', '$paymentGatewayUserTokens->createdBy', UTC_TIMESTAMP(), '$paymentGatewayUserTokens->updatedBy', UTC_TIMESTAMP())"; | |
| } | |
| else | |
| { | |
| $query = "UPDATE payment_gateway_user_tokens SET token='$paymentGatewayUserTokens->token' WHERE user_id='$paymentGatewayUserTokens->userId' AND user_type='$paymentGatewayUserTokens->userType' AND module='$paymentGatewayUserTokens->module'"; | |
| } | |
| $this->executeQuery($query); | |
| }catch(\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $id; | |
| } | |
| public function getPaymentGatewayUserToken(PaymentGatewayUserTokens $paymentGatewayUserTokens){ | |
| try{ | |
| $query = "SELECT id,token,user_id as userId, user_type as userType, module FROM payment_gateway_user_tokens WHERE token='$paymentGatewayUserTokens->token' AND user_id='$paymentGatewayUserTokens->userId' AND user_type='$paymentGatewayUserTokens->userType' AND module='$paymentGatewayUserTokens->module'"; | |
| return $this->executeQueryForObject($query); | |
| }catch(\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| private function getPaymentGatewayUserTokenByUser(PaymentGatewayUserTokens $paymentGatewayUserTokens){ | |
| try{ | |
| $query = "SELECT id,token,user_id as userId, user_type as userType, module FROM payment_gateway_user_tokens WHERE user_id='$paymentGatewayUserTokens->userId' AND user_type='$paymentGatewayUserTokens->userType' AND module='$paymentGatewayUserTokens->module'"; | |
| return $this->executeQueryForObject($query); | |
| }catch(\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| /** | |
| * Get settlement details | |
| * @param GetSettlementDetailsRequest $request | |
| * return $settlementDetails | |
| */ | |
| public function getSettlementDetails($request) | |
| { | |
| $settlementDetails = []; | |
| $request = $this->realEscapeObject($request); | |
| $paymentGateways = $this->getPaymentGatewayDetails($request->module,$request->category,$request->paymentGatewayId); | |
| foreach($paymentGateways as $paymentGateway) { | |
| $settlements = []; | |
| switch($paymentGateway->code) { | |
| case PaymentGateway::WORLD_LINE: | |
| $worldLineHelper = new WorldLineHelper(); | |
| $settlements = $worldLineHelper->executeGetSettlementDetailsBetweenTwoDates($request,$paymentGateway); | |
| break; | |
| case PaymentGateway::RAZORPAY: | |
| $razorPayHelper = new RazorPayHelper(); | |
| $settlements = $razorPayHelper->getSettlementDetails($request,$paymentGateway); | |
| break; | |
| case PaymentGateway::WORLDLINE_TECHPROCESS: | |
| break; | |
| } | |
| $settlementDetails = array_merge($settlementDetails,$settlements); | |
| } | |
| return $settlementDetails; | |
| } | |
| public function updatePaymentRequestSettlementDetailsByLinwaysTxnId($linwaysTxnId,$settlementDetails) | |
| { | |
| $linwaysTxnId = $this->realEscapeString($linwaysTxnId); | |
| $settlementDetails = $this->realEscapeObject($settlementDetails); | |
| $query = "UPDATE PaymentReqInfo SET settlement_details='".addslashes(json_encode($settlementDetails))."' WHERE linwaysTxnId='$linwaysTxnId'"; | |
| try{ | |
| $this->executeQuery($query); | |
| }catch(\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| } | |
| public function getPaymentGatewayModules(SearchPaymentGatewayModuleRequest $request) | |
| { | |
| $query = "SELECT pgm.id,pgm.paymentGatewayId,pgm.module,pgm.category,pgm.is_active AS isActive,pg.name,pg.code | |
| FROM | |
| PaymentGatewayModule pgm | |
| INNER JOIN PaymentGateway pg ON pg.id=pgm.paymentGatewayId WHERE 1=1"; | |
| if(!empty($request->module)) { | |
| $query .= " AND pgm.module='$request->module'"; | |
| } | |
| if(!empty($request->category)) { | |
| $query .= " AND pgm.category='$request->category'"; | |
| } | |
| if(!empty($request->paymentGatewayId)) { | |
| $query .= " AND pgm.paymentGatewayId='$request->paymentGatewayId'"; | |
| } | |
| if(!empty($request->id)) { | |
| $query .= " AND pgm.id='$request->id'"; | |
| } | |
| if($request->isActive == 1 || $request->isActive == 0) { | |
| $query .= " AND pgm.is_active='$request->isActive'"; | |
| } | |
| try{ | |
| $paymentGatewayList = $this->executeQueryForList($query); | |
| }catch(\Exception $e) { | |
| throw new ProfessionalException($e->getCode(),$e->getMessage()); | |
| } | |
| return $paymentGatewayList; | |
| } | |
| /** | |
| * Execute Jodo payment process | |
| * | |
| * @param ExecutePaymentRequest $exePaymentReq | |
| * @param PaymentGateway $paymentGateway | |
| * @throws \Exception:: | |
| */ | |
| public function executeJodo(ExecutePaymentRequest $exePaymentReq, PaymentGateway $paymentGateway) { | |
| try { | |
| if ($this->validatePaymentReq($exePaymentReq)) { | |
| $jodoPayHelper = new JodoHelper(); | |
| return $jodoPayHelper->executePayment($exePaymentReq, $paymentGateway); | |
| } | |
| } catch (\Exception $e) { | |
| throw $e; | |
| } | |
| } | |
| } | |