PHP SDK

Install and use the official econnect-psb-php SDK: Composer, authentication, sending invoices and webhook examples.

The PHP SDK (econnect-psb-php) is a reference implementation for the PSB REST API. The library handles OAuth token management and provides typed API classes for common operations.

Repositorygithub.com/theinvoicingcompany/econnect-psb-phpPackageeverbinding/econnect-psb-php on PackagistLicenseApache 2.0
Requirements
  • PHP 7.2 or higher
  • Extensions: curl, json, mbstring
  • Composer
Installation
composer require everbinding/econnect-psb-php

Then load the Composer autoloader in your project:

require __DIR__ . '/vendor/autoload.php';
Configuration

Set the default configuration with your credentials and the correct environment. During development, use the acceptance URLs.

$config = \EConnect\Psb\Configuration::getDefaultConfiguration();

$config
    ->setUsername('your-username')          // only for Resource Owner flow
    ->setPassword('your-password')          // only for Resource Owner flow
    ->setClientId('your-client-id')
    ->setClientSecret('your-client-secret')
    ->setHost('https://accp-psb.econnect.eu')
    ->setApiKey('Subscription-Key', 'your-subscription-key'); // optional, legacy

For the Identity Server, the SDK uses OpenID Connect internally via jumbojett/openid-connect-php. Which credentials you need depends on the chosen OAuth2 flow — see Authentication.

EnvironmentPSB host (setHost)Identity ServerAcceptancehttps://accp-psb.econnect.euhttps://accp-identity.econnect.euProductionhttps://psb.econnect.euhttps://identity.econnect.eu

Tip: the Subscription-Key is legacy for the PSB API and is no longer required. If you send it, the value must still be valid.

Authentication

After configuration, call login() to obtain and cache an access token:

$config = \EConnect\Psb\Configuration::getDefaultConfiguration();

$auth = new \EConnect\Psb\Authentication($config);
$auth->login();

The SDK refreshes the token automatically as long as you reuse the same Configuration instance.

Send your first invoice

With SalesInvoiceApi you send a UBL file to the PSB. The {partyId} is the sender's Peppol identifier; the receiver is optional — the PSB then picks the best route.

$config = \EConnect\Psb\Configuration::getDefaultConfiguration();

$salesInvoiceApi = new \EConnect\Psb\Api\SalesInvoiceApi(
    new GuzzleHttp\Client(),
    $config
);

$senderPartyId = '0106:12345678';
$filePath = './invoice.xml';
$receiverPartyId = null; // optional

$salesInvoiceApi->sendSalesInvoice($senderPartyId, $filePath, $receiverPartyId);

Make sure the UBL document is valid; otherwise the PSB blocks the send. More about the endpoint and idempotency: Send invoice.

Receive webhooks

The repository includes examples for receiving incoming invoices via webhooks:

PSB webhooks are secured with an X-EConnect-Signature header. See Configure webhooks for platform configuration.

Common operations

The SDK generates API classes per endpoint group from the OpenAPI spec. You can find the full list in the repository and on psb.econnect.eu. Typical classes:

API classUseSalesInvoiceApiSend sales invoices and look up recipientsPurchaseInvoiceApiRetrieve purchase invoicesHookApiRegister and manage webhooksPeppolApiPeppol registration and lookup

Consult the Swagger UI for request and response schemas per operation.

Error handling

The SDK uses Guzzle as the HTTP client. API errors (4xx, 5xx) surface as GuzzleHttp\Exception\ClientException or ServerException. Check $e->getResponse()->getBody() for the PSB error details.

HTTP statusAction401 UnauthorizedToken expired or invalid credentials — call login() again400 Bad RequestValidation error in the document — check with the Validate API409 ConflictIdempotency conflict — document already processed5xxTemporary server error — implement retry with backoff
Generate your own code

Instead of this library, you can also generate PHP code from the OpenAPI spec. See OpenAPI codegen for the command and authentication notes.

Frequently asked questions
Is this a production-ready library or a sample?

The repository describes itself as a reference implementation. The code is open source and used in practice, but always verify that the Packagist version matches your PHP version and that the endpoints you need are covered. For full API coverage you can also run codegen yourself.

Which PHP versions are supported?

The package requires PHP 7.2+. The latest release on Packagist is v0.9.2 (August 2021). Test your integration thoroughly in the acceptance environment.