diff --git a/CHANGELOG.md b/CHANGELOG.md index 7933b628..87ac2d86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.15.0 + +- [add]: Add `soft_descriptor` property to Order Requests +- [add]: Add internal `data_id` property + ## Version 2.14.1 - [fix]: fix tag diff --git a/composer.json b/composer.json index 23678bb6..b8889710 100644 --- a/composer.json +++ b/composer.json @@ -1,47 +1,53 @@ { - "name": "hipay/hipay-fullservice-sdk-php", - "type": "library", - "minimum-stability": "stable", - "description": "The HiPay Enterprise SDK for PHP is a library for developers who want to integrate HiPay Enterprise payment methods to any PHP platform.", - "keywords": [ - "hipay", - "payment", - "payment method" - ], - "scripts": { - "test": "phpunit -c tests/phpunit.xml --testsuite unit,integration", - "lint": "phpcs -p --standard=PHPCompatibility lib/ tests/" - }, - "homepage": "https://hipay.com/product-enterprise/", - "version": "2.14.1", - "license": "Apache-2.0", - "authors": [ - { - "name": "HiPay", - "homepage": "http://www.hipay.com", - "email": "support.tpp@hipay.com" + "name": "hipay/hipay-fullservice-sdk-php", + "type": "library", + "minimum-stability": "stable", + "description": "The HiPay Enterprise SDK for PHP is a library for developers who want to integrate HiPay Enterprise payment methods to any PHP platform.", + "keywords": [ + "hipay", + "payment", + "payment method" + ], + "scripts": { + "test": "phpunit -c tests/phpunit.xml --testsuite unit,integration", + "lint": "phpcs -p --standard=PHPCompatibility lib/ tests/" + }, + "homepage": "https://hipay.com/product-enterprise/", + "version": "2.15.0", + "license": "Apache-2.0", + "authors": [ + { + "name": "HiPay", + "homepage": "http://www.hipay.com", + "email": "support.tpp@hipay.com" + } + ], + "support": { + "email": "support.tpp@hipay.com" + }, + "require": { + "php": ">=7.2", + "ext-curl": "*", + "ext-json": "*", + "ramsey/uuid": "^3.9.7" + }, + "require-dev": { + "phpunit/phpunit": "9.6", + "phpstan/phpstan": "0.*", + "phpcompatibility/php-compatibility": "^9.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "friendsofphp/php-cs-fixer": "^3.2", + "vlucas/phpdotenv": "^4.2.1", + "yoast/phpunit-polyfills": "^1.0" + }, + "autoload": { + "psr-4": { + "HiPay\\Fullservice\\": "lib/HiPay/Fullservice/" + } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } - ], - "support": { - "email": "support.tpp@hipay.com" - }, - "require": { - "php": ">=7.2", - "ext-curl": "*", - "ext-json": "*" - }, - "require-dev": { - "phpunit/phpunit": "9.6", - "phpstan/phpstan": "0.*", - "phpcompatibility/php-compatibility": "^9.3", - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", - "friendsofphp/php-cs-fixer": "^3.2", - "vlucas/phpdotenv": "^4.2.1", - "yoast/phpunit-polyfills": "^1.0" - }, - "autoload": { - "psr-4": { - "HiPay\\Fullservice\\": "lib/HiPay/Fullservice/" - } - } } diff --git a/lib/HiPay/Fullservice/Gateway/Client/GatewayClient.php b/lib/HiPay/Fullservice/Gateway/Client/GatewayClient.php index 0321754d..7e2d8776 100644 --- a/lib/HiPay/Fullservice/Gateway/Client/GatewayClient.php +++ b/lib/HiPay/Fullservice/Gateway/Client/GatewayClient.php @@ -131,13 +131,11 @@ public function __construct(ClientProvider $clientProvider) * * @see \HiPay\Fullservice\Gateway\Client\GatewayClientInterface::requestNewOrder() */ - public function requestNewOrder(OrderRequest $orderRequest) + public function requestNewOrder(OrderRequest $orderRequest, $dataId = null) { // Handle additionnal data management $piDataClient = new PIDataClient($this->getClientProvider()); - $piDataId = $piDataClient->getDataId(array( - 'device_fingerprint' => $orderRequest->device_fingerprint, - 'url_accept' => $orderRequest->accept_url)); + $piDataId = $piDataClient->getDataId($dataId); //Get params array from serializer $params = $this->_serializeRequestToArray($orderRequest); @@ -166,10 +164,11 @@ public function requestNewOrder(OrderRequest $orderRequest) * * @see \HiPay\Fullservice\Gateway\Client\GatewayClientInterface::requestHostedPaymentPage() */ - public function requestHostedPaymentPage(HostedPaymentPageRequest $pageRequest) + public function requestHostedPaymentPage(HostedPaymentPageRequest $pageRequest, $dataId = null) { // Handle additionnal data management $piDataClient = new PIDataClient($this->getClientProvider()); + $piDataId = $piDataClient->getDataId($dataId); if ($this->getClientProvider()->getConfiguration()->isOverridePaymentProductSorting()) { $pageRequest->reorderPaymentProductList(); @@ -183,7 +182,10 @@ public function requestHostedPaymentPage(HostedPaymentPageRequest $pageRequest) $response = $this->getClientProvider()->request( self::METHOD_HOSTED_PAYMENT_PAGE, self::ENDPOINT_HOSTED_PAYMENT_PAGE, - $params + $params, + array( + 'X-HIPAY-DATA-ID: ' . $piDataId + ) ); //Transform response to HostedPaymentPage Model with HostedPaymentPageMapper @@ -193,10 +195,6 @@ public function requestHostedPaymentPage(HostedPaymentPageRequest $pageRequest) */ $hostedPagePayment = $mapper->getModelObjectMapped(); - $piDataId = $piDataClient->getDataId(array( - 'forward_url' => $hostedPagePayment->getForwardUrl() - )); - if ($piDataId) { $piDataClient->sendData($piDataClient->getHPaymentData($piDataId, $pageRequest, $hostedPagePayment)); } diff --git a/lib/HiPay/Fullservice/Gateway/Client/GatewayClientInterface.php b/lib/HiPay/Fullservice/Gateway/Client/GatewayClientInterface.php index 6e3449ad..20ecd0c8 100644 --- a/lib/HiPay/Fullservice/Gateway/Client/GatewayClientInterface.php +++ b/lib/HiPay/Fullservice/Gateway/Client/GatewayClientInterface.php @@ -40,9 +40,10 @@ interface GatewayClientInterface /** * Request a new order * @param OrderRequest $orderRequest + * @param string $dataId * @return Transaction $transaction */ - public function requestNewOrder(OrderRequest $orderRequest); + public function requestNewOrder(OrderRequest $orderRequest, $dataId = null); /** * Request Maintenance operation on a transaction @@ -67,9 +68,10 @@ public function requestMaintenanceOperation( /** * Request Hosted Payment Page * @param HostedPaymentPageRequest $hppRequest + * @param string $dataId * @return HostedPaymentPage $hpp */ - public function requestHostedPaymentPage(HostedPaymentPageRequest $hppRequest); + public function requestHostedPaymentPage(HostedPaymentPageRequest $hppRequest, $dataId = null); /** * Get Transaction information diff --git a/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClient.php b/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClient.php index f8715d21..b7394670 100644 --- a/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClient.php +++ b/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClient.php @@ -24,6 +24,8 @@ use HiPay\Fullservice\Gateway\Request\Order\OrderRequest; use HiPay\Fullservice\HTTP\ClientProvider; +use Ramsey\Uuid\Uuid; + /** * Client class for all request send to the Data API. * @@ -87,6 +89,7 @@ public function sendData($data) self::METHOD_DATA_API, self::ENDPOINT_DATA_API, $data, + [], false, true ); @@ -187,29 +190,19 @@ private function getCommonData($dataId, OrderRequest $request) /** * {@inheritDoc} * - * $params must contain a 'device_fingerprint' key with the associated value or a 'forward_url' key with the associated value - * Computation is a sha256 of device_fingerprint:host_domain or a sha256 of the forward_url if present + * Gets data id from Configuration, or creates a new UUID to act as one if no uuid is in Configuration * * @see \HiPay\Fullservice\Gateway\PIDataClient\PIDataClientInterface::initDataFromOrder() * - * @param array$params * @return false|string */ - public function getDataId(array $params) + public function getDataId($dataId = null) { - if (!empty($params['forward_url'])) { - return hash('sha256', $params['forward_url']); - } elseif (!empty($params['device_fingerprint'])) { - $params['url_accept'] = empty($params['url_accept']) ? null : $params['url_accept']; - - // Cleaning the domain from http(s) tag, www tag, any path and ports - $domain = $this->getDomain($this->getHost($params['url_accept'])); - $fingerprint = $params['device_fingerprint']; - - return hash('sha256', $fingerprint . ':' . $domain); - } else { - return false; + if(empty($dataId)) { + $dataId = Uuid::uuid4()->toString(); } + + return $dataId; } /** diff --git a/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClientInterface.php b/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClientInterface.php index b479b058..38701b16 100644 --- a/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClientInterface.php +++ b/lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClientInterface.php @@ -67,9 +67,9 @@ public function getOrderData($dataId, OrderRequest $orderRequest, AbstractTransa public function getHPaymentData($dataId, HostedPaymentPageRequest $orderRequest, HostedPaymentPage $transaction); /** - * Compute a data id from params - * @param array $params + * Compute a data id + * @param string|null $dataId Existing data ID * @return string */ - public function getDataId(array $params); + public function getDataId($dataId); } diff --git a/lib/HiPay/Fullservice/Gateway/Request/Order/OrderRequest.php b/lib/HiPay/Fullservice/Gateway/Request/Order/OrderRequest.php index bbf2964c..1df8d1e9 100644 --- a/lib/HiPay/Fullservice/Gateway/Request/Order/OrderRequest.php +++ b/lib/HiPay/Fullservice/Gateway/Request/Order/OrderRequest.php @@ -246,4 +246,11 @@ class OrderRequest extends CommonRequest * @var integer $expiration_limit */ public $expiration_limit; + + /** + * Billing descriptor for machine learning + * + * @var string + */ + public $soft_descriptor; } diff --git a/lib/HiPay/Fullservice/HTTP/Client.php b/lib/HiPay/Fullservice/HTTP/Client.php index 5df89dcf..3a49462a 100755 --- a/lib/HiPay/Fullservice/HTTP/Client.php +++ b/lib/HiPay/Fullservice/HTTP/Client.php @@ -41,6 +41,7 @@ interface Client * @param string $method HTTP method * @param string $endpoint Api Endpoint for this request. Base url is determined by Configuration Object * @param array $params Request params to apply. + * @param array $additionalHeaders * @param bool $isVault If true, perform request on secure vault endpoint * @param bool $isData If true, perform request on HiPay data API * @@ -48,5 +49,5 @@ interface Client * @throws \HiPay\Fullservice\Exception\InvalidArgumentException * @return \HiPay\Fullservice\HTTP\Response\AbstractResponse */ - public function request($method, $endpoint, array $params = array(), $isVault = false, $isData = false); + public function request($method, $endpoint, array $params = array(), array $additionalHeaders = array(), $isVault = false, $isData = false); } diff --git a/lib/HiPay/Fullservice/HTTP/ClientProvider.php b/lib/HiPay/Fullservice/HTTP/ClientProvider.php index 5f7b7611..b909b793 100755 --- a/lib/HiPay/Fullservice/HTTP/ClientProvider.php +++ b/lib/HiPay/Fullservice/HTTP/ClientProvider.php @@ -15,7 +15,6 @@ namespace HiPay\Fullservice\HTTP; -use CurlHandle; use HiPay\Fullservice\HTTP\Configuration\ConfigurationInterface; use HiPay\Fullservice\HTTP\Response\AbstractResponse; @@ -83,14 +82,15 @@ public function __construct(ConfigurationInterface $configuration) * @param string $method * @param string $endpoint * @param array $params + * @param array $additionalHeaders * @param bool $isVault * @param bool $isData * * @return AbstractResponse */ - public function request($method, $endpoint, array $params = array(), $isVault = false, $isData = false) + public function request($method, $endpoint, array $params = array(), array $additionalHeaders = array(), $isVault = false, $isData = false) { - return $this->doRequest($method, $endpoint, $params, $isVault, $isData); + return $this->doRequest($method, $endpoint, $params, $additionalHeaders, $isVault, $isData); } /** @@ -127,6 +127,7 @@ public function getHttpClient() * @param string $method HTTP method * @param string $endpoint Endpoint * @param array $params Params to send + * @param array $additionalHeaders * @param bool $isVault Secure vault action * @param bool $isData Special PI Data call * @@ -134,7 +135,7 @@ public function getHttpClient() * @throws \HiPay\Fullservice\Exception\InvalidArgumentException * @return \HiPay\Fullservice\HTTP\Response\AbstractResponse */ - abstract protected function doRequest($method, $endpoint, array $params = array(), $isVault = false, $isData = false); + abstract protected function doRequest($method, $endpoint, array $params = array(), array $additionalHeaders = array(), $isVault = false, $isData = false); /** * Create local http client object used in doRequest method diff --git a/lib/HiPay/Fullservice/HTTP/Configuration/Configuration.php b/lib/HiPay/Fullservice/HTTP/Configuration/Configuration.php index e52cffdf..468e78f7 100755 --- a/lib/HiPay/Fullservice/HTTP/Configuration/Configuration.php +++ b/lib/HiPay/Fullservice/HTTP/Configuration/Configuration.php @@ -599,6 +599,7 @@ public function setHostedPageV2($hostedPageV2) $this->_hostedPageV2 = $hostedPageV2; } + /** * Construct configuration object. * diff --git a/lib/HiPay/Fullservice/HTTP/SimpleHTTPClient.php b/lib/HiPay/Fullservice/HTTP/SimpleHTTPClient.php index 87553fb6..21ec8e87 100755 --- a/lib/HiPay/Fullservice/HTTP/SimpleHTTPClient.php +++ b/lib/HiPay/Fullservice/HTTP/SimpleHTTPClient.php @@ -45,11 +45,12 @@ class SimpleHTTPClient extends ClientProvider * @param string $method * @param string $endpoint * @param array $params + * @param array $additionalHeaders * @param bool $isVault * @param bool $isData * @return AbstractResponse */ - protected function doRequest($method, $endpoint, array $params = array(), $isVault = false, $isData = false) + protected function doRequest($method, $endpoint, array $params = array(), array $additionalHeaders = array(), $isVault = false, $isData = false) { if (empty($method) || !is_string($method)) { throw new InvalidArgumentException("HTTP METHOD must a string and a valid HTTP METHOD Value"); @@ -93,10 +94,10 @@ protected function doRequest($method, $endpoint, array $params = array(), $isVau $options = array( CURLOPT_URL => $finalUrl, CURLOPT_USERPWD => $credentials, - CURLOPT_HTTPHEADER => array( + CURLOPT_HTTPHEADER => array_merge($additionalHeaders, array( 'Accept: ' . $this->getConfiguration()->getApiHTTPHeaderAccept(), 'User-Agent: ' . $userAgent - ), + )), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => false, CURLOPT_HEADER => false, diff --git a/lib/HiPay/Fullservice/SecureVault/Client/SecureVaultClient.php b/lib/HiPay/Fullservice/SecureVault/Client/SecureVaultClient.php index d001169a..2da9fac9 100644 --- a/lib/HiPay/Fullservice/SecureVault/Client/SecureVaultClient.php +++ b/lib/HiPay/Fullservice/SecureVault/Client/SecureVaultClient.php @@ -72,7 +72,7 @@ public function requestLookupToken($token, $requestId = '0') $endPoint .= '?request_id=' . $requestId; $response = $this->getClientProvider() - ->request(self::METHOD_LOOKUP_TOKEN, $endPoint, array(), true); + ->request(self::METHOD_LOOKUP_TOKEN, $endPoint, array(), array(), true); $pctMapper = new PaymentCardTokenMapper($response->toArray()); diff --git a/tests/Unit/HiPay/Tests/Fullservice/Gateway/PIDataClient/PIDataClientTest.php b/tests/Unit/HiPay/Tests/Fullservice/Gateway/PIDataClient/PIDataClientTest.php index ef848755..4bc3d507 100644 --- a/tests/Unit/HiPay/Tests/Fullservice/Gateway/PIDataClient/PIDataClientTest.php +++ b/tests/Unit/HiPay/Tests/Fullservice/Gateway/PIDataClient/PIDataClientTest.php @@ -77,21 +77,14 @@ public function testCanBeConstructUsingClientProvider() * @cover HiPay\Fullservice\Gateway\PIDataClient\PIDataClient::getDataId * @depends testCanBeConstructUsingClientProvider * @param PIDataClient $dataClient - * @return string */ - public function testGetDataIdForOrder(PIDataClient $dataClient) + public function testGetPredefinedDataId(PIDataClient $dataClient) { - $deviceFingerprint = "I AM THE DEVICE"; - $domainName = "i-am-the-domain-name.com"; - - $_SERVER['HTTP_HOST'] = "www." . $domainName . ":8085"; - - $trueId = hash('sha256', $deviceFingerprint . ':' . $domainName); + $expectedDataId = uniqid(); - $this->assertNotEquals($trueId, $dataClient->getDataId(array('forward_url' => $deviceFingerprint))); - $this->assertEquals($trueId, $dataClient->getDataId(array('device_fingerprint' => $deviceFingerprint))); + $dataId = $dataClient->getDataId($expectedDataId); - return $trueId; + $this->assertEquals($expectedDataId, $dataId); } /** @@ -100,26 +93,21 @@ public function testGetDataIdForOrder(PIDataClient $dataClient) * @param PIDataClient $dataClient * @return string */ - public function testGetDataIdForHPayment(PIDataClient $dataClient) + public function testGetEmptyDataId(PIDataClient $dataClient) { - $forwardUrl = "http://forward.me/132468453fs465v15ds4f6s"; - $domainName = "i-am-the-domain-name.com"; - - $_SERVER['HTTP_HOST'] = "www." . $domainName . ":8085"; + $uuidFormat = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'; - $trueId = hash('sha256', $forwardUrl); + $dataId = $dataClient->getDataId(); - $this->assertNotEquals($trueId, $dataClient->getDataId(array('device_fingerprint' => $forwardUrl))); - $this->assertEquals($trueId, $dataClient->getDataId(array('forward_url' => $forwardUrl))); + $this->assertMatchesRegularExpression($uuidFormat, $dataId); - return $trueId; + return $dataId; } - /** * @cover HiPay\Fullservice\Gateway\PIDataClient\PIDataClient::getOrderData * @depends testCanBeConstructUsingClientProvider - * @depends testGetDataIdForOrder + * @depends testGetEmptyDataId */ public function testGetOrderData(PIDataClient $dataClient, $dataId) { @@ -199,7 +187,7 @@ public function testGetOrderData(PIDataClient $dataClient, $dataId) /** * @cover HiPay\Fullservice\Gateway\PIDataClient\PIDataClient::getHPaymentData * @depends testCanBeConstructUsingClientProvider - * @depends testGetDataIdForHPayment + * @depends testGetEmptyDataId */ public function testGetHPaymentData(PIDataClient $dataClient, $dataId) { diff --git a/tests/Unit/HiPay/Tests/Fullservice/HTTP/SimpleHTTPClientTest.php b/tests/Unit/HiPay/Tests/Fullservice/HTTP/SimpleHTTPClientTest.php index c5a70755..fa40368b 100755 --- a/tests/Unit/HiPay/Tests/Fullservice/HTTP/SimpleHTTPClientTest.php +++ b/tests/Unit/HiPay/Tests/Fullservice/HTTP/SimpleHTTPClientTest.php @@ -249,7 +249,7 @@ public function testHttpSuccessVaultRequest() $mock = $this->createMock(Configuration::class); $mock->method('getSecureVaultEndpoint')->willReturn('http://www.mocky.io'); $client = new SimpleHTTPClient($mock); - $response = $client->request('GET', "/v2/5d026cd63100002900ab2f83", array(), true); + $response = $client->request('GET', "/v2/5d026cd63100002900ab2f83", array(), array(), true); $this->assertInstanceOf('\HiPay\Fullservice\HTTP\Response\AbstractResponse', $response); }