diff --git a/.github/workflows/github-ci.yml b/.github/workflows/github-ci.yml new file mode 100644 index 0000000..569eeb8 --- /dev/null +++ b/.github/workflows/github-ci.yml @@ -0,0 +1,53 @@ +name: PHP Composer + +on: + push: + branches: [ "main", "master" ] + pull_request: + branches: [ "main", "master" ] + +permissions: + contents: read + +jobs: + + phpstan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: php-actions/composer@v6 + with: + args: --ignore-platform-reqs + - name: Running Phpstan + run: composer run-script analyze + + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-versions: ['8.1', '8.2', '8.3', '8.4', '8.5'] + steps: + - uses: actions/checkout@v4 + - name: Validate composer.json and composer.lock + run: composer validate --strict + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + - name: Install dependencies + run: composer install --prefer-dist --no-progress + - name: Run test suite + run: composer run-script test + continue-on-error: true + - name: Test Report + uses: dorny/test-reporter@ff2d13cc3645b6e6978bb229ca7a2a5ea91208c1 + if: ${{ !cancelled() }} + with: + name: PHPUnit tests + path: reports/junit.xml + reporter: phpunit-junit \ No newline at end of file diff --git a/README.md b/README.md index 23b3f92..17af764 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ -# OTP Simplepay SDK +# OTP SimplePay SDK ![](https://simplepay.hu/wp-content/uploads/2019/09/simpleLogo-e1569844953356.png) -Version: 2.1.0 +Version: 2.5.0 Support V1 & V2 API versions You can find more info: https://www.simplepay.hu/fejlesztoknek - diff --git a/composer.json b/composer.json index 29deaf2..075aab4 100644 --- a/composer.json +++ b/composer.json @@ -1,30 +1,31 @@ { - "name": "iconocoders/otp-simple-sdk", + "name": "ttimot24/otp-simple-sdk", "description": "OTP Simple Payment SDK", "keywords": [ "otp simple", - "iconocoders", "online payment", "payment" ], "authors": [ { - "name": "Iconocoders", - "email": "support@icoders.co" + "name": "Timot Tarjani", + "email": "timot.tarjani@outlook.com" } ], "minimum-stability": "dev", - "require": { - "php": "~7.2.0|~7.3.0|~7.4.0" + "require": { + "php": "~8.1.0|~8.2.0|~8.3.0|~8.4.0||~8.5.0" }, "type": "library", - "version": "2.1.0", "license": [ - "Apache-2.0" + "Apache-2.0" ], "autoload": { + "classmap": [ + "src/" + ], "psr-4": { - "Source\\": "Source/" + "SimplePay\\": "src/" } } } diff --git a/Source/V1/SimpleBackRef.php b/src/V1/SimpleBackRef.php similarity index 100% rename from Source/V1/SimpleBackRef.php rename to src/V1/SimpleBackRef.php diff --git a/Source/V1/SimpleBase.php b/src/V1/SimpleBase.php similarity index 100% rename from Source/V1/SimpleBase.php rename to src/V1/SimpleBase.php diff --git a/Source/V1/SimpleIdn.php b/src/V1/SimpleIdn.php similarity index 100% rename from Source/V1/SimpleIdn.php rename to src/V1/SimpleIdn.php diff --git a/Source/V1/SimpleIos.php b/src/V1/SimpleIos.php similarity index 100% rename from Source/V1/SimpleIos.php rename to src/V1/SimpleIos.php diff --git a/Source/V1/SimpleIpn.php b/src/V1/SimpleIpn.php similarity index 100% rename from Source/V1/SimpleIpn.php rename to src/V1/SimpleIpn.php diff --git a/Source/V1/SimpleIrn.php b/src/V1/SimpleIrn.php similarity index 100% rename from Source/V1/SimpleIrn.php rename to src/V1/SimpleIrn.php diff --git a/Source/V1/SimpleLiveUpdate.php b/src/V1/SimpleLiveUpdate.php similarity index 100% rename from Source/V1/SimpleLiveUpdate.php rename to src/V1/SimpleLiveUpdate.php diff --git a/Source/V1/SimpleTransaction.php b/src/V1/SimpleTransaction.php similarity index 100% rename from Source/V1/SimpleTransaction.php rename to src/V1/SimpleTransaction.php diff --git a/Source/V2/SimplePay.php b/src/V2/SimplePay.php similarity index 77% rename from Source/V2/SimplePay.php rename to src/V2/SimplePay.php index 4eaba36..bc6391d 100644 --- a/Source/V2/SimplePay.php +++ b/src/V2/SimplePay.php @@ -1,9 +1,11 @@ - * @copyright 2020 OTP Mobil Kft. + * @author SimplePay IT Support + * @copyright 2025 SimplePay Zrt. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ @@ -32,7 +34,7 @@ * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ @@ -46,25 +48,31 @@ class Base public $config = []; protected $headers = []; protected $hashAlgo = 'sha384'; - public $sdkVersion = 'SimplePay_PHP_SDK_2.1.0_200825'; - protected $logSeparator = '|'; - protected $logContent = []; - protected $debugMessage = []; - protected $currentInterface = ''; + public $sdkVersion = 'SimplePay_PHP_SDK_2.1.5_250731'; + protected $transactionBase = []; protected $api = [ 'sandbox' => 'https://sandbox.simplepay.hu/payment', 'live' => 'https://secure.simplepay.hu/payment' ]; protected $apiInterface = [ 'start' => '/v2/start', + 'starteam' => '/v2/starteam', 'finish' => '/v2/finish', 'refund' => '/v2/refund', 'query' => '/v2/query', + 'transactioncancel' => '/v2/transactionCancel', + 'startapplepay' => '/v2/startapplepay', + 'doapplepay' => '/v2/doapplepay', ]; + protected $currentInterface = ''; public $logTransactionId = 'N/A'; public $logOrderRef = 'N/A'; public $logPath = ''; - protected $phpVersion = 7; + protected $logSeparator = '|'; + protected $logContent = []; + public $returnData; + protected $phpVersion = 8; + protected $content; /** * Constructor @@ -77,8 +85,8 @@ public function __construct() $ver = (float)phpversion(); $this->logContent['phpVersion'] = $ver; if (is_numeric($ver)) { - if ($ver < 7.0) { - $this->phpVersion = 5; + if ($ver < $this->phpVersion) { + $this->phpVersion = $ver; } } } @@ -213,30 +221,35 @@ public function getLogContent() */ public function checkOrSetToJson($data = '') { + $json = '[]'; //empty if ($data === '') { $json = json_encode([]); + return $json; } //array if (is_array($data)) { $json = json_encode($data); + return $json; } //object if (is_object($data)) { $json = json_encode($data); + return $json; } //json - $result = @json_decode($data); + $result = json_decode($data); if ($result !== null) { $json = $data; + return $json; } //serialized - $result = @unserialize($data); + $result = unserialize($data); if ($result !== false) { $json = json_encode($result); + return $json; } - return $json; } /** @@ -254,6 +267,9 @@ protected function getHeaders($hash = '', $language = 'en') 'Content-type: application/json', 'Signature: ' . $hash, ]; + if (isset($this->config['SERVER_DATA']) && isset($this->config['SERVER_DATA']['HTTP_REFERER'])) { + $headers[] = 'Referer: ' . $this->config['SERVER_DATA']['HTTP_REFERER']; + } return $headers; } @@ -341,10 +357,21 @@ protected function getFlatArray($arrayForProcess = []) */ protected function setConfig() { + $this->setConfigAccountData(); + $this->setConfigMixedData(); + } + + /** + * Set config account data + * + * @return void + */ + protected function setConfigAccountData() { if (isset($this->transactionBase['currency']) && $this->transactionBase['currency'] != '') { $this->config['merchant'] = $this->config[$this->transactionBase['currency'] . '_MERCHANT']; $this->config['merchantKey'] = $this->config[$this->transactionBase['currency'] . '_SECRET_KEY']; } elseif (isset($this->config['merchantAccount'])) { + $key = ''; foreach ($this->config as $configKey => $configValue) { if ($configValue === $this->config['merchantAccount']) { $key = $configKey; @@ -355,7 +382,14 @@ protected function setConfig() $this->config['merchant'] = $this->config[$this->transactionBase['currency'] . '_MERCHANT']; $this->config['merchantKey'] = $this->config[$this->transactionBase['currency'] . '_SECRET_KEY']; } + } + /** + * Set config mixed data + * + * @return void + */ + protected function setConfigMixedData() { $this->config['api'] = 'live'; if ($this->config['SANDBOX']) { $this->config['api'] = 'sandbox'; @@ -408,17 +442,18 @@ protected function execApiCall() { $this->prepare(); $transaction = []; + $header = []; $this->logContent['callState2'] = 'REQUEST'; $this->logContent['sendApiUrl'] = $this->config['apiUrl']; $this->logContent['sendContent'] = $this->content; $this->logContent['sendSignature'] = $this->config['computedHash']; - $commRresult = $this->runCommunication($this->config['apiUrl'], $this->content, $this->headers); - $this->logContent['callState3'] = 'RESULT'; - //call result + //call + $commRresult = $this->runCommunication($this->config['apiUrl'], $this->content, $this->headers); + //result $result = explode("\r\n", $commRresult); $transaction['responseBody'] = end($result); @@ -439,18 +474,25 @@ protected function execApiCall() //fill transaction data if (is_object(json_decode($transaction['responseBody']))) { - foreach (json_decode($transaction['responseBody']) as $key => $value) { - $transaction[$key] = $value; + foreach ($this->convertToArray(json_decode($transaction['responseBody'])) as $key => $value) { + $transaction[$key] = $value; } } if (isset($transaction['transactionId'])) { $this->logTransactionId = $transaction['transactionId']; + } elseif (isset($transaction['transactions']) && isset($transaction['transactions'][0])) { + if (isset($transaction['transactions'][0]['transactionId'])) { + $this->logTransactionId = $transaction['transactions'][0]['transactionId']; + } } elseif (isset($transaction['cardId'])) { $this->logTransactionId = $transaction['cardId']; } + if (isset($transaction['orderRef'])) { $this->logOrderRef = $transaction['orderRef']; + } elseif (isset($transaction['transactions'])) { + $this->logOrderRef = $transaction['transactions'][0]['orderRef']; } $this->returnData = $transaction; @@ -468,7 +510,7 @@ protected function execApiCall() * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ @@ -497,12 +539,108 @@ public function runStart() } + /** + * Start EAM + * + * @category SDK + * @package SimplePayV2_SDK + * @author SimplePay IT Support + * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) + * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html + */ +class SimplePayStartEam extends Base +{ + protected $currentInterface = 'starteam'; + public $returnData = []; + public $transactionBase = [ + 'salt' => '', + 'merchant' => '', + 'orderRef' => '', + ]; + + /** + * Run finish + * + * @return array $result API response + */ + public function runStartEam() + { + return $this->execApiCall(); + } +} + + + /** + * Start Apple Pay merchant validation + * + * @category SDK + * @package SimplePayV2_SDK + * @author SimplePay IT Support + * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) + * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html + */ +class SimplePayStartApplePay extends Base +{ + protected $currentInterface = 'startapplepay'; + public $transactionBase = [ + 'salt' => '', + 'merchant' => '', + 'orderRef' => '', + 'currency' => '', + 'domain' => '', + 'sdkVersion' => '', + ]; + + /** + * Send initial data to SimplePay API for validation + * + * @return void + */ + public function runStartApplePay() + { + $this->execApiCall(); + } +} + + + /** + * Do Apple Pay merchant transaction + * + * @category SDK + * @package SimplePayV2_SDK + * @author SimplePay IT Support + * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) + * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html + */ +class SimplePayDoApplePay extends Base +{ + protected $currentInterface = 'doapplepay'; + public $transactionBase = [ + 'salt' => '', + 'merchant' => '', + 'transactionId' => '', + 'applePayToken' => [], + 'sdkVersion' => '' + ]; + + /** + * Run Appl Pay trnsaction + * + * @return void + */ + public function runDoApplePay() + { + $this->execApiCall(); + } +} + + /** * Back * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ @@ -510,6 +648,7 @@ class SimplePayBack extends Base { protected $currentInterface = 'back'; protected $notification = []; + protected $notificationFormated = ''; public $request = [ 'rRequest' => '', 'sRequest' => '', @@ -595,19 +734,22 @@ public function getFormatedNotification() * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ class SimplePayIpn extends Base { protected $currentInterface = 'ipn'; - protected $returnData = []; + public $returnData = []; protected $receiveDate = ''; protected $ipnContent = []; protected $responseContent = ''; + protected $confirmContent = []; protected $ipnReturnData = []; + protected $signature = ''; public $validationResult = false; + protected $isGAHExists = true; /** * IPN validation @@ -618,24 +760,7 @@ class SimplePayIpn extends Base */ public function isIpnSignatureCheck($content = '') { - if (!function_exists('getallheaders')) { - /** - * Getallheaders fon Nginx - * - * @return header - */ - function getallheaders() - { - $headers = []; - foreach ($_SERVER as $name => $value) { - if (substr($name, 0, 5) === 'HTTP_') { - $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; - } - } - return $headers; - } - } - $signature = $this->getSignatureFromHeader(getallheaders()); + $signature = $this->getIpnSignature(); foreach (json_decode($this->checkOrSetToJson($content)) as $key => $value) { $this->ipnContent[$key] = $value; @@ -670,7 +795,7 @@ function getallheaders() $this->confirmContent = 'UNSUCCESSFUL VALIDATION'; $this->signature = 'UNSUCCESSFUL VALIDATION'; } elseif ($this->validationResult) { - $this->ipnContent['receiveDate'] = @date("c", time()); + $this->ipnContent['receiveDate'] = date("c", time()); $this->confirmContent = json_encode($this->ipnContent); $this->signature = $this->getSignature($this->config['merchantKey'], $this->confirmContent); } @@ -681,6 +806,28 @@ function getallheaders() return $this->validationResult; } + /** + * Signature for IPN + * + * @return string + */ + protected function getIpnSignature() { + $this->isGAHExists = function_exists('getallheaders'); + if ($this->isGAHExists) { + $signature = $this->getSignatureFromHeader(getallheaders()); + } elseif (!$this->isGAHExists) { + //Getallheaders fon Nginx + $headers = []; + foreach ($this->config['SERVER_DATA'] as $name => $value) { + if (substr($name, 0, 5) === 'HTTP_') { + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } + $signature = $this->getSignatureFromHeader($headers); + } + return $signature; + } + /** * Immediate IPN confirmation * @@ -693,7 +840,7 @@ public function runIpnConfirm() header('Content-type: application/json'); header('Signature: ' . $this->ipnReturnData['signature']); print $this->ipnReturnData['confirmContent']; - } catch (\Exception $e) { + } catch (Exception $e) { $this->writeLog(['ipnConfirm' => $e->getMessage()]); return false; } @@ -719,14 +866,14 @@ public function getIpnConfirmContent() * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ class SimplePayQuery extends Base { protected $currentInterface = 'query'; - protected $returnData = []; + public $returnData = []; protected $transactionBase = [ 'salt' => '', 'merchant' => '' @@ -741,9 +888,10 @@ class SimplePayQuery extends Base */ public function addSimplePayId($simplePayId = '') { - if (!isset($this->transactionBase['transactionIds']) || count($this->transactionBase['transactionIds']) === 0) { + if (!isset($this->transactionBase['transactionIds'])) { + $this->transactionBase['transactionIds'] = []; $this->logTransactionId = $simplePayId; - } + } $this->transactionBase['transactionIds'][] = $simplePayId; } @@ -756,9 +904,10 @@ public function addSimplePayId($simplePayId = '') */ public function addMerchantOrderId($merchantOrderId = '') { - if (!isset($this->transactionBase['orderRefs']) || count($this->transactionBase['orderRefs']) === 0) { + if (!isset($this->transactionBase['orderRefs'])) { + $this->transactionBase['orderRefs'] = []; $this->logOrderRef = $merchantOrderId; - } + } $this->transactionBase['orderRefs'][] = $merchantOrderId; } @@ -779,14 +928,14 @@ public function runQuery() * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ class SimplePayRefund extends Base { protected $currentInterface = 'refund'; - protected $returnData = []; + public $returnData = []; public $transactionBase = [ 'salt' => '', 'merchant' => '', @@ -802,14 +951,20 @@ class SimplePayRefund extends Base */ public function runRefund() { - if ($this->transactionBase['orderRef'] == '') { + if ($this->transactionBase['orderRef'] === '') { unset($this->transactionBase['orderRef']); + if ($this->transactionBase['transactionId'] !== '') { + $this->logTransactionId = $this->transactionBase['transactionId']; + } } + if ($this->transactionBase['transactionId'] == '') { unset($this->transactionBase['transactionId']); + if ($this->transactionBase['orderRef'] !== '') { + $this->logOrderRef = $this->transactionBase['orderRef']; + } } - $this->logTransactionId = @$this->transactionBase['transactionId']; - $this->logOrderRef = @$this->transactionBase['orderRef']; + return $this->execApiCall(); } } @@ -820,14 +975,14 @@ public function runRefund() * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ class SimplePayFinish extends Base { protected $currentInterface = 'finish'; - protected $returnData = []; + public $returnData = []; public $transactionBase = [ 'salt' => '', 'merchant' => '', @@ -850,15 +1005,59 @@ public function runFinish() } - /** - * Hash generation for Signature - * - * @category SDK - * @package SimplePayV2_SDK - * @author SimplePay IT Support - * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) - * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html - */ +/** + * Cancel of transaction + * + * @category SDK + * @package SimplePayV2_SDK + * @author SimplePay IT Support + * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) + * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html + */ +class SimplePayTransactionCancel extends Base +{ + protected $currentInterface = 'transactioncancel'; + public $returnData = []; + public $transactionBase = [ + 'salt' => '', + 'merchant' => '', + ]; + + /** + * Run transaction cancel + * + * @return array $result API response + */ + public function runTransactionCancel() + { + if ($this->transactionBase['orderRef'] === '') { + unset($this->transactionBase['orderRef']); + if ($this->transactionBase['transactionId'] !== '') { + $this->logTransactionId = $this->transactionBase['transactionId']; + } + } + + if ($this->transactionBase['transactionId'] == '') { + unset($this->transactionBase['transactionId']); + if ($this->transactionBase['orderRef'] !== '') { + $this->logOrderRef = $this->transactionBase['orderRef']; + } + } + + return $this->execApiCall(); + } +} + + +/** + * Hash generation for Signature + * + * @category SDK + * @package SimplePayV2_SDK + * @author SimplePay IT Support + * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) + * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html + */ trait Signature { @@ -903,20 +1102,19 @@ public function isCheckSignature($data = '', $signatureToCheck = '') $this->config['computedSignature'] = $this->getSignature($this->config['merchantKey'], $data); $this->logContent['signatureToCheck'] = $signatureToCheck; $this->logContent['computedSignature'] = $this->config['computedSignature']; - try { - if ($this->phpVersion === 7) { - if (!hash_equals($this->config['computedSignature'], $signatureToCheck)) { - throw new \Exception('fail'); - } - } elseif ($this->phpVersion === 5) { - if ($this->config['computedSignature'] !== $signatureToCheck) { - throw new \Exception('fail'); - } + + if ($this->phpVersion >= 7) { + if (!hash_equals($this->config['computedSignature'], $signatureToCheck)) { + $this->logContent['hashCheckResult'] = 'fail'; + return false; + } + } elseif ($this->phpVersion < 7) { + if ($this->config['computedSignature'] !== $signatureToCheck) { + $this->logContent['hashCheckResult'] = 'fail'; + return false; } - } catch (\Exception $e) { - $this->logContent['hashCheckResult'] = $e->getMessage(); - return false; } + $this->logContent['hashCheckResult'] = 'success'; return true; } @@ -946,21 +1144,24 @@ protected function getSignatureFromHeader($header = []) * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ trait Communication { + protected $result; + protected $curlInfo; + /** * Handler for cURL communication * - * @param string $url URL - * @param string $data Sending data to URL - * @param string $headers Header information for POST + * @param string $url URL + * @param string $data Sending data to URL + * @param string $headers Header information for POST * - * @return array Result of cURL communication + * @return string Result of cURL communication */ public function runCommunication($url = '', $data = '', $headers = []) { @@ -981,13 +1182,11 @@ public function runCommunication($url = '', $data = '', $headers = []) $result = curl_exec($curlData); $this->result = $result; $this->curlInfo = curl_getinfo($curlData); - try { - if (curl_errno($curlData)) { - throw new \Exception(curl_error($curlData)); - } - } catch (\Exception $e) { - $this->logContent['runCommunicationException'] = $e->getMessage(); + + if (curl_errno($curlData)) { + $this->logContent['runCommunicationException'] = curl_error($curlData); } + curl_close($curlData); return $result; } @@ -999,7 +1198,7 @@ public function runCommunication($url = '', $data = '', $headers = []) * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ @@ -1081,7 +1280,7 @@ protected function backNotification() * * @category SDK * @package SimplePayV2_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */ @@ -1106,22 +1305,18 @@ public function writeLog($log = []) $log = $this->logContent; } - $date = @date('Y-m-d H:i:s', time()); - $logFile = $this->config['logPath'] . '/' . @date('Ymd', time()) . '.log'; + $date = date('Y-m-d H:i:s', time()); + $logFile = $this->config['logPath'] . '/' . date('Ymd', time()) . '.log'; - try { - if (!is_writable($this->config['logPath'])) { + if (!is_writable($this->config['logPath'])) { + $write = false; + $this->logContent['logFile'] = 'Folder is not writable: ' . $this->config['logPath']; + } + if (file_exists($logFile)) { + if (!is_writable($logFile)) { $write = false; - throw new \Exception('Folder is not writable: ' . $this->config['logPath']); - } - if (file_exists($logFile)) { - if (!is_writable($logFile)) { - $write = false; - throw new \Exception('File is not writable: ' . $logFile); - } + $this->logContent['logFile'] ='File is not writable: ' . $logFile; } - } catch (\Exception $e) { - $this->logContent['logFile'] = $e->getMessage(); } if ($write) { @@ -1185,12 +1380,8 @@ protected function contentFilter($key = '', $value = '') */ protected function logToFile($logFile = '', $logText = '') { - try { - if (!file_put_contents($logFile, $logText, FILE_APPEND | LOCK_EX)) { - throw new \Exception('Log write error'); - } - } catch (\Exception $e) { - $this->logContent['logToFile'] = $e->getMessage(); + if (!file_put_contents($logFile, $logText, FILE_APPEND | LOCK_EX)) { + $this->logContent['logToFile'] = 'Log write error'; } unset($logFile, $logText); } @@ -1202,7 +1393,7 @@ protected function logToFile($logFile = '', $logText = '') * * @category SDK * @package SimplePayV21_SDK - * @author SimplePay IT Support + * @author SimplePay IT Support * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GENERAL PUBLIC LICENSE (GPL V3.0) * @link http://simplepartner.hu/online_fizetesi_szolgaltatas.html */