Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Release 6.46.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
IngenicoEPayments committed Jan 16, 2024
1 parent 959c911 commit ef1ac4e
Show file tree
Hide file tree
Showing 412 changed files with 563 additions and 471 deletions.
72 changes: 56 additions & 16 deletions lib/Ingenico/Connect/Sdk/Communicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function disableLogging()
* @param string $clientMetaInfo
* @param RequestObject|null $requestParameters
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @return DataObject
* @throws Exception
*/
Expand All @@ -67,7 +68,8 @@ public function get(
$relativeUriPath,
$clientMetaInfo = '',
RequestObject $requestParameters = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand All @@ -93,7 +95,10 @@ public function get(
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
$httpStatusCode = $connectionResponse->getHttpStatusCode();
if ($httpStatusCode >= 400) {
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
return $response;
}
Expand All @@ -105,6 +110,7 @@ public function get(
* @param RequestObject|null $requestParameters
* @param callable $bodyHandler Callable accepting a response body chunk and the response headers
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @throws Exception
*/
public function getWithBinaryResponse(
Expand All @@ -113,7 +119,8 @@ public function getWithBinaryResponse(
$clientMetaInfo = '',
RequestObject $requestParameters = null,
callable $bodyHandler = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand Down Expand Up @@ -143,7 +150,10 @@ public function getWithBinaryResponse(
if ($httpStatusCode >= 400) {
$response =
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
}

Expand All @@ -153,6 +163,7 @@ public function getWithBinaryResponse(
* @param string $clientMetaInfo
* @param RequestObject|null $requestParameters
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @return DataObject
* @throws Exception
*/
Expand All @@ -161,7 +172,8 @@ public function delete(
$relativeUriPath,
$clientMetaInfo = '',
RequestObject $requestParameters = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand All @@ -187,7 +199,10 @@ public function delete(
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
$httpStatusCode = $connectionResponse->getHttpStatusCode();
if ($httpStatusCode >= 400) {
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
return $response;
}
Expand All @@ -199,6 +214,7 @@ public function delete(
* @param RequestObject|null $requestParameters
* @param callable $bodyHandler Callable accepting a response body chunk and the response headers
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @throws Exception
*/
public function deleteWithBinaryResponse(
Expand All @@ -207,7 +223,8 @@ public function deleteWithBinaryResponse(
$clientMetaInfo = '',
RequestObject $requestParameters = null,
callable $bodyHandler = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand Down Expand Up @@ -237,7 +254,10 @@ public function deleteWithBinaryResponse(
if ($httpStatusCode >= 400) {
$response =
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
}

Expand All @@ -248,6 +268,7 @@ public function deleteWithBinaryResponse(
* @param DataObject|MultipartDataObject|null $requestBodyObject
* @param RequestObject|null $requestParameters
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @return DataObject
* @throws Exception
*/
Expand All @@ -257,7 +278,8 @@ public function post(
$clientMetaInfo = '',
$requestBodyObject = null,
RequestObject $requestParameters = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand Down Expand Up @@ -297,7 +319,10 @@ public function post(
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
$httpStatusCode = $connectionResponse->getHttpStatusCode();
if ($httpStatusCode >= 400) {
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
return $response;
}
Expand All @@ -310,6 +335,7 @@ public function post(
* @param RequestObject|null $requestParameters
* @param callable $bodyHandler Callable accepting a response body chunk and the response headers
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @throws Exception
*/
public function postWithBinaryResponse(
Expand All @@ -319,7 +345,8 @@ public function postWithBinaryResponse(
$requestBodyObject = null,
RequestObject $requestParameters = null,
callable $bodyHandler = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand Down Expand Up @@ -363,7 +390,10 @@ public function postWithBinaryResponse(
if ($httpStatusCode >= 400) {
$response =
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
}

Expand All @@ -374,6 +404,7 @@ public function postWithBinaryResponse(
* @param DataObject|MultipartDataObject|null $requestBodyObject
* @param RequestObject|null $requestParameters
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @return DataObject
* @throws Exception
*/
Expand All @@ -383,7 +414,8 @@ public function put(
$clientMetaInfo = '',
$requestBodyObject = null,
RequestObject $requestParameters = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand Down Expand Up @@ -423,7 +455,10 @@ public function put(
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
$httpStatusCode = $connectionResponse->getHttpStatusCode();
if ($httpStatusCode >= 400) {
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
return $response;
}
Expand All @@ -436,6 +471,7 @@ public function put(
* @param RequestObject|null $requestParameters
* @param callable $bodyHandler Callable accepting a response body chunk and the response headers
* @param CallContext $callContext
* @param ResponseExceptionFactory|null $responseExceptionFactory
* @throws Exception
*/
public function putWithBinaryResponse(
Expand All @@ -445,7 +481,8 @@ public function putWithBinaryResponse(
$requestBodyObject = null,
RequestObject $requestParameters = null,
callable $bodyHandler = null,
CallContext $callContext = null
CallContext $callContext = null,
ResponseExceptionFactory $responseExceptionFactory = null
) {
$relativeUriPathWithRequestParameters =
$this->getRelativeUriPathWithRequestParameters($relativeUriPath, $requestParameters);
Expand Down Expand Up @@ -489,7 +526,10 @@ public function putWithBinaryResponse(
if ($httpStatusCode >= 400) {
$response =
$this->getResponseFactory()->createResponse($connectionResponse, $responseClassMap);
throw $this->getResponseExceptionFactory()->createException($httpStatusCode, $response, $callContext);
if (is_null($responseExceptionFactory)) {
$responseExceptionFactory = $this->getResponseExceptionFactory();
}
throw $responseExceptionFactory->createException($httpStatusCode, $response, $callContext);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Ingenico/Connect/Sdk/RequestHeaderGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class RequestHeaderGenerator
{
const SDK_VERSION = '6.45.0';
const SDK_VERSION = '6.46.0';

const AUTHORIZATION_ID = 'GCS';

Expand Down
76 changes: 76 additions & 0 deletions lib/Ingenico/Connect/Sdk/Webhooks/SignatureValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
namespace Ingenico\Connect\Sdk\Webhooks;

/**
* Class SignatureValidator
*
* @package Ingenico\Connect\Sdk\Webhooks
*/
class SignatureValidator
{
/** @var SecretKeyStore */
private $secretKeyStore;

/**
* @param SecretKeyStore $secretKeyStore
*/
public function __construct(SecretKeyStore $secretKeyStore)
{
$this->secretKeyStore = $secretKeyStore;
}

/**
* Validates the given body using the given request headers.
* @param string $body
* @param array $requestHeaders
* @throws SignatureValidationException
*/
public function validate($body, $requestHeaders)
{
$this->validateBody($body, $requestHeaders);
}

// utility methods

private function validateBody($body, $requestHeaders)
{
$signature = $this->getHeaderValue($requestHeaders, 'X-GCS-Signature');
$keyId = $this->getHeaderValue($requestHeaders, 'X-GCS-KeyId');
$secretKey = $this->secretKeyStore->getSecretKey($keyId);

$expectedSignature = base64_encode(hash_hmac("sha256", $body, $secretKey, true));

$isValid = $this->areEqualSignatures($signature, $expectedSignature);
if (!$isValid) {
throw new SignatureValidationException("failed to validate signature '$signature'");
}
}

private function areEqualSignatures($signature, $expectedSignature) {
if (function_exists('hash_equals')) {
return hash_equals($expectedSignature, $signature);
} else {
// copied from http://php.net/manual/en/function.hash-equals.php#115635
if(strlen($expectedSignature) != strlen($signature)) {
return false;
} else {
$res = $expectedSignature ^ $signature;
$ret = 0;
for($i = strlen($res) - 1; $i >= 0; $i--) $ret |= ord($res[$i]);
return !$ret;
}
}
}

// general utility methods

private function getHeaderValue($requestHeaders, $headerName) {
$lowerCaseHeaderName = strtolower($headerName);
foreach ($requestHeaders as $name => $value) {
if ($lowerCaseHeaderName === strtolower($name)) {
return $value;
}
}
throw new SignatureValidationException("could not find header '$headerName'");
}
}
Loading

0 comments on commit ef1ac4e

Please sign in to comment.