PHP SDK

Getting Started

GitHub-Repository: https://github.com/secuconnect/secuconnect-php-sdk

Requirements

PHP

You need at least the PHP version 8.0.

We recommend to use the PHP version 8.2.

Additionally you need the following extensions for PHP:

Installing the SDK

We recommend installing SDK as dependency managed by composer:

composer require "secuconnect/secuconnect-php-sdk"

Make sure that composer auto-loading is enabled (if it isn’t already):

require_once '../vendor/autoload.php';

For more information please consult Composer documentation.

Authentication

PHP example
<?php
 
use Secuconnect\Client\ApiException;
use Secuconnect\Client\Authentication\Authenticator;
use Secuconnect\Client\Configuration;
 
require_once '../vendor/autoload.php';
 
try {
$accessToken = Authenticator::authenticateByClientCredentials(
'YOUR_CLIENT_ID',
'YOUR_CLIENT_SECRET'
);
print_r($accessToken);
/*
* Sample output:
* ==============
* fdjt28qq8qr7b0s9epcvesnq33
*/
} catch (ApiException $e) {
echo $e->getTraceAsString();
 
// show the error message from the api
   print_r($e->getResponseBody());
 
$supportId = '';
if (isset($e->getResponseBody()->supportId)) {
$supportId = ' Support-ID: ' . $e->getResponseBody()->supportId;
}
 
echo 'Request was not successful, check the log for details.' . $supportId;
/*
* Sample output:
* ==============
* stdClass Object
* (
*    [error] => invalid_client
*    [error_description] => The client credentials are invalid
* )
* Request was not successful, check the log for details.
*/
}

Configuration

Cache

SDK will use cache to store authentication tokens for further API calls. By default it will use temporary files on the server that made request.

SDK can use any other PSR-6 compliant cache solution, like https://github.com/symfony/cache to store it in a database or in redis to share f.e. it in a cluster environment:

\Secuconnect\Client\Configuration::getDefaultConfiguration()->setCache($yourPSR6cacheInstance);

For more information please consult https://www.php-fig.org/psr/psr-6/

Live

To switch to the live environment it is necessary to change the URLs of the API endpoints, before starting the authentication:

\Secuconnect\Client\Configuration::getDefaultConfiguration()->setHost('https://connect.secucard.com/api/v2');
\Secuconnect\Client\Configuration::getDefaultConfiguration()->setAuthHost('https://connect.secucard.com/');