diff --git a/buy.php b/buy.php
index 19ec35b..a3ef8d4 100644
--- a/buy.php
+++ b/buy.php
@@ -6,42 +6,70 @@
this for production purposes. Merchants should build their own web pages based on their needs.
This demo is just a guide as to what the whole process will look like.
/*Developed by saqib 18-08-2009*/
+/*Updated by nikunjkotecha 04-12-2017*/
-->
-setAction(1);
- $Pipe->setCurrency(414);
- $Pipe->setLanguage("ENG"); //change it to "ARA" for arabic language
- $Pipe->setResponseURL("https://www.knetpaytest.com.kw/php/response.php"); // set your respone page URL
- $Pipe->setErrorURL("https://www.knetpaytest.com.kw/php/error.php"); //set your error page URL
- $Pipe->setAmt("10"); //set the amount for the transaction
- //$Pipe->setResourcePath("/Applications/MAMP/htdocs/php-toolkit/resource/");
- $Pipe->setResourcePath("D:\\php\\resource\\"); //change the path where your resource file is
- $Pipe->setAlias("alias"); //set your alias name here
- $Pipe->setTrackId("3434");//generate the random number here
-
- $Pipe->setUdf1("UDF 1"); //set User defined value
- $Pipe->setUdf2("UDF 2"); //set User defined value
- $Pipe->setUdf3("UDF 3"); //set User defined value
- $Pipe->setUdf4("UDF 4"); //set User defined value
- $Pipe->setUdf5("UDF 5"); //set User defined value
-
- //get results
- if($Pipe->performPaymentInitialization()!=$Pipe->SUCCESS){
- echo "Result=".$Pipe->SUCCESS;
- echo "
".$Pipe->getErrorMsg();
- echo "
".$Pipe->getDebugMsg();
- //header("location: https://www.yourURL.com/error.php");
- }else {
- $payID = $Pipe->getPaymentId();
- $payURL = $Pipe->getPaymentPage();
- echo $Pipe->getDebugMsg();
- //header("location:".$payURL."?PaymentID=".$payID);
- }
-?>
\ No newline at end of file
+
+require_once "com/aciworldwide/commerce/gateway/plugins/e24PaymentPipe.inc.php";
+$pipe = new e24PaymentPipe();
+
+$pipe->setAction(KNET_ACTION_PURCHASE);
+$pipe->setCurrency(KNET_CURRENCY_KWD);
+$pipe->setLanguage(KNET_LANGUAGE_EN);
+
+// Set your respone page URL. This needs to be available on internet.
+// If using HTTPS, it needs to be a valid SSL certificate communicated
+// to K-Net.
+$pipe->setResponseURL("https://www.knetpaytest.com.kw/php/response.php");
+
+// Set your error page URL.
+$pipe->setErrorURL("https://www.knetpaytest.com.kw/php/error.php");
+
+//$pipe->setResourcePath("/Applications/MAMP/htdocs/php-toolkit/resource/");
+$pipe->setResourcePath("D:\\php\\resource\\"); //change the path where your resource file is
+
+// Set your alias name here.
+$pipe->setAlias("alias");
+
+// Set the amount for the transaction.
+$pipe->setAmt("10");
+
+// Random / unique - internal tracking id.
+$pipe->setTrackId("3434");
+
+//set User defined values. This will be returned back in response url.
+$pipe->setUdf1("UDF 1");
+$pipe->setUdf2("UDF 2");
+$pipe->setUdf3("UDF 3");
+$pipe->setUdf4("UDF 4");
+$pipe->setUdf5("UDF 5");
+
+try {
+ $pipe->performPaymentInitialization();
+
+ // Check again once if there is any error.
+ if ($error = $pipe->getErrorMsg()) {
+ throw new \RuntimeException($error);
+ }
+
+ // Store payment id somewhere in the system to validate later.
+ $_SESSION['payment_id'] = $pipe->getPaymentId();
+
+ header("location:" . $pipe->getRedirectUrl());
+ exit;
+}
+catch (\Exception $e) {
+ // Log message somewhere.
+ error_log($e->getMessage());
+
+ // For demo we print here only.
+ echo "Result=" . $pipe->SUCCESS;
+ echo "
" . $pipe->getErrorMsg();
+ echo "
" . $pipe->getDebugMsg();
+ //header("location: https://www.yourURL.com/error.php");
+ exit;
+}
diff --git a/com/aciworldwide/commerce/gateway/plugins/e24PaymentPipe.inc.php b/com/aciworldwide/commerce/gateway/plugins/e24PaymentPipe.inc.php
index 274bdea..fafd7d7 100644
--- a/com/aciworldwide/commerce/gateway/plugins/e24PaymentPipe.inc.php
+++ b/com/aciworldwide/commerce/gateway/plugins/e24PaymentPipe.inc.php
@@ -1,689 +1,740 @@
";
- var $strPasswordOpen = "";
- var $strWebAddressOpen = "";
- var $strPortOpen = "";
- var $strContextOpen = "";
- var $strIDClose = "";
- var $strPasswordClose = "";
- var $strWebAddressClose = "";
- var $strPortClose = "";
- var $strContextClose = "";
- var $webAddress;
- var $port;
- var $id;
- var $password;
- var $passwordHash;
- var $action;
- var $transId;
- var $amt;
- var $responseURL;
- var $trackId;
- var $udf1;
- var $udf2;
- var $udf3;
- var $udf4;
- var $udf5;
- var $paymentPage;
- var $paymentId;
- var $result;
- var $auth;
- var $ref;
- var $avr;
- var $date;
- var $currency;
- var $errorURL;
- var $language;
- var $context;
- var $resourcePath;
- var $alias;
- var $error;
- var $rawResponse;
- var $debugMsg;
- var $arr = array();
-
- function e24PaymentPipe() {
- $this->webAddress = "";
- $this->port = "";
- $this->id = "";
- $this->password = "";
- $this->action = ""; // 1 = purchase
- $this->transId = "";
- $this->amt = "";
- $this->responseURL = "";
- $this->trackId = "";
- $this->udf1 = "";
- $this->udf2 = "";
- $this->udf3 = "";
- $this->udf4 = "";
- $this->udf5 = "";
- $this->paymentPage = "";
- $this->paymentId = "";
- $this->result = 0;
- $this->auth = "";
- $this->ref = "";
- $this->avr = "";
- $this->date = "";
- $this->currency = "";
- $this->errorURL = "";
- $this->language = "";
- $this->context = "";
- $this->resourcePath = "";
- $this->alias = "";
- $this->error = "";
- $this->rawResponse = "";
- $this->debugMsg = "";
- }
-
- function getWebAddress() {
- return webAddress;
- }
-
- function setWebAddress($s) {
- $this->webAddress = $s;
- }
-
- function getPort() {
- return $this->port;
- }
-
- function setPort($s) {
- $this->port = $s;
- }
-
- function set($k, $v) {
- $this->arr[$k] = $v;
- }
-
- function get($k) {
- return $this->arr[$k];
- }
-
- function setId($s) {
- $this->id = $s;
- }
-
- function getId() {
- return $this->id;
- }
-
- function setPassword($s) {
- $this->password = $s;
- }
-
- function setPasswordHash($s) {
- $this->passwordHash = $s;
- }
-
- function getPassword() {
- return $this->password;
- }
-
- function getPasswordHash() {
- return $this->passwordHash;
- }
-
- function setAction($s) {
- $this->action = $s;
- }
-
- function getAction() {
- return $this->action;
- }
-
- function setTransId($s) {
- $this->transId = $s;
- }
-
- function getTransId() {
- return $this->transId;
- }
-
- function setAmt($s) {
- $this->amt = $s;
- }
-
- function getAmt() {
- return $this->amt;
- }
-
- function setResponseURL($s) {
- $this->responseURL = $s;
- }
-
- function getResponseURL() {
- return $this->responseURL;
- }
-
- function setTrackId($s) {
- $this->trackId = $s;
- }
-
- function getTrackId() {
- return $this->trackId;
- }
-
- function setUdf1($s) {
- $this->udf1 = $s;
- }
-
- function getUdf1() {
- return $this->udf1;
- }
-
- function setUdf2($s) {
- $this->udf2 = $s;
- }
-
- function getUdf2() {
- return $this->udf2;
- }
-
- function setUdf3($s) {
- $this->udf3 = $s;
- }
-
- function getUdf3() {
- return $this->udf3;
- }
-
- function setUdf4($s) {
- $this->udf4 = $s;
- }
-
- function getUdf4() {
- return $this->udf4;
- }
-
- function setUdf5($s) {
- $this->udf5 = $s;
- }
-
- function getUdf5() {
- return $this->udf5;
- }
-
- function getPaymentPage() {
- return $this->paymentPage;
- }
+define('KNET_LANGUAGE_EN', 'ENG');
+define('KNET_LANGUAGE_AR', 'ARA');
- function getPaymentId() {
- return $this->paymentId;
- }
-
- function setPaymentId($s) {
- $this->paymentId = $s;
- }
-
- function setPaymentPage($s) {
- $this->paymentPage = $s;
- }
-
- function getRedirectContent() {
- return ($this->paymentPage . "&PaymentID=" . $this->paymentId);
- }
-
- function getResult() {
- return $this->result;
- }
-
- function getAuth() {
- return $this->auth;
- }
-
- function getAvr() {
- return $this->avr;
- }
-
- function getDate() {
- return $this->date;
- }
-
- function getRef() {
- return $this->ref;
- }
-
- function getCurrency() {
- return $this->currency;
- }
-
- function setCurrency($s) {
- $this->currency = $s;
- }
-
- function getLanguage() {
- return $this->language;
- }
-
- function setLanguage($s) {
- $this->language = $s;
- }
-
- function getErrorURL() {
- return $this->errorURL;
- }
+define('KNET_CURRENCY_KWD', 414);
- function setErrorURL($s) {
- $this->errorURL = $s;
- }
-
- function setContext($s) {
- $this->context = $s;
- }
-
- function getResourcePath() {
- return $this->resourcePath;
- }
-
- function setResourcePath($s) {
- $this->resourcePath = $s;
- }
-
- function getAlias() {
- return $this->alias;
- }
+define('KNET_ACTION_PURCHASE', 1);
- function setAlias($s) {
- $this->alias = $s;
- }
-
- function getErrorMsg() {
- return $this->error;
- }
-
- function getRawResponse() {
- return $this->rawResponse;
- }
-
- function getDebugMsg() {
- return $this->debugMsg;
- }
-
- function performPaymentInitialization() {
- $stringbuffer = "";
- if (!$this->getSecureSettings())
- return -1;
- if (strlen($this->id) > 0)
- $stringbuffer .= ("id=" . $this->id . "&");
- if (strlen($this->password) > 0)
- $stringbuffer .= ("password=" . $this->password . "&");
- if (strlen($this->passwordHash) > 0)
- $stringbuffer.=("passwordhash=" . $this->passwordHash . "&");
- if (strlen($this->amt) > 0)
- $stringbuffer.=("amt=" . $this->amt . "&");
- if (strlen($this->currency) > 0)
- $stringbuffer.=("currencycode=" . $this->currency . "&");
- if (strlen($this->action) > 0)
- $stringbuffer.=("action=" . $this->action . "&");
- if (strlen($this->language) > 0)
- $stringbuffer.=("langid=" . $this->language . "&");
- if (strlen($this->responseURL) > 0)
- $stringbuffer.=("responseURL=" . $this->responseURL . "&");
- if (strlen($this->errorURL) > 0)
- $stringbuffer.=("errorURL=" . $this->errorURL . "&");
- if (strlen($this->trackId) > 0)
- $stringbuffer.=("trackid=" . $this->trackId . "&");
- if (strlen($this->udf1) > 0)
- $stringbuffer.=("udf1=" . $this->udf1 . "&");
- if (strlen($this->udf2) > 0)
- $stringbuffer.=("udf2=" . $this->udf2 . "&");
- if (strlen($this->udf3) > 0)
- $stringbuffer.=("udf3=" . $this->udf3 . "&");
- if (strlen($this->udf4) > 0)
- $stringbuffer.=("udf4=" . $this->udf4 . "&");
- if (strlen($this->udf5) > 0)
- $stringbuffer.=("udf5=" . $this->udf5 . "&");
- $s = $this->sendMessage($stringbuffer, "PaymentInitHTTPServlet");
- if ($s == null)
- return -1;
- $i = strpos($s, ":");
- if ($i == -1) {
- $this->error = "Payment Initialization returned an invalid response: " . $s;
- return -1;
- } else {
- $this->paymentId = substr($s, 0, $i);
- $this->paymentPage = substr($s, $i + 1);
- return 0;
+/**
+ * Class e24PaymentPipe.
+ */
+class e24PaymentPipe {
+ protected $id = NULL;
+ protected $webAddress = NULL;
+ protected $port = NULL;
+ protected $password = NULL;
+ protected $passwordHash = NULL;
+ protected $context = NULL;
+
+ protected $responseUrl = '';
+ protected $errorURL = '';
+ protected $action = KNET_ACTION_PURCHASE;
+ protected $resourcePath = '';
+ protected $alias = '';
+ protected $currency = KNET_CURRENCY_KWD;
+ protected $language = KNET_LANGUAGE_AR;
+ protected $amt = NULL;
+
+ protected $trackId = NULL;
+ protected $udf1 = '';
+ protected $udf2 = '';
+ protected $udf3 = '';
+ protected $udf4 = '';
+ protected $udf5 = '';
+
+ protected $transId = NULL;
+ protected $paymentId = NULL;
+ protected $paymentPage = '';
+ protected $result = 0;
+ protected $auth = '';
+ protected $ref = '';
+ protected $avr = '';
+ protected $date = '';
+
+ protected $error = '';
+ protected $rawResponse = '';
+ protected $debugMsg = '';
+
+ protected $arr = [];
+
+ /**
+ * Constructs a new KnetPayment object.
+ */
+ public function __construct() {
+ // @TODO: Reduce setter function calls and move code to construct.
+ // For instance alias, URLs, etc. can be set here, which are required.
+ }
+
+ /**
+ * Function to set amount.
+ *
+ * @param string $s
+ * Amount.
+ */
+ public function setAmt($s) {
+ $this->amt = $s;
+ }
+
+ /**
+ * Function to set currency.
+ *
+ * @param int $s
+ * Currency code.
+ */
+ public function setCurrency($s) {
+ $this->currency = $s;
+ }
+
+ /**
+ * Function to set language.
+ *
+ * @param string $s
+ * Language code.
+ */
+ public function setLanguage($s) {
+ $this->language = $s;
+ }
+
+ /**
+ * Function to set response url.
+ *
+ * @param string $s
+ * Response URL.
+ */
+ public function setResponseUrl($s) {
+ $this->responseUrl = $s;
+ }
+
+ /**
+ * Function to set error url.
+ *
+ * @param string $s
+ * Error URL.
+ */
+ public function setErrorUrl($s) {
+ $this->errorURL = $s;
+ }
+
+ /**
+ * Function to set resource path.
+ *
+ * @param string $s
+ * Resource path.
+ */
+ public function setResourcePath($s) {
+ $this->resourcePath = $s;
+ }
+
+ /**
+ * Function to alias for xml.
+ *
+ * This is received as part of tooklit from K-Net.
+ *
+ * @param string $s
+ * Alias received from K-Net as string.
+ */
+ public function setAlias($s) {
+ $this->alias = $s;
+ }
+
+ /**
+ * Set tracking id.
+ *
+ * @param string $s
+ * Data.
+ */
+ public function setTrackId($s) {
+ $this->trackId = $s;
+ }
+
+ /**
+ * Set user defined data - 1.
+ *
+ * @param string $s
+ * Data.
+ */
+ public function setUdf1($s) {
+ $this->udf1 = $s;
+ }
+
+ /**
+ * Set user defined data - 2.
+ *
+ * @param string $s
+ * Data.
+ */
+ public function setUdf2($s) {
+ $this->udf2 = $s;
+ }
+
+ /**
+ * Set user defined data - 3.
+ *
+ * @param string $s
+ * Data.
+ */
+ public function setUdf3($s) {
+ $this->udf3 = $s;
+ }
+
+ /**
+ * Set user defined data - 4.
+ *
+ * @param string $s
+ * Data.
+ */
+ public function setUdf4($s) {
+ $this->udf4 = $s;
+ }
+
+ /**
+ * Set user defined data - 5.
+ *
+ * @param string $s
+ * Data.
+ */
+ public function setUdf5($s) {
+ $this->udf5 = $s;
+ }
+
+ /**
+ * Function to get payment id.
+ *
+ * @return string
+ * Payment id.
+ */
+ public function getPaymentId() {
+ return $this->paymentId;
+ }
+
+ /**
+ * Function to get redirect url.
+ *
+ * @return string
+ * Redirect URL.
+ */
+ public function getRedirectUrl() {
+ return ($this->paymentPage . '&PaymentID=' . $this->paymentId);
+ }
+
+ /**
+ * Function to get error message.
+ *
+ * @return string
+ * Error message.
+ */
+ public function getErrorMsg() {
+ return $this->error;
+ }
+
+ /**
+ * Function to get raw response.
+ *
+ * @return string
+ * Raw response.
+ */
+ public function getRawResponse() {
+ return $this->rawResponse;
+ }
+
+ /**
+ * Function to get debug message.
+ *
+ * @return string
+ * Debug message.
+ */
+ public function getDebugMsg() {
+ return $this->debugMsg;
+ }
+
+ /**
+ * Helper function to do payment initialization.
+ */
+ public function performPaymentInitialization() {
+ $stringbuffer = '';
+ if (!$this->getSecureSettings()) {
+ return -1;
+ }
+ if (strlen($this->id) > 0) {
+ $stringbuffer .= ('id=' . $this->id . '&');
+ }
+ if (strlen($this->password) > 0) {
+ $stringbuffer .= ('password=' . $this->password . '&');
+ }
+ if (strlen($this->passwordHash) > 0) {
+ $stringbuffer .= ('passwordhash=' . $this->passwordHash . '&');
+ }
+ if (strlen($this->amt) > 0) {
+ $stringbuffer .= ('amt=' . $this->amt . '&');
+ }
+ if (strlen($this->currency) > 0) {
+ $stringbuffer .= ('currencycode=' . $this->currency . '&');
+ }
+ if (strlen($this->action) > 0) {
+ $stringbuffer .= ('action=' . $this->action . '&');
+ }
+ if (strlen($this->language) > 0) {
+ $stringbuffer .= ('langid=' . $this->language . '&');
+ }
+ if (strlen($this->responseUrl) > 0) {
+ $stringbuffer .= ('responseUrl=' . $this->responseUrl . '&');
+ }
+ if (strlen($this->errorURL) > 0) {
+ $stringbuffer .= ('errorURL=' . $this->errorURL . '&');
+ }
+ if (strlen($this->trackId) > 0) {
+ $stringbuffer .= ('trackid=' . $this->trackId . '&');
+ }
+ if (strlen($this->udf1) > 0) {
+ $stringbuffer .= ('udf1=' . $this->udf1 . '&');
+ }
+ if (strlen($this->udf2) > 0) {
+ $stringbuffer .= ('udf2=' . $this->udf2 . '&');
+ }
+ if (strlen($this->udf3) > 0) {
+ $stringbuffer .= ('udf3=' . $this->udf3 . '&');
+ }
+ if (strlen($this->udf4) > 0) {
+ $stringbuffer .= ('udf4=' . $this->udf4 . '&');
+ }
+ if (strlen($this->udf5) > 0) {
+ $stringbuffer .= ('udf5=' . $this->udf5 . '&');
+ }
+ $s = $this->sendMessage($stringbuffer, 'PaymentInitHTTPServlet');
+ if ($s == NULL) {
+ return -1;
+ }
+ $i = strpos($s, ':');
+ if ($i === FALSE) {
+ throw new \RuntimeException('Payment Initialization returned an invalid response: ' . $s);
+ }
+ else {
+ $this->paymentId = substr($s, 0, $i);
+ $this->paymentPage = substr($s, $i + 1);
+ return TRUE;
+ }
+ }
+
+ /**
+ * Helper function to perform the transaction.
+ */
+ protected function performTransaction() {
+ $stringbuffer = '';
+ if (!$this->getSecureSettings()) {
+ return -1;
+ }
+ if (strlen($this->id) > 0) {
+ $stringbuffer .= ('id=' . $this->id . '&');
+ }
+ if (strlen($this->password) > 0) {
+ $stringbuffer .= ('password=' . $this->password . '&');
+ }
+ if (strlen($this->passwordHash) > 0) {
+ $stringbuffer .= ('passwordhash=' . $this->passwordHash . '&');
+ }
+ if (strlen($this->currency) > 0) {
+ $stringbuffer .= ('currencycode=' . $this->currency . '&');
+ }
+ if (strlen($this->amt) > 0) {
+ $stringbuffer .= ('amt=' . $this->amt . '&');
+ }
+ if (strlen($this->action) > 0) {
+ $stringbuffer .= ('action=' . $this->action . '&');
+ }
+ if (strlen($this->paymentId) > 0) {
+ $stringbuffer .= ('paymentid=' . $this->paymentId . '&');
+ }
+ if (strlen($this->transId) > 0) {
+ $stringbuffer .= ('transid=' . $this->transId . '&');
+ }
+ if (strlen($this->trackId) > 0) {
+ $stringbuffer .= ('trackid=' . $this->trackId . '&');
+ }
+ if (strlen($this->udf1) > 0) {
+ $stringbuffer .= ('udf1=' . $this->udf1 . '&');
+ }
+ if (strlen($this->udf2) > 0) {
+ $stringbuffer .= ('udf2=' . $this->udf2 . '&');
+ }
+ if (strlen($this->udf3) > 0) {
+ $stringbuffer .= ('udf3=' . $this->udf3 . '&');
+ }
+ if (strlen($this->udf4) > 0) {
+ $stringbuffer .= ('udf4=' . $this->udf4 . '&');
+ }
+ if (strlen($this->udf5) > 0) {
+ $stringbuffer .= ('udf5=' . $this->udf5 . '&');
+ }
+
+ if (is_array($this->arr) && count($this->arr)) {
+ foreach ($this->arr as $key => $var) {
+ $stringbuffer .= ($key . '=' . $var . '&');
+ }
+ }
+ $stringbuffer = substr($stringbuffer, 0, strlen($stringbuffer) - 1);
+ echo $stringbuffer;
+ $s = $this->sendMessage($stringbuffer, 'PaymentTranHTTPServlet');
+ if ($s == NULL) {
+ return -1;
+ }
+
+ $arraylist = $this->parseResults($s);
+ if ($arraylist == NULL) {
+ return -1;
+ }
+ else {
+ $this->result = $arraylist[0];
+ $this->auth = $arraylist[1];
+ $this->ref = $arraylist[2];
+ $this->avr = $arraylist[3];
+ $this->date = $arraylist[4];
+ $this->transId = $arraylist[5];
+ $this->trackId = $arraylist[6];
+ $this->udf1 = $arraylist[7];
+ $this->udf2 = $arraylist[8];
+ $this->udf3 = $arraylist[9];
+ $this->udf4 = $arraylist[10];
+ $this->udf5 = $arraylist[11];
+ return 0;
+ }
+ }
+
+ /**
+ * Send message to K-Net server and get URL to redirect.
+ *
+ * @param string $s
+ * Data to send.
+ * @param string $s1
+ * Function to call.
+ *
+ * @return mixed|null|string
+ * Message.
+ */
+ protected function sendMessage($s, $s1) {
+ $stringbuffer = '';
+ $error = '';
+ $this->debugMsg .= ('
---------- ' . $s1 . ': ' . time() . ' ----------
');
+ if ($this->port == '443') {
+ if (strlen($this->webAddress) <= 0) {
+ $error = 'No URL specified.';
+ return NULL;
+ }
+ if ($this->port == '443') {
+ $stringbuffer .= ('https://');
+ }
+ else {
+ $stringbuffer .= ('http://');
+ }
+ $stringbuffer .= ($this->webAddress);
+ if (strlen($this->port) > 0) {
+ $stringbuffer .= (':');
+ $stringbuffer .= ($this->port);
+ }
+ if (strlen($this->context) > 0) {
+ if (!$this->startsWith($this->context, '/')) {
+ $stringbuffer .= ('/');
}
- }
-
- function performTransaction() {
- $stringbuffer = "";
- if (!$this->getSecureSettings())
- return -1;
- if (strlen($this->id) > 0)
- $stringbuffer.=("id=" . $this->id . "&");
- if (strlen($this->password) > 0)
- $stringbuffer.=("password=" . $this->password . "&");
- if (strlen($this->passwordHash) > 0)
- $stringbuffer.=("passwordhash=" . $this->passwordHash . "&");
- if (strlen($this->currency) > 0)
- $stringbuffer.=("currencycode=" . $this->currency . "&");
- if (strlen($this->amt) > 0)
- $stringbuffer.=("amt=" . $this->amt . "&");
- if (strlen($this->action) > 0)
- $stringbuffer.=("action=" . $this->action . "&");
- if (strlen($this->paymentId) > 0)
- $stringbuffer.=("paymentid=" . $this->paymentId . "&");
- if (strlen($this->transId) > 0)
- $stringbuffer.=("transid=" . $this->transId . "&");
- if (strlen($this->trackId) > 0)
- $stringbuffer.=("trackid=" . $this->trackId . "&");
- if (strlen($this->udf1) > 0)
- $stringbuffer.=("udf1=" . $this->udf1 . "&");
- if (strlen($this->udf2) > 0)
- $stringbuffer.=("udf2=" . $this->udf2 . "&");
- if (strlen($this->udf3) > 0)
- $stringbuffer.=("udf3=" . $this->udf3 . "&");
- if (strlen($this->udf4) > 0)
- $stringbuffer.=("udf4=" . $this->udf4 . "&");
- if (strlen($this->udf5) > 0)
- $stringbuffer.=("udf5=" . $this->udf5 . "&");
-
- if (is_array($this->arr) && count($this->arr)) {
- foreach ($this->arr as $key => $var) {
- $stringbuffer .= ($key . "=" . $var . "&");
- }
+ $stringbuffer .= ($this->context);
+ if (!$this->endsWith($this->context, '/')) {
+ $stringbuffer .= ('/');
}
- $stringbuffer = substr($stringbuffer, 0, strlen($stringbuffer) - 1);
- echo $stringbuffer;
- $s = $this->sendMessage($stringbuffer, "PaymentTranHTTPServlet");
- if ($s == null)
- return -1;
-
- $arraylist = $this->parseResults($s);
- if ($arraylist == null) {
- return -1;
- } else {
- $this->result = $arraylist[0];
- $this->auth = $arraylist[1];
- $this->ref = $arraylist[2];
- $this->avr = $arraylist[3];
- $this->date = $arraylist[4];
- $this->transId = $arraylist[5];
- $this->trackId = $arraylist[6];
- $this->udf1 = $arraylist[7];
- $this->udf2 = $arraylist[8];
- $this->udf3 = $arraylist[9];
- $this->udf4 = $arraylist[10];
- $this->udf5 = $arraylist[11];
- return 0;
+ }
+ else {
+ $stringbuffer .= ('/');
+ }
+ $stringbuffer .= ('servlet/');
+ $stringbuffer .= ($s1);
+ $this->debugMsg .= ('
About to create the URL to: ' . $stringbuffer);
+ $url = $stringbuffer;
+
+ $this->debugMsg .= ('
About to create http connection....');
+
+ $this->debugMsg .= ('
Created connection.!!');
+ if (strlen($s) > 0) {
+ $c = curl_init();
+ curl_setopt($c, CURLOPT_HEADER, 0);
+ curl_setopt($c, CURLOPT_URL, $stringbuffer);
+ curl_setopt($c, CURLOPT_POST, TRUE);
+ curl_setopt($c, CURLOPT_POSTFIELDS, $s);
+ curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
+ curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
+ $this->debugMsg .= ('
about to write DataOutputSteam....');
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, CURLOPT_RETURNTRANSFER);
+ $this->debugMsg .= ('
after DataOutputStream.!!');
+ $tmp = curl_exec($c);
+ if (curl_error($c)) {
+ echo 'CURL ERROR: ' . curl_errno($c) . '::' . curl_error($c);
}
- }
+ elseif ($tmp) {
- function sendMessage($s, $s1) {
- $stringbuffer = "";
- $error = "";
- $this->debugMsg .= ("
---------- " . $s1 . ": " . time() . " ----------
");
- if ($this->port == "443") {
- if (strlen($this->webAddress) <= 0) {
- $error = "No URL specified.";
- return null;
- }
- if ($this->port == "443")
- $stringbuffer.=("https://");
- else
- $stringbuffer.=("http://");
- $stringbuffer.=($this->webAddress);
- if (strlen($this->port) > 0) {
- $stringbuffer.=(":");
- $stringbuffer.=($this->port);
- }
- if (strlen($this->context) > 0) {
- if (!$this->StartsWith($this->context, "/"))
- $stringbuffer.=("/");
- $stringbuffer.=($this->context);
- if (!$this->EndsWith($this->context, "/"))
- $stringbuffer.=("/");
- } else {
- $stringbuffer.=("/");
- }
- $stringbuffer.=("servlet/");
- $stringbuffer.=($s1);
- $this->debugMsg.=("
About to create the URL to: " . $stringbuffer);
- $url = $stringbuffer;
- //echo '
'. $stringbuffer . '
';
- $this->debugMsg.=("
About to create http connection....");
-
- $this->debugMsg.=("
Created connection.!!");
- if (strlen($s) > 0) {
- $c = curl_init();
- curl_setopt($c, CURLOPT_HEADER, 0);
- curl_setopt($c, CURLOPT_URL, $stringbuffer);
- curl_setopt($c, CURLOPT_POST, true);
- curl_setopt($c, CURLOPT_POSTFIELDS, $s);
- curl_setopt($c, CURLOPT_SSL_VERIFYHOST, true);
- curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
- $this->debugMsg.=("
about to write DataOutputSteam....");
- curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
- $this->debugMsg.=("
after DataOutputStream.!!");
- $tmp = curl_exec($c);
- if (curl_error($c)) {
- echo 'CURL ERROR: ' . curl_errno($c) . '::' . curl_error($c);
- } elseif ($tmp) {
-
- curl_close($c);
- $this->rawResponse = $tmp;
- $this->debugMsg.=("
Received RESPONSE: " . $this->rawResponse);
- return $this->rawResponse;
- } else {
- $error = "No Data To Post!";
- }
- } else {
- $this->clearFields();
- $this->error = "Failed to make connection:\n" . $error; //. $exception;
- return null;
- }
+ curl_close($c);
+ $this->rawResponse = $tmp;
+ $this->debugMsg .= ('
Received RESPONSE: ' . $this->rawResponse);
+ return $this->rawResponse;
}
- }
-
- function parseResults($s) {
-
- $arraylist = array(); {
- if ($this->StartsWith($s, "!ERROR!")) {
- $this->error = $s;
- return null;
- }
-
- $tokens = strtok($s, ":\r\n");
- print_r($tokens);
- $s1;
- $flag = false;
- foreach ($tokens as $token) {
- $s2 = $token;
- if (!$s2 . $this->startsWith(":")) {
- $arraylist[] = ($s2);
- $flag = false;
- } else {
- if ($flag)
- $arraylist[] = ("");
- $flag = true;
- }
- }
- return $arraylist;
+ else {
+ $error = 'No Data To Post!';
}
-
- $this->error = "Internal Error!";
- return null;
+ }
+ else {
+ $this->clearFields();
+ throw new \RuntimeException('Failed to make connection: ' . $error);
+ }
+ }
+ }
+
+ /**
+ * Helper function to parse the results.
+ */
+ protected function parseResults($s) {
+
+ $arraylist = [];
+
+ if ($this->startsWith($s, '!ERROR!')) {
+ $this->error = $s;
+ return NULL;
+ }
+
+ $tokens = strtok($s, ":\r\n");
+
+ $flag = FALSE;
+ foreach ($tokens as $token) {
+ $s2 = $token;
+ if (!$s2 . $this->startsWith(':')) {
+ $arraylist[] = ($s2);
+ $flag = FALSE;
+ }
+ else {
+ if ($flag) {
+ $arraylist[] = ('');
+ }
+ $flag = TRUE;
+ }
}
+ return $arraylist;
+ }
- function clearFields() {
- $this->error = "";
- $this->paymentPage = "";
- $this->paymentId = "";
- }
+ /**
+ * Helper function to reset data.
+ */
+ public function clearFields() {
+ $this->error = '';
+ $this->paymentPage = '';
+ $this->paymentId = '';
+ }
- function getSecureSettings() {
- $s = "";
- if (!$this->createReadableZip())
- return false;
- $s = $this->readZip();
- if ($s == "")
- return false;
+ /**
+ * Helper function to get secure settings from zip and set into members.
+ */
+ protected function getSecureSettings() {
+ $s = '';
- unlink($this->getResourcePath() . "resource.cgz");
- return $this->parseSettings($s);
+ // Try to read the contents of zip if already exists.
+ try {
+ $s = $this->readZip();
}
+ catch (\Exception $e) {
+ // Zip file seems not available, try to create it and read again.
+ if (!$this->createReadableZip()) {
+ throw new \RuntimeException('Cannot create readable zip file.');
+ }
- function createReadableZip() { {
-
- $filenameInput = $this->getResourcePath() . "resource.cgn";
- $handleInput = fopen($filenameInput, "r");
- $contentsInput = fread($handleInput, filesize($filenameInput));
-
- $filenameOutput = $this->getResourcePath() . "resource.cgz";
- @unlink($filenameOutput);
- $handleOutput = fopen($filenameOutput, "w");
-
- $inByteArray = $this->getBytes($contentsInput);
- $outByteArray = $this->simpleXOR($inByteArray);
-
- fwrite($handleOutput, $this->getString($outByteArray));
- fclose($handleInput);
- fclose($handleOutput);
- }
+ $s = $this->readZip();
+ }
- return true;
+ if ($s == '') {
+ throw new \RuntimeException('Cannot read data from zip file.');
}
- function readZip() {
+ return $this->parseSettings($s);
+ }
- $s = ""; {
+ /**
+ * Helper function to create readable zip.
+ */
+ protected function createReadableZip() {
+ $filenameInput = $this->resourcePath . 'resource.cgn';
+ $handleInput = fopen($filenameInput, 'r');
+ $contentsInput = fread($handleInput, filesize($filenameInput));
- $filenameInput = $this->getResourcePath() . "resource.cgz";
+ $filenameOutput = $this->resourcePath . 'resource.cgz';
- $zipentry;
- $i = 0;
+ // Unlink the file if exists before re-creating it.
+ @unlink($filenameOutput);
- $zip = new ZipArchive;
- if ($zip->open($filenameInput) === TRUE) {
- $zip->extractTo($this->resourcePath);
- $zip->close();
- } else {
- echo 'failed';
- $this->error = "Failed to unzip file";
- }
+ $handleOutput = fopen($filenameOutput, 'w');
+
+ $inByteArray = $this->getBytes($contentsInput);
+ $outByteArray = $this->simplexor($inByteArray);
- if (strlen($this->error) === 0) {
- $xmlNameInput = $this->resourcePath . $this->getAlias() . ".xml";
- $xmlHandleInput = fopen($xmlNameInput, "r");
- $xmlContentsInput = fread($xmlHandleInput, filesize($xmlNameInput));
- fclose($xmlHandleInput);
- unlink($xmlNameInput);
- $s = $xmlContentsInput;
+ fwrite($handleOutput, $this->getString($outByteArray));
+ fclose($handleInput);
+ fclose($handleOutput);
+
+ return TRUE;
+ }
+
+ /**
+ * Helper function to read data from zip.
+ *
+ * @return string
+ * Data from Zip.
+ */
+ protected function readZip() {
+ $s = '';
+
+ $filenameInput = $this->resourcePath . 'resource.cgz';
+
+ $i = 0;
+
+ $zip = new \ZipArchive();
+ if ($zip->open($filenameInput) === TRUE) {
+ $zip->extractTo($this->resourcePath);
+ $zip->close();
+ }
+ else {
+ throw new \RuntimeException('Failed to unzip file');
+ }
+
+ if (strlen($this->error) === 0) {
+ $xmlNameInput = $this->resourcePath . $this->alias . '.xml';
+ $xmlHandleInput = fopen($xmlNameInput, 'r');
+ $xmlContentsInput = fread($xmlHandleInput, filesize($xmlNameInput));
+ fclose($xmlHandleInput);
+
+ $s = $xmlContentsInput;
+
+ $s = $this->getString($this->simplexor($this->getBytes($s)));
+ }
+ else {
+ throw new \RuntimeException('Unable to open resource');
+ }
+
+ return $s;
+ }
+
+ /**
+ * Helper function to parse settings.
+ *
+ * @param string $s
+ * Settings as string.
+ *
+ * @return bool
+ * True if all settings parsed and set into respective members.
+ */
+ private function parseSettings($s) {
+ $i = 0;
+ $j = 0;
+ $i = strpos($s, '') + strlen('');
+ $j = strpos($s, '');
- $s = $this->getString($this->simpleXOR($this->getBytes($s)));
- } else {
- $this->error = "Unable to open resource";
- }
- return $s;
- }
- }
+ $this->id = substr($s, $i, $j - $i);
- function parseSettings($s) {
- $i = 0;
- $j = 0;
- $i = strpos($s, "") + strlen("");
- $j = strpos($s, "");
-
- $this->setId(substr($s, $i, $j - $i));
- $i = strpos($s, "") + strlen("");
- $j = strpos($s, "");
- $this->setPassword(substr($s, $i, $j - $i));
-
- $i = strpos($s, "") + strlen("");
- $j = strpos($s, "");
- $this->setPasswordHash(substr($s, $i, $j - $i));
-
- $i = strpos($s, "") + strlen("");
- $j = strpos($s, "");
- $this->setWebAddress(substr($s, $i, $j - $i));
- $i = strpos($s, "") + strlen("");
- $j = strpos($s, "");
- $this->setPort(substr($s, $i, $j - $i));
- $i = strpos($s, "") + strlen("");
- $j = strpos($s, "");
- $this->setContext(substr($s, $i, $j - $i));
- return true;
- }
-
- function simpleXOR($abyte0) {
- $key = "Those who profess to favour freedom and yet depreciate agitation are men who want rain without thunder and lightning";
- $abyte1 = $this->getBytes($key);
-
- for ($i = 0; $i < sizeof($abyte0);) {
- for ($j = 0; $j < sizeof($abyte1); $j++) {
- $abyte2[$i] = ($abyte0[$i] ^ $abyte1[$j]);
- if (++$i == sizeof($abyte0))
- break;
- }
- }
+ $i = strpos($s, '') + strlen('');
+ $j = strpos($s, '');
+ $this->password = substr($s, $i, $j - $i);
- return $abyte2;
- }
+ $i = strpos($s, '') + strlen('');
+ $j = strpos($s, '');
+ $this->passwordHash = substr($s, $i, $j - $i);
- function getBytes($s) {
- $hex_ary = array();
- $size = strlen($s);
- for ($i = 0; $i < $size; $i++)
- $hex_ary[] = chr(ord($s[$i]));
- return $hex_ary;
- }
+ $i = strpos($s, '') + strlen('');
+ $j = strpos($s, '');
+ $this->webAddress = substr($s, $i, $j - $i);
- function getString($byteArray) {
- $s = "";
- foreach ($byteArray as $byte) {
- $s .=$byte;
+ $i = strpos($s, '') + strlen('');
+ $j = strpos($s, '');
+ $this->port = substr($s, $i, $j - $i);
+
+ $i = strpos($s, '') + strlen('');
+ $j = strpos($s, '');
+ $this->context = substr($s, $i, $j - $i);
+
+ return TRUE;
+ }
+
+ /**
+ * Helper function simplexor.
+ *
+ * @param mixed $abyte0
+ * Data abyte0.
+ *
+ * @return mixed
+ * Processed output.
+ */
+ protected function simplexor($abyte0) {
+ $key = 'Those who profess to favour freedom and yet depreciate agitation are men who want rain without thunder and lightning';
+ $abyte1 = $this->getBytes($key);
+
+ for ($i = 0; $i < count($abyte0);) {
+ for ($j = 0; $j < count($abyte1); $j++) {
+ $abyte2[$i] = ($abyte0[$i] ^ $abyte1[$j]);
+ if (++$i == count($abyte0)) {
+ break;
}
- return $s;
- }
-
- function StartsWith($Haystack, $Needle) {
- // Recommended version, using strpos
- return strpos($Haystack, $Needle) === 0;
- }
-
- function EndsWith($Haystack, $Needle) {
- // Recommended version, using strpos
- return strrpos($Haystack, $Needle) === strlen($Haystack) - strlen($Needle);
- }
-
-}
+ }
+ }
+
+ return $abyte2;
+ }
+
+ /**
+ * Helper function to get bytes array from string.
+ *
+ * @param string $s
+ * String to convert into bytes array..
+ *
+ * @return array
+ * Array of bytes from string.
+ */
+ protected function getBytes($s) {
+ $hex_ary = [];
+ $size = strlen($s);
+ for ($i = 0; $i < $size; $i++) {
+ $hex_ary[] = chr(ord($s[$i]));
+ }
+ return $hex_ary;
+ }
+
+ /**
+ * Helper function to get string from bytes array.
+ *
+ * @param array $byteArray
+ * Array containing bytes.
+ *
+ * @return string
+ * String from the bytes array.
+ */
+ protected function getString(array $byteArray) {
+ $s = '';
+ foreach ($byteArray as $byte) {
+ $s .= $byte;
+ }
+ return $s;
+ }
+
+ /**
+ * Helper function startsWith.
+ *
+ * @param string $haystack
+ * Hay stack - full string.
+ * @param string $needle
+ * Needle - to search.
+ *
+ * @return bool
+ * True or false.
+ */
+ protected function startsWith($haystack, $needle) {
+ // Recommended version, using strpos.
+ return strpos($haystack, $needle) === 0;
+ }
+
+ /**
+ * Helper function endsWith.
+ *
+ * @param string $haystack
+ * Hay stack - full string.
+ * @param string $needle
+ * Needle - to search.
+ *
+ * @return bool
+ * True or false.
+ */
+ protected function endsWith($haystack, $needle) {
+ // Recommended version, using strpos.
+ return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle);
+ }
-function xor_string($string) {
- $buf = '';
- $size = strlen($string);
- for ($i = 0; $i < $size; $i++)
- $buf .= chr(ord($string[$i]) ^ 255);
- return $buf;
}
-?>
\ No newline at end of file