PHP code example of beziworld / laravel-edoreczenia

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

    

beziworld / laravel-edoreczenia example snippets


use Beziworld\EDoreczenia\Facades\EDoreczenia;
use Beziworld\EDoreczenia\Messages\OutgoingMessage;

$result = EDoreczenia::send(
    OutgoingMessage::create('Faktura FV/1/2026')
        ->toRecipient('AE:PL-98765-43210-SFVYC-19', companyName: 'Przykładowa Spółka')
        ->text('W załączeniu faktura.')
        ->caseId('FV/1/2026')
        ->attachFile(storage_path('invoices/fv-1-2026.pdf'))
);

$result->messageTaskId;   // sending is asynchronous (HTTP 202)

EDoreczenia::sendTaskStatus($result->messageTaskId);   // MessageTaskStatus::Pending / Finished
foreach (EDoreczenia::sendTask($result->messageTaskId) as $sent) {
    $sent->messageId;             // id of the message created for the recipient
    $sent->succeeded();           // false when the recipient could not be served
    $sent->errorDescription;
}

use Beziworld\EDoreczenia\Enums\MessageFormat;

$list = EDoreczenia::inbox(limit: 50, filters: ['opened' => false]);   // metadata, does not open messages
$list->total;              // matching messages
$list->electronicCount;    // messages still waiting in the delivery service

foreach ($list->messages as $message) {
    $message->id;
    $message->subject;
    $message->from?->displayName();
    $message->createdAt;        // CarbonImmutable, Europe/Warsaw
    $message->isNotice();       // notice of arrival (Stub), daysToReceive until deemed delivery
    $message->messageStatus();  // MessageStatus::Delivered, ...
}

$message = EDoreczenia::message($id, MessageFormat::FullExtended);   // content with attachments
$message->textBody;
$message->attachments[0]->filename;
$message->attachments[0]->content;   // decoded binary

EDoreczenia::downloadAttachment($id, $attachmentId)->saveTo('/tmp/file.pdf');   // binary, for files above 15 MB
EDoreczenia::markAsRead([$id1, $id2]);
EDoreczenia::deleteMessages([$id1, $id2]);

foreach (EDoreczenia::evidences($messageId) as $evidence) {
    $evidence->evidenceType();   // EvidenceType::ProofOfReceiptPdf (BP.OP), ContentHandover (E.1), ...
    $evidence->eventAt;
}

$file = EDoreczenia::evidenceFile($evidence);               // signed XML or PDF; puh/purde chosen from the type
EDoreczenia::evidenceFile($hpn, pdf: true);                 // PDF visualisation of H.PN
EDoreczenia::hybridDeliveryConfirmation($messageId);        // H.EPO
EDoreczenia::mailboxEvidences(downloaded: false);           // evidences of every message in the mailbox
EDoreczenia::technicalEvidences($messageId);                // ZIP
EDoreczenia::messageArchive($messageId);                    // ZIP with visualisation, text, attachments, evidences

$search = EDoreczenia::search();

$result = $search->byNip('525-224-84-81');           // public institutions, companies and organisations
$search->byKrs('28860');
$search->byRegon('012100784');
$search->byNameAndAddress('Przykładowa Spółka', ['city' => 'Warszawa', 'buildingNumber' => '12A', 'postalCode' => '00-001']);
$search->byPersonAndAddress('Jan', 'Kowalski', ['city' => 'Kraków', 'buildingNumber' => '1']);   // public senders only
$search->byAddresses(['AE:PL-98765-43210-SFVYC-19']);
$search->verifyAddresses($upTo1000Addresses);         // status and blocking warnings
$search->ownData();                                   // data of your mailbox

$entry = $result->first();
$entry->address;               // AE:PL-...
$entry->isActive();
$entry->isBlocked();           // BLOCK_WARNING: do not send
$entry->entity()?->displayName();
$entry->entity()?->nip();

// routes/console.php
Schedule::command('edoreczenia:poll')->everyFiveMinutes()->withoutOverlapping();

use Beziworld\EDoreczenia\Events\EvidenceReceived;
use Beziworld\EDoreczenia\Events\MessageReceived;

Event::listen(function (MessageReceived $event) {
    $event->connection;   // connection name
    $event->message;      // metadata only; the message is not opened
});

Event::listen(function (EvidenceReceived $event) {
    $event->evidence->evidenceType();
});

use Beziworld\EDoreczenia\Messages\OutgoingMessage;
use Beziworld\EDoreczenia\Notifications\EDoreczeniaChannel;

class InvoiceIssued extends Notification
{
    public function via($notifiable): array
    {
        return [EDoreczeniaChannel::NAME];
    }

    public function toEDoreczenia($notifiable): OutgoingMessage
    {
        return OutgoingMessage::create('Faktura')->text('...')->attachFile($this->path);
    }
}

// on the notifiable model
public function routeNotificationForEdoreczenia(): ?string
{
    return $this->ade;   // AE:PL-...
}

// config/edoreczenia.php: connections.default, connections.branch, ...
EDoreczenia::connection('branch')->inbox();

// mailbox of a tenant stored in the database
EDoreczenia::using([
    'address' => $tenant->ade,
    'system_name' => $tenant->ade_system,
    'private_key' => decrypt($tenant->ade_key),
    'environment' => 'prod',
], 'tenant-' . $tenant->id)->send($message);

EDoreczenia::request('GET', '/{address}/threads', ['limit' => 20])->json();
EDoreczenia::request('GET', '/{address}/numberMessages')->json();
EDoreczenia::updateControlData($ids, ['op' => 'replace', 'path' => '...', 'value' => 'TRASH']);