fiskaly/fiskaly-sdk-php

This package is abandoned and no longer maintained. No replacement package was suggested.

fiskaly Cloud-TSE SDK for PHP

1.2.200 2021-05-12 16:38 UTC

This package is auto-updated.

Last update: 2022-12-12 20:33:37 UTC


README

The fiskaly SDK includes an HTTP client that is needed1 for accessing the kassensichv.io API that implements a cloud-based, virtual CTSS (Certified Technical Security System) / TSE (Technische Sicherheitseinrichtung) as defined by the German KassenSichV (Kassen­sich­er­ungsver­ord­nung).

Supported Versions

  • PHP 7.1+

Features

  • Automatic authentication handling (fetch/refresh JWT and re-authenticate upon 401 errors).
  • Automatic retries on failures (server errors or network timeouts/issues).
  • Automatic JSON parsing and serialization of request and response bodies.
  • Future: [1] compliance regarding BSI CC-PP-0105-2019 which mandates a locally executed SMA component for creating signed log messages.
  • Future: Automatic offline-handling (collection and documentation according to Anwendungserlass zu § 146a AO)

Integration

Composer

The PHP SDK is available for a download via Composer.

Packagist - Package Repository.

Simply execute this command from the shell in your project directory:

$ composer require fiskaly/fiskaly-sdk-php

Or you can manually add the package to your composer.json file:

"require": {
    "fiskaly/fiskaly-sdk-php": "*"
}

then run

$ composer install 

Finally, be sure to include the autoloader in your code:

<?php
require_once('vendor/autoload.php');

Service

Additionally, to the SDK, you'll also need the fiskaly service. Follow these steps to integrate it into your project:

  1. Go to https://developer.fiskaly.com/downloads#service
  2. Download the appropriate service build for your platform
  3. Start the service

Usage

Demo

<?php
require __DIR__ . '\\vendor\\autoload.php';
use FiskalyClient\FiskalyClient;

/** initialize the fiskaly API client class using credentials */
try {
    $client = FiskalyClient::createUsingCredentials('http://localhost:8080/invoke', $_ENV["FISKALY_API_KEY"], $_ENV["FISKALY_API_SECRET"], 'https://kassensichv.io/api/v1');
} catch (Exception $e) {
    exit($e);
}
/** get version of client and SMAERS */
try {
    $version = $client->getVersion();
    echo "Version: ", $version, "\n\n";
} catch (Exception $e) {
    exit($e);
}

Another way to create FiskalyClient object is using context string. You can get it via getContext method and save it in memory via $_SESSION variable or persistent in cache or database.

<?php
/** initialize the fiskaly API client class using context */
try {
    $client = FiskalyClient::createUsingContext('http://localhost:8080/invoke', $_SESSION["FISKALY_CONTEXT"]);
} catch (Exception $e) {
    exit($e);
}

Client Configuration

The SDK is built on the fiskaly Client which can be configured through the SDK.

A reason why you would do this, is to enable the debug mode.

Enabling the debug mode

The following code snippet demonstrates how to enable the debug mode in the client.

<?php
/** configure client */
try {
    $config_params = array(
        'debug_level' => 4,
        'debug_file' =>  __DIR__ . '../../fiskaly.log',
        'client_timeout' =>  5000,
        'smaers_timeout' =>  2000,
    );
    $config = $client->configure($config_params);
    echo "Configuration: ", $config, "\n\n";
} catch (Exception $e) {
    exit($e);
}

Related