From 730b2b71389f9d00a5775ba0875bf92a5775ace3 Mon Sep 17 00:00:00 2001 From: Lito Date: Thu, 30 Aug 2018 13:02:09 +0200 Subject: [PATCH 1/2] Updated composer packages --- composer.lock | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/composer.lock b/composer.lock index a0fbe3e..a345be1 100644 --- a/composer.lock +++ b/composer.lock @@ -259,16 +259,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.6", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { @@ -280,12 +280,12 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -318,7 +318,7 @@ "spy", "stub" ], - "time": "2018-04-18T13:57:24+00:00" + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1070,25 +1070,28 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.8.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "suggest": { + "ext-ctype": "For best performance" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -1121,20 +1124,20 @@ "polyfill", "portable" ], - "time": "2018-04-30T19:57:29+00:00" + "time": "2018-08-06T14:22:27+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.11", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0" + "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/c5010cc1692ce1fa328b1fb666961eb3d4a85bb0", - "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0", + "url": "https://api.github.com/repos/symfony/yaml/zipball/c2f4812ead9f847cb69e90917ca7502e6892d6b8", + "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8", "shasum": "" }, "require": { @@ -1180,7 +1183,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-05-03T23:18:14+00:00" + "time": "2018-08-10T07:34:36+00:00" }, { "name": "webmozart/assert", From 781cc32a666ba30d81eaf00f2fb88c0f63efa3ca Mon Sep 17 00:00:00 2001 From: Lito Date: Thu, 30 Aug 2018 13:03:28 +0200 Subject: [PATCH 2/2] Updated private with protected scope. Fixed messages response as array --- src/Redsys/Tpv/Curl.php | 9 ++++--- src/Redsys/Tpv/Signature.php | 12 ++++----- src/Redsys/Tpv/Tpv.php | 49 +++++++++++++++++++++++------------- tests/Redsys/Tpv/TpvTest.php | 3 +-- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/Redsys/Tpv/Curl.php b/src/Redsys/Tpv/Curl.php index a4f6a01..bd0314f 100644 --- a/src/Redsys/Tpv/Curl.php +++ b/src/Redsys/Tpv/Curl.php @@ -7,11 +7,11 @@ class Curl { - private $settings = array(); + protected $settings = array(); - private $connect; - private $html; - private $info; + protected $connect; + protected $html; + protected $info; public function __construct(array $settings) { @@ -129,6 +129,7 @@ public function setBase() } $base = parse_url($this->info['url']); + $this->settings['base'] = $base['scheme'].'://'.$base['host']; } diff --git a/src/Redsys/Tpv/Signature.php b/src/Redsys/Tpv/Signature.php index e6eefb8..822fdd4 100644 --- a/src/Redsys/Tpv/Signature.php +++ b/src/Redsys/Tpv/Signature.php @@ -35,7 +35,7 @@ public static function fromXML($xml, $key) return self::MAC256($xml, self::encryptKey($order[1], $key)); } - private static function calculate($prefix, array $fields, array $values, $key) + protected static function calculate($prefix, array $fields, array $values, $key) { foreach ($fields as $field) { if (!isset($values[$prefix.$field])) { @@ -48,7 +48,7 @@ private static function calculate($prefix, array $fields, array $values, $key) return self::MAC256(base64_encode(json_encode($values)), $key); } - private static function encrypt3DES($message, $key) + protected static function encrypt3DES($message, $key) { if (function_exists('openssl_encrypt')) { return self::encrypt3DESOpenSSL($message, $key); @@ -57,7 +57,7 @@ private static function encrypt3DES($message, $key) return self::encrypt3DESMcrypt($message, $key); } - private static function encrypt3DESOpenSSL($message, $key) + protected static function encrypt3DESOpenSSL($message, $key) { $l = ceil(strlen($message) / 8) * 8; $message = $message.str_repeat("\0", $l - strlen($message)); @@ -65,19 +65,19 @@ private static function encrypt3DESOpenSSL($message, $key) return substr(openssl_encrypt($message, 'des-ede3-cbc', $key, OPENSSL_RAW_DATA, "\0\0\0\0\0\0\0\0"), 0, $l); } - private static function encrypt3DESMcrypt($message, $key) + protected static function encrypt3DESMcrypt($message, $key) { $iv = implode(array_map('chr', array(0, 0, 0, 0, 0, 0, 0, 0))); return mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv); } - private static function encryptKey($order, $key) + protected static function encryptKey($order, $key) { return self::encrypt3DES($order, base64_decode($key)); } - private static function MAC256($string, $key) + protected static function MAC256($string, $key) { return base64_encode(hash_hmac('sha256', $string, $key, true)); } diff --git a/src/Redsys/Tpv/Tpv.php b/src/Redsys/Tpv/Tpv.php index b498d6e..fd986f3 100644 --- a/src/Redsys/Tpv/Tpv.php +++ b/src/Redsys/Tpv/Tpv.php @@ -8,7 +8,7 @@ class Tpv { - private $options = array( + protected $options = array( 'Version' => '0.1', 'Environment' => 'test', 'Currency' => '978', @@ -16,18 +16,24 @@ class Tpv 'ConsumerLanguage' => '001' ); - private $option_prefix = 'Ds_Merchant_'; + protected $option_prefix = 'Ds_Merchant_'; - private $o_required = array('Environment', 'Currency', 'Terminal', 'ConsumerLanguage', 'MerchantCode', 'Key', 'SignatureVersion', 'MerchantName', 'Titular'); - private $o_optional = array('UrlOK', 'UrlKO', 'TransactionType', 'MerchantURL', 'PayMethods'); + protected $o_required = array( + 'Environment', 'Currency', 'Terminal', 'ConsumerLanguage', + 'MerchantCode', 'Key', 'SignatureVersion', 'MerchantName', 'Titular' + ); + + protected $o_optional = array( + 'UrlOK', 'UrlKO', 'TransactionType', 'MerchantURL', 'PayMethods' + ); - private $environment = ''; - private $environments = array( + protected $environment = ''; + protected $environments = array( 'test' => 'https://sis-t.redsys.es:25443/sis', 'real' => 'https://sis.redsys.es/sis' ); - private $values = array(); + protected $values = array(); public function __construct(array $options) { @@ -179,7 +185,7 @@ public function sendXml(array $options) )); } - private function setXmlValues() + protected function setXmlValues() { $xml = array('DS_Version' => $this->options['Version']); @@ -190,7 +196,7 @@ private function setXmlValues() return $xml; } - private function xmlArray2string($xml) + protected function xmlArray2string($xml) { $doc = new DOMDocument(); @@ -249,7 +255,7 @@ public function checkTransactionXml(array $post) return array_merge($post, $data); } - private function setValueDefault(array $options, $option) + protected function setValueDefault(array $options, $option) { $code = $this->option_prefix.$option; @@ -262,7 +268,7 @@ private function setValueDefault(array $options, $option) return $this; } - private function setValues(array $options) + protected function setValues(array $options) { foreach ($options as $key => $value) { $key = $this->option_prefix.$key; @@ -338,14 +344,19 @@ public function checkTransaction(array $post) return array_merge($post, array_map('urldecode', $data)); } - private function checkTransactionError(array $data, $prefix) + public function getTransactionParameters(array $post) + { + return json_decode(base64_decode(strtr($post['Ds_MerchantParameters'], '-_', '+/')), true); + } + + protected function checkTransactionError(array $data, $prefix) { if ($error = (isset($data[$prefix.'ErrorCode']) ? $data[$prefix.'ErrorCode'] : false)) { - throw new Exception(Messages::getByCode($error) ?: '', (int)$error); + $this->throwErrorByCode($error); } } - private function checkTransactionResponse(array $data, $prefix) + protected function checkTransactionResponse(array $data, $prefix) { $response = isset($data[$prefix.'Response']) ? $data[$prefix.'Response'] : null; @@ -356,19 +367,21 @@ private function checkTransactionResponse(array $data, $prefix) $value = (int)$response; if (($value < 0) || (($value > 99) && ($value !== 900))) { - throw new Exception(Messages::getByCode($response) ?: '', $value); + $this->throwErrorByCode($response); } } - private function checkTransactionSignature($signature, $postSignature) + protected function checkTransactionSignature($signature, $postSignature) { if ($signature !== strtr($postSignature, '-_', '+/')) { throw new Exception(sprintf('Signature not valid (%s != %s)', $signature, $postSignature)); } } - public function getTransactionParameters(array $post) + protected function throwErrorByCode($code) { - return json_decode(base64_decode(strtr($post['Ds_MerchantParameters'], '-_', '+/')), true); + $message = Messages::getByCode($code); + + throw new Exception($message ? $message['message'] : '', (int)$code); } } diff --git a/tests/Redsys/Tpv/TpvTest.php b/tests/Redsys/Tpv/TpvTest.php index 78d9619..64b95fc 100644 --- a/tests/Redsys/Tpv/TpvTest.php +++ b/tests/Redsys/Tpv/TpvTest.php @@ -11,9 +11,8 @@ class TpvTest extends PHPUnit_Framework_TestCase { public function testInstance() { - $config = require (realpath(__DIR__.'/../../..').'/config.php'); + $tpv = new Tpv(require (__DIR__.'/../../../config.php')); - $tpv = new Tpv($config); $this->assertInstanceOf('Redsys\Tpv\Tpv', $tpv); return $tpv;