PHP code example of barnetik / ticketbai

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

    

barnetik / ticketbai example snippets


use Barnetik\Tbai\Fingerprint\Vendor;
use Barnetik\Tbai\PrivateKey;
use Barnetik\Tbai\TicketBai;

$license = 'LICENCIA_DESARROLLO';
$developerCif = 'CIF';
$appName = 'TBAI PHP APP';
$version = '1.0';

$certificatePath = '/path/to/certificate.p12';
$certificatePassword = 'myCertificatePassword';

// Where we want the signed document to be stored
$signedXmlPath = './signed.xml';

$ticketbai = TicketBai::createFromJson(
    new Vendor($license, $developerCif, $appName, $version),
    json_decode(file_get_contents('tbai-sample.json'), true)
);

$ticketbai->sign(
    PrivateKey::p12($certificatePath),
    $certificatePassword,
    $signedXmlPath
);



// We have an endpoint for each province Araba, Bizkaia or Gipuzkoa
use Barnetik\Tbai\Api\Bizkaia\Endpoint as BizkaiaEndpoint;

/**
 * BizkaiaEndpoint(bool $dev = false, bool $debug = false)
 * For production usage $dev param must be false
 * $bizkaiaEndpoint = new BizkaiaEndpoint();
 */
$bizkaiaEndpoint = new BizkaiaEndpoint(true, true);
$result = $bizkaiaEndpoint->submitInvoice(
    $ticketbai,
    PrivateKey::p12($certificatePath),
    $certificatePassword,
);


if ($result->isDelivered()) {
    var_dump('SUCCESS!');
} else {
    var_dump($result->errorDataRegistry());
    var_dump($result->headers());
}

$shortSignatureValue = $ticketbai->chainSignatureValue();

use Barnetik\Tbai\Qr;

/**
 * Qr(TicketBai $ticketBai, bool $dev = false)
 * For production usage $dev param must be false
 * $qr = new Qr($ticketbai);
 */
$qr = new Qr($ticketbai, true);


$qr->savePng('/path/to/qr.png');

// Get the code that must be shown over QR on any invoice
$tbaiIdentifier = $qr->ticketbaiIdentifier();