Coder Social home page Coder Social logo

theinvoicingcompany / econnect-psb-php Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 2.0 68 KB

A reference implementation meant as an example how to use the PSB api using PHP.

Home Page: https://psb.econnect.eu/introduction/overview.html

License: Apache License 2.0

PHP 99.54% Shell 0.46%
peppol econnect

econnect-psb-php's Introduction

PHP Client

A reference implementation meant as an example how to use the PSB api using PHP.

Requirements

  • PHP 7.2 or greater

Install

composer require everbinding/econnect-psb-php

Then include composer autoloader.

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

Configure

$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

Login using the default configuration.

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

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

Use api

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);

Example client

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.

Build your own source

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;

Read more

If you want to know more about Peppol e-procurement or other procurement network the go to the Procurement Service Bus introduction page.

econnect-psb-php's People

Contributors

thiemenl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.