1. Go to this page and download the library: Download elkadrey/fiskaly-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
elkadrey / fiskaly-laravel example snippets
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
//use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Cache;
class Controller extends BaseController
{
private ?FiskalyLaravelClient $client = null;
public function __construct()
{
//Make the connection
$this->client = FiskalyLaravelClient::create([
"api_key" => env("TSE_API_KEY"),
"api_secret" => env("TSE_API_SECRET"),
"baseUrl" => env("TSE_API_URL", null),
"token" => Cache::get("tse_token"),
"token_expire_at" => Cache::get("tse_token_expire_at"),
]);
//Set debug level (2 is default)
/** Debug levels list
* 0 = errors only
* 1 = errors and warning
* 2 = all with info for each API response
*/
$this->client->setLog(2);
//make Auth with token in case empty token or expired
$token = $this->client->MakeAuth();
//Also you can use getToken
//$token = $this->client->getToken();
Cache::put("tse_token", $token->access_token);
Cache::put("tse_token_expire_at", $token->access_token_expires_at);
}
public function createTSS(Request $request)
{
$this->validate($request, [
"metadata" => "nullable|array"
]);
try
{
//create a ready INITIALIZED TSS (5 steps in one)
set_time_limit(0);
$results = $this->client->createTSS($request->metadata);
return JsonResource::make($results);
}
catch(Exception $e)
{
//Your exception code here
}
}
}