TypeError: Cannot access offset of type array in isset or empty in file /vendor/worldline-global-collect/connect-sdk-php/lib/Worldline/Connect/Sdk/Webhooks/InMemorySecretKeyStore.php on line 31
In the InMemorySecretKeyStore
class, there could be a potential issue when $keyId
is passed as an array. The current implementation tries to access $this->secretKeys[$keyId]
directly, which would cause an error if $keyId
is an array.
A possible solution would be to check if $keyId
is an array and handle it accordingly. Here's a proposed change to the getSecretKey
method:
public function getSecretKey($keyId)
{
if (is_array($keyId)) {
$keyId = $keyId[0];
}
if (!isset($this->secretKeys[$keyId]) || is_null($this->secretKeys[$keyId])) {
throw new SecretKeyNotAvailableException($keyId, "could not find secret key for key id $keyId");
}
return $this->secretKeys[$keyId];
}
In the SignatureValidator
class, there could be a potential issue when $signature
is passed as an array. The current implementation tries to compare $signature
directly, which would cause an error if $signature
is an array.
private function areEqualSignatures($signature, $expectedSignature)
{
if (is_array($signature)) {
$signature = $signature[0];
}
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;
}
}
}
The Worldline Connect PHP SDK helps you to communicate with the Worldline Connect Server API. Its primary features are:
- convenient PHP wrapper around the API calls and responses:
- marshalls PHP request objects to HTTP requests
- unmarshalls HTTP responses to PHP response objects or PHP exceptions
- handling of all the details concerning authentication
- handling of required metadata
Its use is demonstrated by an example for most calls. The examples execute a call using the provided API keys.
See the Worldline Connect Developer Hub for more information on how to use the SDK.
This repository consists out of the following components:
- The source code of the SDK itself:
/src
and/lib
- The source code of the unit and integration tests (including the examples):
/tests
PHP 5.4 or above is required. In addition, to support streaming uploads, package robtimus/multipart is required.
-
Initialize Composer in your project, if this is not already done, by executing the following command:
composer init
-
Add a requirement to the SDK to your
composer.json
file by executing the following command:composer require worldline-global-collect/connect-sdk-php
-
Add
vendor/autoload.php
to your project, if this is not already done, by adding the following line of code:require __DIR__ . '/vendor/autoload.php';
- Download the latest version of the PHP SDK from GitHub. Choose the
connect-sdk-php-x.y.z.tar.gz
file from the releases page, wherex.y.z
is the version number. - Add the contents of the
tar.gz
file to your project. The content of the/src
and/lib
folders may be combined, if this is required by the project. - Add all classes from the
/src
and/lib
folders to your autoloader; all classes inside these folders are compliant with PSR-4.
- Install Composer
- From the root of the sdk-php project, run
composer install
- Copy
tests/config.json.dist
totests/config.json
and replace the template values by actual values - From the root of the sdk-php project,
vendor/phpunit/phpunit/phpunit
(or justphpunit
when it is already installed on your local machine)