1. Go to this page and download the library: Download lenorix/laravel-beel 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/ */
lenorix / laravel-beel example snippets
'beel' => [
'key' => env('BEEL_API_KEY'), // beel_sk_test_... (sandbox) or beel_sk_live_...
'company_id' => env('BEEL_COMPANY_ID'), // company UUID, not the NIF
'account_id' => env('BEEL_ACCOUNT_ID'), // optional
'webhook_secret' => env('BEEL_WEBHOOK_SECRET'),
],
use Lenorix\LaravelBeel\BeelManager;
$company = app(BeelManager::class)->company();
$invoice = $company->invoices->create($request);
$company->invoices->issue($invoice->getId());
foreach ($company->customers->all() as $customer) {
// every page, fetched lazily
}
use Lenorix\LaravelBeel\Events\BeelWebhookReceived;
Event::listen(function (BeelWebhookReceived $event): void {
if ($event->isTest()) {
return;
}
if ($event->type === 'verifactu.status.updated') {
SyncVerifactuStatus::dispatch($event->id, $event->typed()->getData()->getInvoiceId());
}
});
use Lenorix\LaravelBeel\Events\Webhooks\VerifactuStatusUpdated;
Event::listen(function (VerifactuStatusUpdated $event): void {
SyncVerifactuStatus::dispatch($event->webhook->id, $event->data()->getInvoiceId());
});
use Lenorix\LaravelBeel\Events\Webhooks\InvoicePdfGenerated;
use Lenorix\LaravelBeel\Jobs\StoreInvoicePdf;
Event::listen(function (InvoicePdfGenerated $event): void {
if (! $event->webhook->isTest()) {
$invoiceId = $event->data()->getInvoiceId();
StoreInvoicePdf::dispatch($invoiceId, "invoices/{$invoiceId}.pdf", disk: 's3', companyId: $event->webhook->companyId);
}
});
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Storage;
use Lenorix\LaravelBeel\Jobs\StoreInvoicePdf;
$path = "beel-tmp/{$invoice->beel_invoice_id}.pdf";
Bus::chain([
new StoreInvoicePdf($invoice->beel_invoice_id, $path, disk: 's3', overwrite: true),
function () use ($invoice, $path) {
$invoice->addMediaFromDisk($path, 's3')->toMediaCollection('pdf');
Storage::disk('s3')->delete($path);
},
])->catch(function () use ($path) {
Storage::disk('s3')->delete($path);
})->dispatch();
use Lenorix\LaravelBeel\Testing\BeelFake;
Http::preventStrayRequests();
BeelFake::api()
->createInvoice(BeelFake::invoice(['status' => 'DRAFT']))
->issueInvoice(BeelFake::error(422, 'EMISSION_NOT_READY')) // answers in order,
->issueInvoice(BeelFake::invoice()) // the last one repeats
->listCustomers([BeelFake::customer()])
->invoicePdf() // the PDF link and its download
->fake();