PHP code example of invoiceninja / einvoice

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

    

invoiceninja / einvoice example snippets


use InvoiceNinja\EInvoice\EInvoice;
use InvoiceNinja\EInvoice\Validation\Profiles\InvoiceSettingsProfile;
use InvoiceNinja\EInvoice\Validation\ValidationGroups;

$errors = (new EInvoice())->validatePayload(
    $payload['Invoice'], // inner document, without the e_invoice / Invoice wrappers
    InvoiceSettingsProfile::class,
    [ValidationGroups::INVOICE_SETTINGS],
);

foreach ($errors as $error) {
    // Paths are relative to the inner document, e.g. ProjectReference[1].ID.value.
    $path = $error->getPropertyPath();
    $message = $error->getMessage();
    $code = $error->getCode();
}

use InvoiceNinja\EInvoice\Tests\Support\TestLogger;

TestLogger::get()->debug('Payload', ['payload' => $payload]);

foreach ($errors as $error) {
    TestLogger::get()->debug('Validation error', [
        'path' => $error->getPropertyPath(),
        'message' => $error->getMessage(),
        'code' => $error->getCode(),
    ]);
}