A reference implementation meant as an example how to use the PSB api using PHP.
- PHP 7.2 or greater
- Install library using
composer
.
composer require everbinding/econnect-psb-php
Then include composer autoloader.
require __DIR__ . '/vendor/autoload.php';
$config = \EConnect\Psb\Configuration::getDefaultConfiguration();
$config
->setUsername("{username}")
->setPassword("{password}");
->setClientId("{clientId}")
->setClientSecret("{clientSecret}")
->setHost("https://psb.econnect.eu")
->setApiKey('Subscription-Key', '{subscription key}');
Login using the default configuration.
$config = \EConnect\Psb\Configuration::getDefaultConfiguration();
$authN = new \EConnect\Psb\Authentication($config);
$authN->login();
Use the api using the default configuration after a successful login.
In this example we are calling the send sales invoice api. The user must have send permission on the provide sender partyId
. Also make sure the UBL is valid, otherwise it will be block for sending. The receiver partyId
is optional, the PSB will use the best possible route we no receiver partyId is provided.
$config = \EConnect\Psb\Configuration::getDefaultConfiguration();
$salesInvoiceApi = new EConnect\Psb\Api\SalesInvoiceApi(
new GuzzleHttp\Client();
$config
);
$yourPartyId = "senderPartyId";
$filePath = "./Ubl.xml";
$receiverPartyId = null;
$salesInvoiceApi->sendSalesInvoice($yourPartyId, $filePath, $receiverPartyId);
There is a simple example php client
that you can run on a php webserver. With the example you can send an invoice via Peppol
.
Also there is a webhook receiver example
that you need to have in order to receive invoices from Peppol
.
Instead of using this code, you could also generate the php code yourself using the openapi-generator-cli
.
openapi-generator-cli generate -g php -i https://psb.econnect.eu/v1/swagger.json?subscriptionKey={your-subscription} -o C:\temp --additional-properties=invokerPackage=EConnect\Psb
And use Jumbojett\OpenIDConnectClient
to get the access token.
You can also copy the code from: Authentication.php
use Jumbojett\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://identity.econnect.eu',
'{clientId}',
'{clientSecret}');
$oidc->addScope('ap');
// Add username and password
$oidc->addAuthParam(array('username'=>'{username}'));
$oidc->addAuthParam(array('password'=>'{password}'));
// to validate the JWT and whether the acces_token property is present
$token = $oidc->requestResourceOwnerToken(TRUE)->access_token;
If you want to know more about Peppol e-procurement or other procurement network the go to the Procurement Service Bus introduction page
.