From 69875a6cf690078c189274a4f56687e8c84c4808 Mon Sep 17 00:00:00 2001 From: Gregorio Magini Date: Thu, 19 Nov 2015 13:33:37 +0100 Subject: [PATCH 1/2] WSS2S class with support for callRequestTokenS2S and callRequestTokenS2S methods --- CHANGELOG.md | 4 +- src/Parameter/PagamParameter.php | 155 +++++++++++++++++++++ src/Parameter/RequestTokenParameter.php | 116 ++++++++++++++++ src/Response/PagamResponse.php | 52 +++++++ src/Response/RequestTokenResponse.php | 71 ++++++++++ src/Service.php | 41 ++++++ src/SoapClient.php | 174 ++++++++++++++++++++++++ src/SoapClientInterface.php | 26 ++++ src/WSCryptDecrypt.php | 28 +--- src/WSCryptDecryptSoapClient.php | 165 +--------------------- src/WSS2S.php | 46 +++++++ src/WSS2SSoapClient.php | 27 ++++ 12 files changed, 723 insertions(+), 182 deletions(-) create mode 100644 src/Parameter/PagamParameter.php create mode 100644 src/Parameter/RequestTokenParameter.php create mode 100644 src/Response/PagamResponse.php create mode 100644 src/Response/RequestTokenResponse.php create mode 100644 src/Service.php create mode 100644 src/SoapClient.php create mode 100644 src/SoapClientInterface.php create mode 100644 src/WSS2S.php create mode 100644 src/WSS2SSoapClient.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c68332..997a5ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] +### Added +- WSS2S class with support for callRequestTokenS2S and callRequestTokenS2S methods ## [1.3.0] - 2015-11-06 ### Changed @@ -59,4 +61,4 @@ This project adheres to [Semantic Versioning](http://semver.org/). [1.1.1]: https://github.com/endelwar/GestPayWS/compare/v1.1.0...v1.1.1 [1.1.0]: https://github.com/endelwar/GestPayWS/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/endelwar/GestPayWS/compare/v0.1.0...v1.0.0 -[0.1.0]: https://github.com/endelwar/GestPayWS/compare/67d07c5c9c4d1873ba9620af25b91e0a53664d80...v0.1.0 \ No newline at end of file +[0.1.0]: https://github.com/endelwar/GestPayWS/compare/67d07c5c9c4d1873ba9620af25b91e0a53664d80...v0.1.0 diff --git a/src/Parameter/PagamParameter.php b/src/Parameter/PagamParameter.php new file mode 100644 index 0000000..58bcba1 --- /dev/null +++ b/src/Parameter/PagamParameter.php @@ -0,0 +1,155 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS\Parameter; + +use InvalidArgumentException; + +/** + * Class PagamParameter + * @package EndelWar\GestPayWS\Parameter + * + * @property string $shopLogin + * @property string $uicCode; + * @property string $amount; + * @property string $shopTransactionId; + * @property string $cardNumber; + * @property int $expiryMonth; + * @property int $expiryYear; + * @property string $buyerName; + * @property string $buyerEmail; + * @property string $languageId; + * @property int $cvv; + * @property string $min; + * @property string $transKey; + * @property string $PARes; + * @property string $customInfo; + * @property string $IDEA; + * @property string $requestToken; + * @property string $tokenValue; + * @property string $clientIP; + * @property string $itemType; + * @property string $shippingDetails; + * @property string $redFraudPrevention; + * @property string $Red_CustomerInfo; + * @property string $Red_ShippingInfo; + * @property string $Red_BillingInfo; + * @property string $Red_CustomerData; + * @property string $Red_CustomInfo; + * @property string $Red_Items; + */ +class PagamParameter extends Parameter +{ + protected $parametersName = array( + 'shopLogin', + 'uicCode', + 'amount', + 'shopTransactionId', + 'cardNumber', + 'expiryMonth', + 'expiryYear', + 'buyerName', + 'buyerEmail', + 'languageId', + 'cvv', + 'min', + 'transKey', + 'PARes', + 'customInfo', + 'IDEA', + 'requestToken', + 'tokenValue', + 'clientIP', + 'itemType', + 'shippingDetails', + 'redFraudPrevention', + 'Red_CustomerInfo', + 'Red_ShippingInfo', + 'Red_BillingInfo', + 'Red_CustomerData', + 'Red_CustomInfo', + 'Red_Items', + ); + protected $mandatoryParameters = array( + 'shopLogin', + 'uicCode', + 'amount', + 'shopTransactionId', + ); + private $invalidChars = array( + '&', + ' ', + '§', //need also to be added programmatically, because UTF-8 + '(', + ')', + '*', + '<', + '>', + ',', + ';', + ':', + '*P1*', + '/', + '[', + ']', + '?', + '=', + '--', + '/*', + '%', + '//', + ); + private $invalidCharsFlattened = ''; + + /** + * @param array $parameters + */ + public function __construct(array $parameters = array()) + { + $this->invalidChars[] = chr(167); //§ ascii char + + parent::__construct($parameters); + } + + /** + * @param string $key + * @param mixed $value + */ + public function set($key, $value) + { + if (!in_array($key, $this->parametersName, true)) { + throw new InvalidArgumentException(sprintf('%s is not a valid parameter name.', $key)); + } + $this->verifyParameterValidity($value); + parent::set($key, $value); + } + + /** + * @param $value + * @return bool + */ + public function verifyParameterValidity($value) + { + if (strlen($this->invalidCharsFlattened) === 0) { + $invalidCharsQuoted = array_map('preg_quote', $this->invalidChars); + $this->invalidCharsFlattened = implode('|', $invalidCharsQuoted); + } + + if (preg_match_all('#' . $this->invalidCharsFlattened . '#', $value, $matches)) { + $invalidCharsMatched = '"' . implode('", "', $matches[0]) . '"'; + throw new InvalidArgumentException( + 'String ' . $value . ' contains invalid chars (i.e.: ' . $invalidCharsMatched . ').' + ); + } + + return true; + } +} diff --git a/src/Parameter/RequestTokenParameter.php b/src/Parameter/RequestTokenParameter.php new file mode 100644 index 0000000..1af324a --- /dev/null +++ b/src/Parameter/RequestTokenParameter.php @@ -0,0 +1,116 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS\Parameter; + +use InvalidArgumentException; + +/** + * Class RequestTokenParameter + * @package EndelWar\GestPayWS\Parameter + * + * @property string $shopLogin + * @property string $requestToken; + * @property string $cardNumber; + * @property int $expiryMonth; + * @property int $expiryYear; + * @property int $cvv; + * @property string $withAuth; + */ +class RequestTokenParameter extends Parameter +{ + protected $parametersName = array( + // Mandatory parameters + 'shopLogin', + 'requestToken', + 'cardNumber', + 'expiryMonth', + 'expiryYear', + // Optional parameters + 'cvv', + 'withAuth' + ); + protected $mandatoryParameters = array( + 'shopLogin', + 'requestToken', + 'cardNumber', + 'expiryMonth', + 'expiryYear', + ); + private $invalidChars = array( + '&', + ' ', + '§', //need also to be added programmatically, because UTF-8 + '(', + ')', + '*', + '<', + '>', + ',', + ';', + ':', + '*P1*', + '/', + '[', + ']', + '?', + '=', + '--', + '/*', + '%', + '//', + ); + private $invalidCharsFlattened = ''; + + /** + * @param array $parameters + */ + public function __construct(array $parameters = array()) + { + $this->invalidChars[] = chr(167); //§ ascii char + + parent::__construct($parameters); + } + + /** + * @param string $key + * @param mixed $value + */ + public function set($key, $value) + { + if (!in_array($key, $this->parametersName, true)) { + throw new InvalidArgumentException(sprintf('%s is not a valid parameter name.', $key)); + } + $this->verifyParameterValidity($value); + parent::set($key, $value); + } + + /** + * @param $value + * @return bool + */ + public function verifyParameterValidity($value) + { + if (strlen($this->invalidCharsFlattened) === 0) { + $invalidCharsQuoted = array_map('preg_quote', $this->invalidChars); + $this->invalidCharsFlattened = implode('|', $invalidCharsQuoted); + } + + if (preg_match_all('#' . $this->invalidCharsFlattened . '#', $value, $matches)) { + $invalidCharsMatched = '"' . implode('", "', $matches[0]) . '"'; + throw new InvalidArgumentException( + 'String ' . $value . ' contains invalid chars (i.e.: ' . $invalidCharsMatched . ').' + ); + } + + return true; + } +} diff --git a/src/Response/PagamResponse.php b/src/Response/PagamResponse.php new file mode 100644 index 0000000..f212712 --- /dev/null +++ b/src/Response/PagamResponse.php @@ -0,0 +1,52 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS\Response; + +/** + * Class PagamResponse + * @package EndelWar\GestPayWS\Response + */ +class PagamResponse extends Response +{ + protected $parametersName = array( + 'TransactionType', + 'TransactionResult', + 'ShopTransactionID', + 'BankTransactionID', + 'AuthorizationCode', + 'Currency', + 'Amount', + 'Country', + 'CardBIN', + 'Buyer', + 'CustomInfo', + 'TDLevel', + 'ErrorCode', + 'ErrorDescription', + 'AlertCode', + 'AlertDescription', + 'TransactionKey', + 'VbV', + 'RedResponseCode', + 'RedResponseDescription', + ); + + /** + * @param \stdClass $soapResponse + * @throws \Exception + */ + public function __construct($soapResponse) + { + $xml = simplexml_load_string($soapResponse->callPagamS2SResult->any); + parent::__construct($xml); + } +} diff --git a/src/Response/RequestTokenResponse.php b/src/Response/RequestTokenResponse.php new file mode 100644 index 0000000..76e3276 --- /dev/null +++ b/src/Response/RequestTokenResponse.php @@ -0,0 +1,71 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS\Response; + +/** + * Class RequestTokenResponse + * @package EndelWar\GestPayWS\Response + */ +class RequestTokenResponse extends Response +{ + protected $parametersName = array( + 'TransactionType', + 'TransactionResult', + 'TransactionErrorCode', + 'TransactionErrorDescription', + 'AuthorizationErrorCode', + 'AuthorizationResult', + 'AuthorizationCodeDescription', + 'CardCountry', + 'CardCountryCode', + 'CheckCVV', + 'CheckCVVDescription', + 'IssuerCountry', + 'IssuerCountryCode', + 'CompanyDescription', + 'CompanyCode', + 'Commercial', + 'ProductDescription', + 'ProductType', + 'CheckDigit', + 'CheckDigitDescription', + 'CheckDate', + 'CheckDateDescription', + 'EnrolledCode', + 'EnrolledDescription', + 'Prepaid', + 'CardBIN', + 'Token', + 'TokenExpiryMonth', + 'TokenExpiryYear', + ); + + /** + * @param \stdClass $soapResponse + * @throws \Exception + */ + public function __construct($soapResponse) + { + $xml = simplexml_load_string($soapResponse->CallRequestTokenS2SResult->any); + parent::__construct($xml); + } + + /** + * @param string $shopLogin + * @param string $wsdlEnvironment + * @return string + */ + public function getToken() + { + return $this->get('Token'); + } +} diff --git a/src/Service.php b/src/Service.php new file mode 100644 index 0000000..c65e1a0 --- /dev/null +++ b/src/Service.php @@ -0,0 +1,41 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS; + +use EndelWar\GestPayWS\Parameter\Parameter; + +/** + * Class Service + * @package EndelWar\GestPayWS + */ +abstract class Service +{ + protected $soapClient; + + /** + * @param \SoapClient $soapClient + */ + public function __construct(\SoapClient $soapClient) + { + $this->soapClient = $soapClient; + } + + /** + * @param EndelWar\GestPayWS\Parameter $parameters + */ + protected function validateParameters(Parameter $parameters) + { + if (!$parameters->areAllMandatoryParametersSet()) { + throw new \InvalidArgumentException('Missing parameter'); + } + } +} diff --git a/src/SoapClient.php b/src/SoapClient.php new file mode 100644 index 0000000..dd01556 --- /dev/null +++ b/src/SoapClient.php @@ -0,0 +1,174 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS; + +abstract class SoapClient implements SoapClientInterface +{ + public $wsdlEnvironment; + protected $streamContextOption = array(); + protected $certificatePeerName = array( + 'test' => 'testecomm.sella.it', + 'production' => 'ecomms2s.sella.it', + ); + protected $soapClient; + + /** + * WSCryptDecryptSoapClient constructor. + * @param bool|false $testEnv enable the test environment + * @param null $caFile path to Certification Authority bundle file + */ + public function __construct($testEnv = false, $caFile = null) + { + $soapClientDefaultOption = array( + 'user_agent' => 'EndelWar-GestPayWS/1.3 (+https://github.com/endelwar/GestPayWS)', + 'stream_context' => $this->getStreamContext($testEnv, $caFile), + 'connection_timeout' => 3000, + ); + if ($testEnv) { + $soapClientEnvironmentOption = $this->setTestEnvironment(); + } else { + $soapClientEnvironmentOption = $this->setProductionEnvironment(); + } + $soapClientOption = array_merge($soapClientDefaultOption, $soapClientEnvironmentOption); + $this->soapClient = new \soapClient(static::getWsdlUrl($this->wsdlEnvironment), $soapClientOption); + } + + /** + * @return array + */ + private function setTestEnvironment() + { + $this->wsdlEnvironment = 'test'; + $soapClientTestOption = array( + 'trace' => true, + 'cache_wsdl' => WSDL_CACHE_NONE, + ); + + return $soapClientTestOption; + } + + /** + * @return array + */ + private function setProductionEnvironment() + { + $this->wsdlEnvironment = 'production'; + + return array(); + } + + /** + * @param bool $testEnv + * @param string $caFile + * @return resource + */ + private function getStreamContext($testEnv = false, $caFile = null) + { + if ($testEnv) { + $host = $this->certificatePeerName['test']; + } else { + $host = $this->certificatePeerName['production']; + } + + $this->streamContextOption['ssl']['crypto_method'] = STREAM_CRYPTO_METHOD_TLS_CLIENT; + $this->streamContextOption['ssl']['verify_peer'] = true; + $this->streamContextOption['ssl']['SNI_enabled'] = true; + + // Disable TLS compression to prevent CRIME attacks where supported (PHP 5.4.13 or later). + if (PHP_VERSION_ID >= 50413) { + $this->streamContextOption['ssl']['disable_compression'] = true; + } + + if (PHP_VERSION_ID < 50600) { + //CN_match was deprecated in favour of peer_name in PHP 5.6 + $this->streamContextOption['ssl']['CN_match'] = $host; + $this->streamContextOption['ssl']['SNI_server_name'] = $host; + // PHP 5.6 or greater will find the system cert by default. When < 5.6, use the system ca-certificates. + if (is_null($caFile)) { + $this->streamContextOption['ssl']['cafile'] = $this->getDefaultCABundle(); + } else { + $this->streamContextOption['ssl']['cafile'] = $caFile; + } + } else { + $this->streamContextOption['ssl']['peer_name'] = $host; + $this->streamContextOption['ssl']['verify_peer_name'] = true; + } + + return stream_context_create($this->streamContextOption); + } + + /** + * @return \soapClient + */ + public function getSoapClient() + { + return $this->soapClient; + } + + /** + * Returns the default cacert bundle for the current system. + * + * First, the openssl.cafile and curl.cainfo php.ini settings are checked. + * If those settings are not configured, then the common locations for + * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X + * and Windows are checked. If any of these file locations are found on + * disk, they will be utilized. + * + * Note: the result of this function is cached for subsequent calls. + * + * @throws \RuntimeException if no bundle can be found. + * @return string + * + * @link https://github.com/guzzle/guzzle/blob/6.1.0/src/functions.php#L143 + */ + public function getDefaultCABundle() + { + $cafiles = array( + // Red Hat, CentOS, Fedora (provided by the ca-certificates package) + '/etc/pki/tls/certs/ca-bundle.crt', + // Ubuntu, Debian (provided by the ca-certificates package) + '/etc/ssl/certs/ca-certificates.crt', + // FreeBSD (provided by the ca_root_nss package) + '/usr/local/share/certs/ca-root-nss.crt', + // OS X provided by homebrew (using the default path) + '/usr/local/etc/openssl/cert.pem', + // Google app engine + '/etc/ca-certificates.crt', + // Windows? + 'C:\\windows\\system32\\curl-ca-bundle.crt', + 'C:\\windows\\curl-ca-bundle.crt', + ); + + if ($ca = ini_get('openssl.cafile')) { + return $ca; + } + if ($ca = ini_get('curl.cainfo')) { + return $ca; + } + foreach ($cafiles as $filename) { + if (file_exists($filename)) { + return $filename; + } + } + throw new \RuntimeException(<<< EOT +No system CA bundle could be found in any of the the common system locations. +PHP versions earlier than 5.6 are not properly configured to use the system's +CA bundle by default. Mozilla provides a commonly used CA bundle which can be +downloaded here (provided by the maintainer of cURL): +https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once +you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP +ini setting to point to the path to the file. See http://curl.haxx.se/docs/sslcerts.html +for more information. +EOT + ); + } +} diff --git a/src/SoapClientInterface.php b/src/SoapClientInterface.php new file mode 100644 index 0000000..cf7d4ce --- /dev/null +++ b/src/SoapClientInterface.php @@ -0,0 +1,26 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS; + +/** + * Interface SoapClient + * @package EndelWar\GestPayWS + */ +interface SoapClientInterface +{ + /** + * Returns the WSDL Url of the client for the current environment. + * @param string $wsdlEnvironment Either "test" or "production" + * @return string + */ + static function getWsdlUrl($wsdlEnvironment); +} diff --git a/src/WSCryptDecrypt.php b/src/WSCryptDecrypt.php index 91682d6..59469fe 100644 --- a/src/WSCryptDecrypt.php +++ b/src/WSCryptDecrypt.php @@ -20,31 +20,17 @@ * Class WSCryptDecrypt * @package EndelWar\GestPayWS */ -class WSCryptDecrypt +class WSCryptDecrypt extends Service { - private $soapClient; - - /** - * @param \SoapClient $soapClient - */ - public function __construct(\SoapClient $soapClient) - { - $this->soapClient = $soapClient; - } - /** * @param EncryptParameter $parameters * @return EncryptResponse */ public function encrypt(EncryptParameter $parameters) { - if (!$parameters->areAllMandatoryParametersSet()) { - throw new \InvalidArgumentException('Missing parameter'); - } + $this->validateParameters($parameters); $soapResponse = $this->soapClient->Encrypt($parameters); - $encryptResponse = new EncryptResponse($soapResponse); - - return $encryptResponse; + return new EncryptResponse($soapResponse); } /** @@ -53,12 +39,8 @@ public function encrypt(EncryptParameter $parameters) */ public function decrypt(DecryptParameter $parameters) { - if (!$parameters->areAllMandatoryParametersSet()) { - throw new \InvalidArgumentException('Missing parameter'); - } + $this->validateParameters($parameters); $soapResponse = $this->soapClient->Decrypt($parameters); - $decryptResponse = new DecryptResponse($soapResponse); - - return $decryptResponse; + return new DecryptResponse($soapResponse); } } diff --git a/src/WSCryptDecryptSoapClient.php b/src/WSCryptDecryptSoapClient.php index 7683107..934aa75 100644 --- a/src/WSCryptDecryptSoapClient.php +++ b/src/WSCryptDecryptSoapClient.php @@ -11,168 +11,17 @@ namespace EndelWar\GestPayWS; -class WSCryptDecryptSoapClient +class WSCryptDecryptSoapClient extends SoapClient { - protected $wsdlUrl = array( - 'test' => 'https://testecomm.sella.it/gestpay/GestPayWS/WsCryptDecrypt.asmx?wsdl', - 'production' => 'https://ecomms2s.sella.it/gestpay/GestPayWS/WsCryptDecrypt.asmx?wsdl', - ); - public $wsdlEnvironment; - protected $streamContextOption = array(); - protected $certificatePeerName = array( - 'test' => 'testecomm.sella.it', - 'production' => 'ecomms2s.sella.it', - ); - protected $soapClient; - - /** - * WSCryptDecryptSoapClient constructor. - * @param bool|false $testEnv enable the test environment - * @param null $caFile path to Certification Authority bundle file - */ - public function __construct($testEnv = false, $caFile = null) - { - $soapClientDefaultOption = array( - 'user_agent' => 'EndelWar-GestPayWS/1.3 (+https://github.com/endelwar/GestPayWS)', - 'stream_context' => $this->getStreamContext($testEnv, $caFile), - 'connection_timeout' => 3000, - ); - if ($testEnv) { - $soapClientEnvironmentOption = $this->setTestEnvironment(); - } else { - $soapClientEnvironmentOption = $this->setProductionEnvironment(); - } - $soapClientOption = array_merge($soapClientDefaultOption, $soapClientEnvironmentOption); - $this->soapClient = new \soapClient($this->wsdlUrl[$this->wsdlEnvironment], $soapClientOption); - } - - /** - * @return array - */ - private function setTestEnvironment() - { - $this->wsdlEnvironment = 'test'; - $soapClientTestOption = array( - 'trace' => true, - 'cache_wsdl' => WSDL_CACHE_NONE, - ); - - return $soapClientTestOption; - } - - /** - * @return array - */ - private function setProductionEnvironment() - { - $this->wsdlEnvironment = 'production'; - - return array(); - } - - /** - * @param bool $testEnv - * @param string $caFile - * @return resource - */ - private function getStreamContext($testEnv = false, $caFile = null) - { - if ($testEnv) { - $host = $this->certificatePeerName['test']; - } else { - $host = $this->certificatePeerName['production']; - } - - $this->streamContextOption['ssl']['crypto_method'] = STREAM_CRYPTO_METHOD_TLS_CLIENT; - $this->streamContextOption['ssl']['verify_peer'] = true; - $this->streamContextOption['ssl']['SNI_enabled'] = true; - - // Disable TLS compression to prevent CRIME attacks where supported (PHP 5.4.13 or later). - if (PHP_VERSION_ID >= 50413) { - $this->streamContextOption['ssl']['disable_compression'] = true; - } - - if (PHP_VERSION_ID < 50600) { - //CN_match was deprecated in favour of peer_name in PHP 5.6 - $this->streamContextOption['ssl']['CN_match'] = $host; - $this->streamContextOption['ssl']['SNI_server_name'] = $host; - // PHP 5.6 or greater will find the system cert by default. When < 5.6, use the system ca-certificates. - if (is_null($caFile)) { - $this->streamContextOption['ssl']['cafile'] = $this->getDefaultCABundle(); - } else { - $this->streamContextOption['ssl']['cafile'] = $caFile; - } - } else { - $this->streamContextOption['ssl']['peer_name'] = $host; - $this->streamContextOption['ssl']['verify_peer_name'] = true; - } - - return stream_context_create($this->streamContextOption); - } - /** - * @return \soapClient + * {@inheritdoc} */ - public function getSoapClient() + static function getWsdlUrl($wsdlEnvironment) { - return $this->soapClient; - } - - /** - * Returns the default cacert bundle for the current system. - * - * First, the openssl.cafile and curl.cainfo php.ini settings are checked. - * If those settings are not configured, then the common locations for - * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X - * and Windows are checked. If any of these file locations are found on - * disk, they will be utilized. - * - * Note: the result of this function is cached for subsequent calls. - * - * @throws \RuntimeException if no bundle can be found. - * @return string - * - * @link https://github.com/guzzle/guzzle/blob/6.1.0/src/functions.php#L143 - */ - public function getDefaultCABundle() - { - $cafiles = array( - // Red Hat, CentOS, Fedora (provided by the ca-certificates package) - '/etc/pki/tls/certs/ca-bundle.crt', - // Ubuntu, Debian (provided by the ca-certificates package) - '/etc/ssl/certs/ca-certificates.crt', - // FreeBSD (provided by the ca_root_nss package) - '/usr/local/share/certs/ca-root-nss.crt', - // OS X provided by homebrew (using the default path) - '/usr/local/etc/openssl/cert.pem', - // Google app engine - '/etc/ca-certificates.crt', - // Windows? - 'C:\\windows\\system32\\curl-ca-bundle.crt', - 'C:\\windows\\curl-ca-bundle.crt', - ); - - if ($ca = ini_get('openssl.cafile')) { - return $ca; - } - if ($ca = ini_get('curl.cainfo')) { - return $ca; - } - foreach ($cafiles as $filename) { - if (file_exists($filename)) { - return $filename; - } - } - throw new \RuntimeException(<<< EOT -No system CA bundle could be found in any of the the common system locations. -PHP versions earlier than 5.6 are not properly configured to use the system's -CA bundle by default. Mozilla provides a commonly used CA bundle which can be -downloaded here (provided by the maintainer of cURL): -https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once -you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP -ini setting to point to the path to the file. See http://curl.haxx.se/docs/sslcerts.html -for more information. -EOT + $environments = array( + 'test' => 'https://testecomm.sella.it/gestpay/GestPayWS/WsCryptDecrypt.asmx?wsdl', + 'production' => 'https://ecomms2s.sella.it/gestpay/GestPayWS/WsCryptDecrypt.asmx?wsdl', ); + return $environments[$wsdlEnvironment]; } } diff --git a/src/WSS2S.php b/src/WSS2S.php new file mode 100644 index 0000000..e42333c --- /dev/null +++ b/src/WSS2S.php @@ -0,0 +1,46 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS; + +use EndelWar\GestPayWS\Parameter\PagamParameter; +use EndelWar\GestPayWS\Parameter\RequestTokenParameter; +use EndelWar\GestPayWS\Response\PagamResponse; +use EndelWar\GestPayWS\Response\RequestTokenResponse; + +/** + * Class WsS2S + * @package EndelWar\GestPayWS + */ +class WSS2S extends Service +{ + /** + * @param PagamParameter $parameters + * @return EncryptResponse + */ + public function pagam(PagamParameter $parameters) + { + $this->validateParameters($parameters); + $soapResponse = $this->soapClient->callPagamS2S($parameters); + return new PagamResponse($soapResponse); + } + + /** + * @param RequestTokenParameter $parameters + * @return RequestTokenResponse + */ + public function requestToken(RequestTokenParameter $parameters) + { + $this->validateParameters($parameters); + $soapResponse = $this->soapClient->callRequestTokenS2S($parameters); + return new RequestTokenResponse($soapResponse); + } +} diff --git a/src/WSS2SSoapClient.php b/src/WSS2SSoapClient.php new file mode 100644 index 0000000..558e5d1 --- /dev/null +++ b/src/WSS2SSoapClient.php @@ -0,0 +1,27 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EndelWar\GestPayWS; + +class WSS2SSoapClient extends SoapClient +{ + /** + * {@inheritdoc} + */ + static function getWsdlUrl($wsdlEnvironment) + { + $environments = array( + 'test' => 'https://testecomm.sella.it/gestpay/GestPayWS/WsS2S.asmx?wsdl', + 'production' => 'https://ecommS2S.sella.it/gestpay/GestPayWS/WsS2S.asmx?wsdl', + ); + return $environments[$wsdlEnvironment]; + } +} From dccf04ebdce57636276033e993b7d2ba80ba58aa Mon Sep 17 00:00:00 2001 From: Gregorio Magini Date: Thu, 17 Dec 2015 15:34:54 +0100 Subject: [PATCH 2/2] Fixes StyleCI analysis fails --- src/Service.php | 6 +++--- src/SoapClientInterface.php | 2 +- src/WSCryptDecryptSoapClient.php | 2 +- src/WSS2SSoapClient.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Service.php b/src/Service.php index c65e1a0..8b35b3c 100644 --- a/src/Service.php +++ b/src/Service.php @@ -34,8 +34,8 @@ public function __construct(\SoapClient $soapClient) */ protected function validateParameters(Parameter $parameters) { - if (!$parameters->areAllMandatoryParametersSet()) { - throw new \InvalidArgumentException('Missing parameter'); - } + if (!$parameters->areAllMandatoryParametersSet()) { + throw new \InvalidArgumentException('Missing parameter'); + } } } diff --git a/src/SoapClientInterface.php b/src/SoapClientInterface.php index cf7d4ce..1cabb65 100644 --- a/src/SoapClientInterface.php +++ b/src/SoapClientInterface.php @@ -22,5 +22,5 @@ interface SoapClientInterface * @param string $wsdlEnvironment Either "test" or "production" * @return string */ - static function getWsdlUrl($wsdlEnvironment); + public static function getWsdlUrl($wsdlEnvironment); } diff --git a/src/WSCryptDecryptSoapClient.php b/src/WSCryptDecryptSoapClient.php index 934aa75..e7963f9 100644 --- a/src/WSCryptDecryptSoapClient.php +++ b/src/WSCryptDecryptSoapClient.php @@ -16,7 +16,7 @@ class WSCryptDecryptSoapClient extends SoapClient /** * {@inheritdoc} */ - static function getWsdlUrl($wsdlEnvironment) + public static function getWsdlUrl($wsdlEnvironment) { $environments = array( 'test' => 'https://testecomm.sella.it/gestpay/GestPayWS/WsCryptDecrypt.asmx?wsdl', diff --git a/src/WSS2SSoapClient.php b/src/WSS2SSoapClient.php index 558e5d1..ebf56df 100644 --- a/src/WSS2SSoapClient.php +++ b/src/WSS2SSoapClient.php @@ -16,7 +16,7 @@ class WSS2SSoapClient extends SoapClient /** * {@inheritdoc} */ - static function getWsdlUrl($wsdlEnvironment) + public static function getWsdlUrl($wsdlEnvironment) { $environments = array( 'test' => 'https://testecomm.sella.it/gestpay/GestPayWS/WsS2S.asmx?wsdl',