Skip to content

Commit

Permalink
Merge branch 'release/2.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
JBaptisteLvt committed Sep 8, 2023
2 parents ea36382 + 8bd675b commit 1a90e83
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 108 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
94 changes: 50 additions & 44 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
"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": "[email protected]"
}
],
"support": {
"email": "[email protected]"
},
"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": "[email protected]"
},
"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/"
}
}
}
18 changes: 8 additions & 10 deletions lib/HiPay/Fullservice/Gateway/Client/GatewayClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 9 additions & 16 deletions lib/HiPay/Fullservice/Gateway/PIDataClient/PIDataClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -87,6 +89,7 @@ public function sendData($data)
self::METHOD_DATA_API,
self::ENDPOINT_DATA_API,
$data,
[],
false,
true
);
Expand Down Expand Up @@ -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<string, mixed>$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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $params
* Compute a data id
* @param string|null $dataId Existing data ID
* @return string
*/
public function getDataId(array $params);
public function getDataId($dataId);
}
7 changes: 7 additions & 0 deletions lib/HiPay/Fullservice/Gateway/Request/Order/OrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion lib/HiPay/Fullservice/HTTP/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ interface Client
* @param string $method HTTP method
* @param string $endpoint Api Endpoint for this request. Base url is determined by Configuration Object
* @param array<string, mixed> $params Request params to apply.
* @param array<int, string> $additionalHeaders
* @param bool $isVault If true, perform request on secure vault endpoint
* @param bool $isData If true, perform request on HiPay data API
*
* @throws \HiPay\Fullservice\Exception\RuntimeException
* @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);
}
9 changes: 5 additions & 4 deletions lib/HiPay/Fullservice/HTTP/ClientProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace HiPay\Fullservice\HTTP;

use CurlHandle;
use HiPay\Fullservice\HTTP\Configuration\ConfigurationInterface;
use HiPay\Fullservice\HTTP\Response\AbstractResponse;

Expand Down Expand Up @@ -83,14 +82,15 @@ public function __construct(ConfigurationInterface $configuration)
* @param string $method
* @param string $endpoint
* @param array<string, mixed> $params
* @param array<int, string> $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);
}

/**
Expand Down Expand Up @@ -127,14 +127,15 @@ public function getHttpClient()
* @param string $method HTTP method
* @param string $endpoint Endpoint
* @param array<string, mixed> $params Params to send
* @param array<int, string> $additionalHeaders
* @param bool $isVault Secure vault action
* @param bool $isData Special PI Data call
*
* @throws \HiPay\Fullservice\Exception\RuntimeException
* @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
Expand Down
1 change: 1 addition & 0 deletions lib/HiPay/Fullservice/HTTP/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ public function setHostedPageV2($hostedPageV2)
$this->_hostedPageV2 = $hostedPageV2;
}


/**
* Construct configuration object.
*
Expand Down
7 changes: 4 additions & 3 deletions lib/HiPay/Fullservice/HTTP/SimpleHTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ class SimpleHTTPClient extends ClientProvider
* @param string $method
* @param string $endpoint
* @param array<string, mixed> $params
* @param array<int, string> $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");
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Loading

0 comments on commit 1a90e83

Please sign in to comment.