PHP code example of kb-data-solutions / php-sdk

1. Go to this page and download the library: Download kb-data-solutions/php-sdk 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/ */

    

kb-data-solutions / php-sdk example snippets


use KBDataSolutions\Sdk\Client;

$client = Client::create(
    clientId: $clientId,
    clientSecret: $clientSecret,
    baseUri: 'https://app.kbdatasolutions.nl',
);

$debtor = $client->debtors()->find($debtorId);

use KBDataSolutions\Sdk\Debtor\DebtorType;
use KBDataSolutions\Sdk\Debtor\Request\CreateDebtorRequest;

$debtor = $client->debtors()->create(new CreateDebtorRequest(
    externalCustomerId: 'wc-customer-42',
    oneTime: false,
    type: DebtorType::Consumer,
    country: 'NL',
    firstName: 'Jane',
    lastName: 'Doe',
    email: '[email protected]',
));

$debtor = $client->debtors()->find($debtor->id);

use KBDataSolutions\Sdk\Debtor\DebtorType;
use KBDataSolutions\Sdk\Debtor\Request\CreateDebtorRequest;
use KBDataSolutions\Sdk\Invoice\Currency;
use KBDataSolutions\Sdk\Invoice\DecimalAmount;
use KBDataSolutions\Sdk\Invoice\Request\CreateInvoiceRequest;
use KBDataSolutions\Sdk\Invoice\Request\DocumentUpload;
use KBDataSolutions\Sdk\Invoice\Request\InvoiceLine;
use KBDataSolutions\Sdk\Invoice\TaxTreatment;

$invoice = $client->invoices()->create(new CreateInvoiceRequest(
    externalInvoiceId: 'wc-order-1042',
    invoiceDate: new DateTimeImmutable('2026-08-01'),
    currency: Currency::Eur,
    taxTreatment: TaxTreatment::Domestic,
    destinationCountry: 'NL',
    netAmount: new DecimalAmount('10.00'),
    vatAmount: new DecimalAmount('2.10'),
    grossAmount: new DecimalAmount('12.10'),
    lines: [
        new InvoiceLine(
            externalId: '1',
            description: 'Widget',
            sku: 'WID-1',
            quantity: '1',
            unitPrice: new DecimalAmount('10.00'),
            netAmount: new DecimalAmount('10.00'),
            vatAmount: new DecimalAmount('2.10'),
            grossAmount: new DecimalAmount('12.10'),
            vatRate: '21',
        ),
    ],
    debtor: new CreateDebtorRequest(
        externalCustomerId: 'wc-customer-42',
        oneTime: false,
        type: DebtorType::Consumer,
        country: 'NL',
    ),
    document: new DocumentUpload('invoice.pdf', file_get_contents('/path/to/invoice.pdf')),
));

use KBDataSolutions\Sdk\Exception\SdkException;
use KBDataSolutions\Sdk\Exception\ValidationException;

try {
    $client->debtors()->create($request);
} catch (ValidationException $exception) {
    // $exception->fieldErrors(): array<string, list<string>>
} catch (SdkException $exception) {
    // any other SDK failure (authentication, authorization, not found, conflict, rate limit, transport, mapping)
}

$client->debtors()->create($request, idempotencyKey: 'order-1042-debtor');

use KBDataSolutions\Sdk\Invoice\PollingOptions;

$invoice = $client->invoices()->waitUntilProcessed(
    $invoice->id,
    new PollingOptions(maxAttempts: 10, intervalMilliseconds: 2000),
);