PHP code example of einvoicing / laravel

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

    

einvoicing / laravel example snippets


use Einvoicing\Laravel\Facades\Einvoicing;

$report = Einvoicing::validate($xml);

if (! $report->valid) {
    foreach ($report->errors() as $finding) {
        logger()->warning("{$finding->ruleId}: {$finding->message}", [
            'fix' => $finding->fix,
            'terms' => $finding->businessTerms,
        ]);
    }
}

use Einvoicing\Laravel\Rules\PeppolDocument;

$request->validate([
    'invoice' => ['

$conversion = Einvoicing::convert([
    'number' => $invoice->number,
    'issued' => $invoice->issued_at->toDateString(),
    'currency' => $invoice->currency,
    // seller, buyer, lines, payment...
]);

Storage::put("invoices/{$invoice->id}.xml", $conversion->document);

if (! Einvoicing::canReceive($customer->peppol_id)) {
    // Tell them, rather than failing a send later.
}

$participant = Einvoicing::participant($customer->peppol_id);
$participant->registered;
$participant->capabilities;

use Einvoicing\Laravel\Facades\Einvoicing;

it('will not send an invoice the network would reject', function () {
    $fake = Einvoicing::fake()->shouldBeInvalid(['PEPPOL-EN16931-R003']);

    $this->post('/invoices/1/send')->assertSessionHasErrors();

    $fake->assertValidated();
});

Einvoicing::fake()->shouldBeInvalid(['BR-CO-10']);              // by rule id
Einvoicing::fake()->shouldBeInvalid([[...]]);                    // full findings
Einvoicing::fake()->shouldFind('9932:GB1', registered: false);   // off the network
Einvoicing::fake()->shouldFind('9932:GB1', documentTypes: ['Order-2::Order']);
Einvoicing::fake()->shouldFindNobody();

$fake->assertValidated();
$fake->assertValidated(fn (string $xml) => str_contains($xml, 'INV-1'));
$fake->assertValidatedCount(1);
$fake->assertNothingValidated();
$fake->assertConverted(fn (array $invoice) => $invoice['number'] === 'INV-1');
$fake->assertLookedUp('9932:GB123456789');
$fake->assertNothingLookedUp();

$this->app->singleton(Einvoicing\Client::class, fn () => new Einvoicing\Client(
    key: config('einvoicing.key'),
    http: new MyClient,
));
bash
php artisan einvoicing:validate storage/app/invoice.xml
php artisan einvoicing:validate storage/app/invoice.xml --strict
php artisan einvoicing:participant 9932:GB123456789
php artisan einvoicing:usage
json
{
    "config": {
        "allow-plugins": { "php-http/discovery": true }
    }
}