PHP code example of beziworld / laravel-debt-registers

1. Go to this page and download the library: Download beziworld/laravel-debt-registers 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-debt-registers example snippets


use Beziworld\DebtRegisters\Facades\DebtRegisters;

$result = DebtRegisters::driver('krd')->checkCompany('526-025-09-95');   // separators and "PL" are accepted

$result->reportNumber;                // "U1/0000123456/2026"
$result->createdAt;                   // CarbonImmutable, Europe/Warsaw
$result->hasNegativeInformation();    // true when unpaid obligations are listed
$result->totalArrears();              // Money: amount "4520.11" (decimal string), currency "PLN"
$result->summary->creditorsCount;     // 2

foreach ($result->obligations as $obligation) {
    $obligation->title;               // "FV/0001/2026"
    $obligation->type;                // "Invoice"
    $obligation->arrears;             // Money
    $obligation->paymentDate;         // CarbonImmutable
    $obligation->disputed;            // true when the debtor raised objections
    $obligation->creditor->name;      // "Hurtownia Alfa S.A."
    $obligation->creditor->nip;
}

foreach ($result->paidObligations as $paid) {
    $paid->paidDebt;                  // Money
    $paid->paidDate;
}

$result = DebtRegisters::checkConsumer('44051401359', consentGivenAt: $application->consent_at);

$krd = DebtRegisters::krd();

$krd->report('U1/0000123456/2026');                 // GetDisclosureReport, not a new disclosure
$krd->checkCompanyByOtherNumber('DE123456789');     // foreign company number
$krd->checkConsumerByOtherNumber('X1234567', now());
$krd->incognito()->checkCompany('5260250995');      // art. 25 entities only: no trace in the query register

$krd->lastSession()?->passwordExpiresAt;            // warn before the API password expires
$krd->lastSession()?->shouldChangePassword;

// config/debt-registers.php
'connections' => [
    'krd' => ['driver' => 'krd', 'login' => env('KRD_LOGIN'), 'password' => env('KRD_PASSWORD')],
    'krd_branch' => ['driver' => 'krd', 'environment' => 'production', 'login' => env('KRD_BRANCH_LOGIN'), 'password' => env('KRD_BRANCH_PASSWORD')],
],

DebtRegisters::driver('krd_branch')->checkCompany($nip);

// Credentials stored per tenant
DebtRegisters::using(['login' => $tenant->krd_login, 'password' => $tenant->krd_password, 'environment' => 'production'])
    ->checkCompany($nip);

use Beziworld\DebtRegisters\Enums\ObligationType;
use Beziworld\DebtRegisters\Nicci\Address;
use Beziworld\DebtRegisters\Nicci\Debtor;
use Beziworld\DebtRegisters\Nicci\NicciDocument;
use Beziworld\DebtRegisters\Nicci\Obligation;

$batch = (new NicciDocument())
    ->addCase(
        orderId: 'order-1',
        debtor: Debtor::company('Dłużnik Sp. z o.o.', '5260250995', Address::polish('ul. Prosta 1', '00-001', 'Warszawa')),
        obligations: [
            new Obligation(
                title: 'FV/0001/2026',
                paymentDate: $invoice->due_date,
                callSent: $invoice->demand_sent_at,     // payment demand with the warning about KRD
                arrears: '1230.50',
                debt: '1500.00',
                type: ObligationType::Invoice,
                userId: 'invoice-'.$invoice->id,        // your id, used to update or remove it later
            ),
        ],
        caseId: 'customer-'.$customer->id,
    )
    ->addCase('order-2', Debtor::consumer('Jan', 'Kowalski', '44051401359', Address::polish('ul. Długa 2', '00-002', 'Warszawa')), [/* ... */])
    ->addCase('order-3', Debtor::soleTrader('Jan Nowak Usługi', '8226951300', 'Jan', 'Nowak'), [/* ... */]);

$submissions = DebtRegisters::krd()->submissions();
$jobId = $submissions->submit($batch, description: 'November 2026');   // never retried automatically

use Beziworld\DebtRegisters\Enums\InformationType;
use Beziworld\DebtRegisters\Enums\RemoveReason;

$batch = (new NicciDocument())
    ->updateObligation('u-1', 'invoice-15', $obligationWithLowerArrears)         // partial payment
    ->updateCase('u-2', 'customer-7', $debtor, $obligations)                     // obligations left out are removed
    ->remove('r-1', 'customer-9')                                                // whole case paid
    ->remove('r-2', 'invoice-21', InformationType::ObligationInformation, RemoveReason::Cession);

$job = $submissions->job($jobId);   // Job: status (Queued, Started, Processed, Canceled, Failed), progress, queueNumber

if ($job?->isProcessed()) {
    $report = $submissions->result($jobId);

    $report->successful();                         // no fatal error and no failed order
    $report->failedOrders();                       // OrderResult with errorMessage and errorCode
    $report->order('order-1')?->systemId;          // KRD case id, e.g. "CAF/0000219303/2018"
    $report->order('order-1')?->obligationSystemIds;   // ['invoice-15' => 'OBF/0000408118/2018']
    $report->xml;                                  // the original report, for archiving
}

$submissions->jobs(changedSince: now()->subDay());   // for a scheduled poller
$submissions->cancel($jobId);                        // only while queued