PHP code example of padosoft / laravel-ecr17

1. Go to this page and download the library: Download padosoft/laravel-ecr17 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/ */

    

padosoft / laravel-ecr17 example snippets


use Padosoft\Ecr17\Facades\Ecr17;

// Configure via config/ecr17.php (or .env), then:
Ecr17::connect();

$result = Ecr17::pay(amountCents: 1000, paymentType: 'credit'); // €10.00

if ($result->outcome === \Padosoft\Ecr17\Response\Outcome::Ok) {
    // $result->authCode, $result->pan, $result->stan, ...
}

use Padosoft\Ecr17\Ecr17Client;
use Padosoft\Ecr17\Ecr17Config;
use Padosoft\Ecr17\Transport\SocketTransport;

$config = new Ecr17Config(host: '192.168.1.50', port: 10000, terminalId: '12345678', cashRegisterId: '1');
$client = new Ecr17Client(new SocketTransport($config->host, $config->port, $config->connectionTimeoutMs), $config);

$status = $client->status();

$client->setOnProgress(fn (string $msg) => /* "INSERIRE CARTA" ... */);
$client->setOnReceiptLine(fn (string $line) => /* receipt text */);
$client->setOnConnectionStateChange(fn (string $state) => /* connecting|connected|disconnected */);
bash
php artisan vendor:publish --tag=ecr17-config