PHP code example of gabrielecorio / fiscozen-wrapper

1. Go to this page and download the library: Download gabrielecorio/fiscozen-wrapper 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/ */

    

gabrielecorio / fiscozen-wrapper example snippets


use GabrieleCorio\FiscozenWrapper\FiscozenClient;
use GabrieleCorio\FiscozenWrapper\Exceptions\AuthenticationException;

$client = new FiscozenClient(
    email: '[email protected]',
    password: 'your-password',
    sessionDir: '/path/to/sessions', // optional; defaults to sys_get_temp_dir()/fiscozen_sessions
);

// --- Request 1: submit credentials ---
try {
    $phoneNumber = $client->startLogin(); // returns the masked phone number
    // Store $phoneNumber in your session and show the OTP input to the user
} catch (AuthenticationException $e) {
    // handle error
}

// --- Request 2: submit OTP ---
try {
    $client->submitOtp($otpFromUser);
} catch (AuthenticationException $e) {
    // handle error
}

$client->login(function (string $phoneNumber): string {
    echo "OTP sent to {$phoneNumber}: ";
    return trim(fgets(STDIN));
});

$client->isAuthenticated(); // bool — makes a lightweight API call to verify the session
$client->logout();          // deletes the cookie file and invalidates the local session
$client->relogin($callback); // destroys the existing session and authenticates again

$invoices = $client->invoices()->list(
    page: 1,
    pageSize: 20,
    selfInvoice: false,
);

foreach ($invoices->results as $invoice) {
    // Read the fields needed by your application.
}

// Invoices issued to a customer in a period (most recent first by default).
$issued = $client->invoices()->list(
    counterpart: 1239628,
    dateFrom: new DateTimeImmutable('2026-06-01'),
    dateTo: new DateTimeImmutable('2026-10-31'),
    pageSize: 50,
);
// No match returns count 0 and an empty `results`, not an error.

// Or find the customer by name, surname or business name.
$issued = $client->invoices()->list(counterpartSearch: 'Rossi');

// Invoice details by number and year (e.g. 24/2026), no internal ID needed.
try {
    $invoice = $client->invoices()->findByNumber(number: 24, year: 2026);
    echo $invoice['full_id'], ' ', $invoice['amount'], ' ', $invoice['status'];
    $rows = $invoice['data']['rows']; // description, quantity, amount, total, vat_code
} catch (InvoiceNotFoundException $e) {
    // "Invoice not found: 24/2026"
}

// Or by internal Fiscozen ID.
$invoice = $client->invoices()->get(6512587);

$formatInfo = $client->invoices()->getFormatInfo(
    new DateTimeImmutable('2026-01-15'),
);

$counterparts = $client->counterparts()->list();

$paymentMethods = $client->payments()->listMethods(
    page: 1,
    pageSize: 20,
);

$year = 2026;

$stats = $client->dashboard()->getRealtimeYearStats($year);
$forecast = $client->dashboard()->getFulfillmentForecast($year);
$tasks = $client->dashboard()->getTasks();

$page = $client->invoices()->list(page: 1, pageSize: 20);

echo $page->count;
echo $page->page;
echo $page->pages;

if ($page->next !== null) {
    // Request the next page explicitly using page: $page->page + 1.
}

use GabrieleCorio\FiscozenWrapper\Exceptions\ApiException;

try {
    $response = $client->getUserMe();
    $user = $response['data'] ?? [];

    echo $user['first_name'] . ' ' . $user['last_name'];
    echo $user['email'];
    echo $user['fiscal_code'];
} catch (ApiException $e) {
    echo "HTTP {$e->getHttpStatusCode()}: {$e->getMessage()}";
}

$client = new FiscozenClient(
    email: '[email protected]',
    password: 'your-password',
    sessionDir: __DIR__ . '/sessions',
);
bash
php examples/login.php
php examples/read_dashboard.php --year=2026
php examples/read_invoices.php --page=1 --page-size=20
php examples/read_invoices.php --counterpart=1239628 --date-from=2026-06-01 --date-to=2026-10-31
php examples/read_invoices.php --counterpart-search=Rossi
php examples/read_invoice.php --number=24 --year=2026
php examples/read_counterparts.php
php examples/read_payment_methods.php --page=1 --page-size=20
php examples/read_user_info.php

src/
├── FiscozenClient.php          # Main entry point
├── Api/
│   └── ApiClient.php           # HTTP client for API endpoints
├── Auth/
│   └── AuthManager.php         # Authentication & session management
└── Exceptions/
    ├── ApiException.php
    ├── AuthenticationException.php
    └── OtpRequiredException.php